Trading strategies backtesting
Project description
backintime 0.6.1.2 (ОІ)
вњЁ A framework for trading strategies backtesting with Python вњЁ
Trailing stop, stop limit and OCO orders are not supported as of the current version.
Expected in 1.x.x releases.
Features
- Market/Limit orders management
- Use CSV or Binance API as a data source
- The same data can be represented in up to 16 timeframes
(few short candles is compressed to longer one) - Brief trading history statistics (win rate, avg. profit, etc.)
- Export trades to csv
This is how it looks like - MACD strategy
from backintime import TradingStrategy, Timeframes
from backintime.oscillators.macd import macd
'''
Extend TradingStrategy class and implement __call__ method
to have your own strategy
'''
class MacdStrategy(TradingStrategy):
# declare required oscillators here for later use
using_oscillators = ( macd(Timeframes.H4), )
def __call__(self):
# runs each time a new candle closes
macd = self.oscillators.get('MACD_H4')
if not self.position and macd.crossover_up():
self._buy() # buy at market
elif self.position and macd.crossover_down():
self._sell() # sell at market
backtesting is done as follows (with binance API data):
# add the following import to the ones above
from backintime import BinanceApiCandles
feed = BinanceApiCandles('BTCUSDT', Timeframes.H4)
backtester = Backtester(MacdStrategy, feed)
backtester.run_test(since='2020-01-01', start_money=10000)
# the result is available as a printable instance
res = backtester.results()
print(res)
# and also can be saved to a csv file
res.to_csv('filename.csv', sep=';', summary=True)
Alternatively, you can use a csv file on your local machine as source
from backintime import TimeframeDump, TimeframeDumpScheme
# specify column indexes in input csv
columns = TimeframeDumpScheme(
open_time=0, close_time=6,
open=1, high=3, low=4,
close=2, volume=5)
feed = TimeframeDump('h4.csv', Timeframes.H4, columns)
backtester = Backtester(MacdStrategy, feed)
backtester.run_test('2020-01-01', 10000)
print(backtester.results())
Install
pip install backintime
License
MIT
Author
Akim Mukhtarov @akim_int80h
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
backintime-0.6.1.2.tar.gz
(20.0 kB
view hashes)
Built Distribution
Close
Hashes for backintime-0.6.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27d6d1531c199d3fd8b885eb20e9f39a781315f72efba8ee06c9945b6c6a0c4c |
|
MD5 | 26b2a531f89c31e3e0f7160dc87f4384 |
|
BLAKE2b-256 | 22d43b345bebc77e583c7902dde4a14ff6dcccabcd443494d077d5b78339218a |