Is this correct?

I'm trying to get "three most recent 2000 constant-volume bars", is this code correct?

   for number in self.bond_price:
                vol_bar_one = self.Volume[0:2001]
                vol_bar_two = self.Volume[2001:4001]
                vol_bar_three = self.Volume[4001:6001]

                vol_bar_one_price = bond_price.vol_bar_one["close"]

                vol_bar_two_price = bond_price.vol_bar_two["close"]

                vol_bar_three_price = bond_price.vol_bar_three["close"]


My worry is that these bars will not remain static but will update with each new contract traded, kicking out the oldest value in the slice and inserting a new one for the "most recent value.

Update Backtest

In the following code is self.Volume a historical data request? Unfortunately, I can not answer this question well enough without more code to analyze. 

A historical data request will return a static dataframe and the bars created in this snippet can be saved for future reference in a rolling window. When historical data is requested with an integer x and not DateTime values, it will retrieve the last x bars and hence the bars created during each time loop will be new.


Update Backtest


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.


This discussion is closed