Back

Using DataNormalizationMode.Raw and History()

I'm feeding raw data into my algorithm by making sure to set DataNormalizationMode.Raw in all my calls to AddEquity. 

However, in a separate part of my algorithm, I am trying to calculate the 6-month returns of these equities like so:

def Rebalance(self):

# specify symbols as a list so that a DataFrame is returned
bars = self.History(['SPY', 'VEU', 'TLT', 'IJH', 'IJR'], TimeSpan.FromDays(127))

# get the return of each symbol over the period (127 days)

# first, group the data by symbol
gb = bars.groupby(bars.index.get_level_values(0))

# then, divide the final close price by the first close price and subtract 1.0 to get the 6-month return
returns = gb.last()['close'].div(gb.first()['close']) - 1.0

 

Since I am inputting raw data into my algorithm, won't History() return raw price data?  If this is the case, then woudn't some of my return calculations be way off in the case of a split or reverse split? 

Is it possible for me to specify that I'd like to use adjusted prices in a call to History()?   Alternatively, is there a beter way to calculate the 6-month return by creating a custom indicator?

Update Backtest








Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed