Package: gmocoin-backtest
gmocoin-backtestgmocoin-backtest is a python library for backtest with gmocoin fx btc trade technical analysis on Python 3.7 and above.backtest data fromhereInstallation$ pip install gmocoin-backtestUsagebasic runfromgmocoin_backtestimportBacktestclassMyBacktest(Backtest):defstrategy(self):fast_ma=self.sma(period=5)slow_ma=self.sma(period=25)# golden crossself.sell_exit=self.buy_entry=(fast_ma>slow_ma)&(fast_ma.shift()<=slow_ma.shift())# dead crossself.buy_exit=self.sell_entry=(fast_ma<slow_ma)&(fast_ma.shift()>=slow_ma.shift())MyBacktest(from_date="2021-07-15",to_date="2021-08-15").run()advanced runfromgmocoin_backtestimportBacktestfrompprintimportpprintclassMyBacktest(Backtest):defstrategy(self):rsi=self.rsi(period=10)ema=self.ema(period=20)atr=self.atr(period=20)lower=ema-atrupper=ema+atrself.buy_entry=(rsi<30)&(self.df.C<lower)self.sell_entry=(rsi>70)&(self.df.C>upper)self.sell_exit=ema>self.df.Cself.buy_exit=ema<self.df.Cbt=MyBacktest(symbol="BTC",# (default=BTC_JPY)sqlite_file_name="backtest.sqlite3",# (default=backtest.sqlite3)from_date="2021-07-15",# (default="")to_date="2021-08-15",# (default="")size=0.1,# (default=0.001)interval="1H",# 5-60S(second), 1-60T(minute), 1-24H(hour) (default=1T)data_dir="data",# data directory (default=data))pprint(bt.run(),sort_dicts=False){'total profit':-76320.2,'total trades':25,'win rate':56.0,'profit factor':0.549,'maximum drawdown':105907.1,'recovery factor':-0.721,'riskreward ratio':0.431,'sharpe ratio':-0.226,'average return':-0.075,'stop loss':0,'take profit':0}Supported indicatorsSimple Moving Average 'sma'Exponential Moving Average 'ema'Moving Average Convergence Divergence 'macd'Relative Strenght Index 'rsi'Bollinger Bands 'bbands'Stochastic Oscillator 'stoch'Average True Range 'atr'Strategy examplesMACDclassMyBacktest(Backtest):defstrategy(self):macd,signal=self.macd(fast_period=12,slow_period=26,signal_period=9)self.sell_exit=self.buy_entry=(macd>signal)&(macd.shift()<=signal.shift())self.buy_exit=self.sell_entry=(macd<signal)&(macd.shift()>=signal.shift())Bollinger BandsclassMyBacktest(Backtest):defstrategy(self):upper,mid,lower=self.bbands(period=20,band=2)self.sell_exit=self.buy_entry=(upper>self.df.C)&(upper.shift()<=self.df.C.shift())self.buy_exit=self.sell_entry=(lower<self.df.C)&(lower.shift()>=self.df.C.shift())StochasticclassMyBacktest(Backtest):defstrategy(self):k,d=self.stoch(k_period=5,d_period=3)self.sell_exit=self.buy_entry=((k>20)&(d>20)&(k.shift()<=20)&(d.shift()<=20))self.buy_exit=self.sell_entry=((k<80)&(d<80)&(k.shift()>=80)&(d.shift()>=80))Moving average divergence rateclassMyBacktest(Backtest):defstrategy(self):sma=self.sma(period=20)ratio=(self.df.C-sma)/sma*100self.sell_exit=self.buy_entry=ratio>-5&(ratio.shift()<=-5)self.buy_exit=self.sell_entry=ratio<5&(ratio.shift()>=5)MomentumclassMyBacktest(Backtest):defstrategy(self):mom=self.df.C-self.df.C.shift(10)self.sell_exit=self.buy_entry=mom>0&(mom.shift()<=0)self.buy_exit=self.sell_entry=mom<0&(mom.shift()>=0)Donchian ChannelsclassMyBacktest(Backtest):defstrategy(self):high=self.df.H.rolling(20).max()low=self.df.L.rolling(20).min()self.sell_exit=self.buy_entry=(high>self.df.C)&(high.shift()<=self.df.C)self.buy_exit=self.sell_entry=(low<self.df.C)&(low.shift()>=self.df.C)Relative Vigor IndexclassMyBacktest(Backtest):defrvi(self,*,period:int=10,price:str="C")->Tuple[pd.DataFrame,pd.DataFrame]:co=self.df.C-self.df.On=(co+2*co.shift(1)+2*co.shift(2)+co.shift(3))/6hl=self.df.H-self.df.Ld=(hl+2*hl.shift(1)+2*hl.shift(2)+hl.shift(3))/6rvi=n.rolling(period).mean()/d.rolling(period).mean()signal=(rvi+2*rvi.shift(1)+2*rvi.shift(2)+rvi.shift(3))/6returnrvi,signaldefstrategy(self):rvi,signal=self.rvi(period=5)self.sell_exit=self.buy_entry=(rvi>signal)&(rvi.shift()<=signal.shift())self.buy_exit=self.sell_entry=(rvi<signal)&(rvi.shift()>=signal.shift())