Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
Created August 2, 2020 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuyasugano/f3d287a6bc73af7d0aab3a4c10d9692c to your computer and use it in GitHub Desktop.
Save yuyasugano/f3d287a6bc73af7d0aab3a4c10d9692c to your computer and use it in GitHub Desktop.
backtesting.py ema strategy Backtest.optimize
n1=list(range(5, 20))
n2=list(range(15, 30))
stats = bt_ema.optimize(n1=n1, n2=n2,
maximize='Equity Final [$]', constraint=lambda p: p.n1 < p.n2)
print(stats)
Start 2015-01-01 00:00:00
End 2020-07-30 00:00:00
Duration 2037 days 00:00:00
Exposure [%] 98.3309
Equity Final [$] 102.75
Equity Peak [$] 125.776
Return [%] 10175
Buy & Hold Return [%] 2969.48
Max. Drawdown [%] -46.1918
Avg. Drawdown [%] -10.5397
Max. Drawdown Duration 260 days 00:00:00
Avg. Drawdown Duration 32 days 00:00:00
# Trades 92
Win Rate [%] 35.8696
Best Trade [%] 253.563
Worst Trade [%] -14.4748
Avg. Trade [%] 8.04839
Max. Trade Duration 116 days 00:00:00
Avg. Trade Duration 22 days 00:00:00
Expectancy [%] 14.6598
SQN 1.34727
Sharpe Ratio 0.235095
Sortino Ratio 2.36271
Calmar Ratio 0.174238
_strategy EmaCrossStrategy(n1=6,n2=16)
dtype: object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment