Closed GF-Huang closed 2 years ago
hey @GF-Huang , you seem to use btplotting actively. if you need any help feel free to get in touch.
Hi @happydasch, can you explain how btplotting draws the graph? I'm trying to backtest stock and options together in 1 minute bars. Because options expire every week, even if every 2 days (SPY's options), and each stock has many options at different strikes. So I had to call cerebro.datas.clear()
in every daily backtesting to save memory (RAM).
My code:
I had try to replace strategy.observers
, but not work. As you see in the above image, I only take 2 days data for testing my idea:
df_underlying_list[:2]
.
Then I plotting:
But the DataTrades
still existing.
And seems only one Broker observer was plotted. (df_underlying_list[0]
is 2021-05-03
, df_underlying_list[1]
is 2021-05-04
)
cerebro.run()
then plotting them into together by once call cerebro.plot()
?so btplotting is using the result coming from backtrader. It will only plot the data that backtrader returns.
for your code above, i do not fully understand, how your strategy should work or what you want to achieve. But i noticed you reuse the instance of cerebro.
plotting multiple runs (or some combined result) will not be possible with current code. you could look into the optbrowser to plot multiple results within a browser or you could create multiple html files with results and browse them later.
for the observers, the info about observers is obtained here: https://github.com/happydasch/btplotting/blob/512780f8ab71395fef3667e872deca3a8a2f2e9a/btplotting/app.py#L197
also you add a observer with the same name multiple times, you could give them unique names, then they would plot i believe.
Thanks. My strategy is empty now, I just want to confirm btplotting can do this before writing strategy, I will take a look into _get_plotobjects
. Thank you.
..\btplotting\app.py:514: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling
frame.insert
many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, usenewframe = frame.copy()
df[source_id] = new_line