forked fromkernc/backtesting.py
- Notifications
You must be signed in to change notification settings - Fork0
🔎 📈 🐍 💰 Backtest trading strategies in Python.
License
NotificationsYou must be signed in to change notification settings
NashLea/backtesting.py
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Backtest trading strategies with Python.
$ pip install backtesting
frombacktestingimportBacktest,Strategyfrombacktesting.libimportcrossoverfrombacktesting.testimportSMA,GOOGclassSmaCross(Strategy):definit(self):Close=self.data.Closeself.ma1=self.I(SMA,Close,10)self.ma2=self.I(SMA,Close,20)defnext(self):ifcrossover(self.ma1,self.ma2):self.buy()elifcrossover(self.ma2,self.ma1):self.sell()bt=Backtest(GOOG,SmaCross,cash=10000,commission=.002)bt.run()bt.plot()
Results in:
Start 2004-08-19 00:00:00End 2013-03-01 00:00:00Duration 3116 days 00:00:00Exposure [%] 94.29Equity Final [$] 69665.12Equity Peak [$] 69722.15Return [%] 596.65Buy & Hold Return [%] 703.46Max. Drawdown [%] -33.61Avg. Drawdown [%] -5.68Max. Drawdown Duration 689 days 00:00:00Avg. Drawdown Duration 41 days 00:00:00# Trades 93Win Rate [%] 53.76Best Trade [%] 56.98Worst Trade [%] -17.03Avg. Trade [%] 2.44Max. Trade Duration 121 days 00:00:00Avg. Trade Duration 32 days 00:00:00Expectancy [%] 6.92SQN 1.77Sharpe Ratio 0.22Sortino Ratio 0.54Calmar Ratio 0.07_strategy SmaCross
Find more usage examples in thedocumentation.
- Simple, well-documented API
- Blazing fast execution
- Built-in optimizer
- Library of composable base strategies and utilities
- Indicator-library-agnostic
- Supportsany financial instrument with candlestick data
- Detailed results
- Interactive visualizations
About
🔎 📈 🐍 💰 Backtest trading strategies in Python.
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Languages
- Python97.4%
- JavaScript1.9%
- Shell0.7%