Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
backtesting.py ema strategy Backtest.run
from backtesting import Backtest
# start from 1 BTC with the commission 0.12%
df_ = df.copy()
bt_ema = Backtest(df_, EmaCrossStrategy, cash=1, commission=.0012, trade_on_close=True)
bt_ema.run()
Start 2015-01-01 00:00:00
End 2020-07-30 00:00:00
Duration 2037 days 00:00:00
Exposure [%] 98.4291
Equity Final [$] 83.5116
Equity Peak [$] 108.37
Return [%] 8251.16
Buy & Hold Return [%] 2969.48
Max. Drawdown [%] -43.0488
Avg. Drawdown [%] -10.8991
Max. Drawdown Duration 256 days 00:00:00
Avg. Drawdown Duration 31 days 00:00:00
# Trades 134
Win Rate [%] 35.8209
Best Trade [%] 129.537
Worst Trade [%] -14.2521
Avg. Trade [%] 4.69578
Max. Trade Duration 99 days 00:00:00
Avg. Trade Duration 15 days 00:00:00
Expectancy [%] 10.6319
SQN 1.33068
Sharpe Ratio 0.230749
Sortino Ratio 1.384
Calmar Ratio 0.10908
_strategy EmaCrossStrategy
dtype: object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment