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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file backintime-1.6.0.tar.gz.
File metadata
- Download URL: backintime-1.6.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.5 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76dcb19576b902ddd089644de7a2188754b6526d6cae7f6c61f89477aae76e1f
|
|
| MD5 |
758ece27f667555fa6e0b332900a74ad
|
|
| BLAKE2b-256 |
5724f243d415aadb57216c614dd88453cad9dbe11831ed9565295d56e1d33dce
|
File details
Details for the file backintime-1.6.0-py3-none-any.whl.
File metadata
- Download URL: backintime-1.6.0-py3-none-any.whl
- Upload date:
- Size: 32.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.5 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
835cbfd49560a7cfb584b3c59104275744ec3a6f3280d8969205dc99862681e9
|
|
| MD5 |
6f9268fef373fba00db0519453f6014c
|
|
| BLAKE2b-256 |
800b0adb70e0c59d70ad24c589a59a0c0dfcd0f23db300cc8213a9061fc3b896
|