I am exploring the research environment, and want to plot some graph. I just copy most of the code from docs, but there is still something wrong.
qb = QuantBook()
es = qb.AddFuture("ES")
es.SetFilter(timedelta(0), timedelta(90))
start_date = datetime(2014, 7, 1, 9, 30)
end_date = datetime(2014, 7, 3, 23, 59)
future_history = qb.GetFutureHistory(es.Symbol, start_date, end_date, Resolution.Minute)
future_history.GetAllData()
history = future_history.GetAllData()
# drop expiry and symbols
history.reset_index(level = 0, drop = True, inplace=True)
history.reset_index(level = 0, drop = True, inplace=True)
# consolidate to 5 min bars
close_prices = history["close"]
offset = '5T'
df_5min_ohlc = close_prices.resample(offset).ohlc()
# I copied the below code, but still have an error
# manually update the indicator
bb = BollingerBands(30, 2)
bb_values = {'time': [], 'upperband': [], 'middleband': [], 'lowerband': []}
for row in df_5min_ohlc.itertuples():
time = row.Index
close = row.close
bb.Update(time, close)
if bb.IsReady:
bb_values['time'].append(time) # Save timestamps to create index for dataframe
bb_values['upperband'].append(bb.UpperBand.Current.Value)
bb_values['middleband'].append(bb.MiddleBand.Current.Value)
bb_values['lowerband'].append(bb.LowerBand.Current.Value)
consolidated_bbdf = pd.DataFrame(bb_values, columns=['time', 'upperband', 'middleband', 'lowerband'])
consolidated_bbdf = consolidated_bb.set_index('time')
TypeError: No method matches given arguments for Update: (<class 'pandas._libs.tslibs.timestamps.Timestamp'>, <class 'float'>)
Error related Code:
bb.Update(time, close)
So what should I pass instead?
Thx in advance
Varad Kabade
Hi Will Chau,
The above issue occurs because some of the close prices are NaN in the data frame. To resolve this, we recommend checking if the current close is NaN or not before making the indicator update:
Refer to the attached backtest.
Best,
Varad Kabade
Will Chau
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!