How to correctly update indicator with bar in python?

Back

I am implementing a custom alpha model in python and need to warm up the indicators for securities added to the universe. For indicators that accept the Update function with the signature (index, decimal) this works great:

for tuple in history.loc[ticker].itertuples():

ema.Update(tuple.Index, tuple.close)

How to do the same thing for indicators that only accept bars, like AverageTrueRange??

Where to get the Bar instance from?

Thanks

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.


Hi Manuel, 

you can create Trade Bars by using the TradeBar constructor . Here an example how to do so for a rolling window of trade bars (can be applied in an analogous fashion to Indicators) :  

rolling_window = RollingWindow[TradeBar](size)

for tuple in history.loc[ticker].itertuples():
tradebar = TradeBar(tuple.Index, symbol, tuple.open, tuple.high, tuple.low, tuple.close, tuple.volume)
rolling_window.Add(tradebar)

Note: symbol should be the actual QC Symbol object (not the string). 

1

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