Using DataNormalizationMode.Raw and History()

Back

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








 
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.


Exactly. I would like to use raw data for my daily universe selection but then access adjusted prices to calculate momentum. A reverse split would screw up a momentum calculation if raw data was used and yet raw prices are essential for me to select which stocks to add to the universe.

0

Hi Nathaniel, 

History() return adjusted prices by default. So it should be fine if you need the History request to calculate the returns. 

0

Hi everyone,

Just to clarify, the normalization of the data returned by the History method matches the normalization of the data that the algorithm subscribes to. Therefore, if we subscribe to raw pricing data, the history method will return a dataframe of raw historical prices by default.

See the attached backtest and plot for reference.

Best,
Derek Melchin

1

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.


Hi Derek, 

thanks for the clarification. I formerly thought the History method always return adjusted price data due to this older post here. I think it should be mentioned somewhere in the documentation that prices in coarse are raw by default and prices of history requests matches the corresponding data normalization mode. 

Follow-up question: Is there a way to get AdjustedPrice within FineSelection? As we can see here, AdjustedPrice is not available in FineFundamental class. For many of my algorithms I prefer to filter by market cap which is only available in FineSelection and after this step I'd like to apply History (with adjusted prices) on the filtered list of symbols. 

Currently I am using History in CoarseSelection which is not ideal since it causes many unnecessary computations. 

Would you consider to add AdjustedPrice to FineFundamental/FineSelection to enable us to filter by market cap before we use History with adjusted prices? This would speed up my universe selection part. 

 

0

Another and maybe better solution would be to set a data normalization mode for the history request which can differ from the data normalization mode of the universe / subscribed symbols. 

Something like this: 

self.History(symbol, lookback, Resolution.Daily, DataNormalizationMode.Adjusted)

I've searched through the documentation and forum but couldn't find anything helpful. 

0

Hi Arthur,

We are in the process of updating our documentation. I've created a GitHub Issue to specify that the new docs should state that prices in coarse are raw by default and prices of history requests matches the corresponding data normalization mode. Track our progress here.

Since adjusted prices are available in coarse selection, we can filter the symbols by adjusted price before they are considered in fine selection. Having adjusted prices in both selection functions is redundant.

I've created a GitHub Issue to add a data normalization parameter to the History method. Track our progress here.

Best,
Derek Melchin

1

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.


Thanks Derek Melchin , these precisions are useful!

0

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