kernc / backtesting.py

:mag_right: :chart_with_upwards_trend: :snake: :moneybag: Backtest trading strategies in Python.
https://kernc.github.io/backtesting.py/
GNU Affero General Public License v3.0
5.38k stars 1.05k forks source link

Attach date column when printing '_equity_curve` #1148

Closed edofe99 closed 3 months ago

edofe99 commented 4 months ago

When you print the equity curve like this:

bt = Backtest(df,DonchainBreakout,cash=10_000, exclusive_orders= True)
stats = bt.run()
equity = stats['_equity_curve']
print(equity)

The result is this:

          Equity  DrawdownPct  DrawdownDuration
0    10000.00000      0.00000               NaN
1    10000.00000      0.00000               NaN
2    10000.00000      0.00000               NaN
3    10000.00000      0.00000               NaN
4    10000.00000      0.00000               NaN

And there are as many rows as the input dataframe. It would be a good practice to have also the date column inherited from the main dataframe on this equity dataframe.

coder145 commented 3 months ago

Certainly! It seems like the key issue here is that your data lacks a "DateTimeIndex". As your equity curve has the same index as your data. just convert the date in your data to index and it should be fine.