项目作者: 10mohi6

项目描述 :
bitmex-backtest is a python library for backtest with bitmex fx trade rest api on Python 3.7 and above.
高级语言: Python
项目地址: git://github.com/10mohi6/bitmex-backtest-python.git
创建时间: 2019-11-02T18:05:54Z
项目社区:https://github.com/10mohi6/bitmex-backtest-python

开源协议:MIT License

下载


bitmex-backtest

PyPI
License: MIT
codecov
Build Status
PyPI - Python Version
Downloads

bitmex-backtest is a python library for backtest with bitmex fx trade rest api on Python 3.7 and above.

Installation

  1. $ pip install bitmex-backtest

Usage

basic

  1. from bitmex_backtest import Backtest
  2. bt = Backtest()
  3. bt.candles("XBTUSD")
  4. fast_ma = bt.sma(period=5)
  5. slow_ma = bt.sma(period=25)
  6. bt.sell_exit = bt.buy_entry = (fast_ma > slow_ma) & (fast_ma.shift() <= slow_ma.shift())
  7. bt.buy_exit = bt.sell_entry = (fast_ma < slow_ma) & (fast_ma.shift() >= slow_ma.shift())
  8. bt.run()
  9. bt.plot()

advanced

  1. from bitmex_backtest import Backtest
  2. bt = Backtest(test=True)
  3. filepath = "xbtusd-60.csv"
  4. if bt.exists(filepath):
  5. bt.read_csv(filepath)
  6. else:
  7. params = {
  8. "resolution": "60", # 1 hour candlesticks (default=1) 1,3,5,15,30,60,120,180,240,360,720,1D,3D,1W,2W,1M
  9. "count": "5000" # 5000 candlesticks (default=500)
  10. }
  11. bt.candles("XBTUSD", params)
  12. bt.to_csv(filepath)
  13. fast_ma = bt.sma(period=10)
  14. slow_ma = bt.sma(period=30)
  15. exit_ma = bt.sma(period=5)
  16. bt.buy_entry = (fast_ma > slow_ma) & (fast_ma.shift() <= slow_ma.shift())
  17. bt.sell_entry = (fast_ma < slow_ma) & (fast_ma.shift() >= slow_ma.shift())
  18. bt.buy_exit = (bt.C < exit_ma) & (bt.C.shift() >= exit_ma.shift())
  19. bt.sell_exit = (bt.C > exit_ma) & (bt.C.shift() <= exit_ma.shift())
  20. bt.quantity = 100 # default=1
  21. bt.stop_loss = 200 # stop loss (default=0)
  22. bt.take_profit = 1000 # take profit (default=0)
  23. print(bt.run())
  24. bt.plot("backtest.png")
  1. total profit -342200.000
  2. total trades 162.000
  3. win rate 32.716
  4. profit factor 0.592
  5. maximum drawdown 470950.000
  6. recovery factor -0.727
  7. riskreward ratio 1.295
  8. sharpe ratio -0.127
  9. average return -20.325
  10. stop loss 23.000
  11. take profit 1.000

advanced.png

Supported indicators

  • Simple Moving Average ‘sma’
  • Exponential Moving Average ‘ema’
  • Moving Average Convergence Divergence ‘macd’
  • Relative Strenght Index ‘rsi’
  • Bollinger Bands ‘bband’
  • Stochastic Oscillator ‘stoch’
  • Market Momentum ‘mom’

Getting started

For help getting started with bitmex REST API, view our online documentation.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request