
超簡単Pythonで仮想通貨FX自動売買バックテスト(bybit 利用)
Pythonでbybit利用して超簡単に仮想通貨FX自動売買バックテスト
1. ツールインストール
$ pip install bybit-backtest
2. ファイル作成
bybit.py
from bybit_backtest import Backtest
class MyBacktest(Backtest):
def strategy(self):
fast_ma = self.sma(period=5)
slow_ma = self.sma(period=25)
# golden cross
self.sell_exit = self.buy_entry = (fast_ma > slow_ma) & (
fast_ma.shift() <= slow_ma.shift()
)
# dead cross
self.buy_exit = self.sell_entry = (fast_ma < slow_ma) & (
fast_ma.shift() >= slow_ma.shift()
)
MyBacktest(
symbol="BTCUSD",
from_date="2020-10-01",
to_date="2020-11-01",
interval="1T",
).run("backtest.png")
3. 実行
$ python bybit.py
total profit 2.866
total trades 2342.000
win rate 35.397
profit factor 1.171
maximum drawdown 0.567
recovery factor 5.054
riskreward ratio 2.063
sharpe ratio NaN
average return 0.000
stop loss 0.000
take profit 0.000
backtest.png
以上、超簡単!