def main(plot): import coloredlogs coloredlogs.install(level='DEBUG', fmt='[%(asctime)s] %(levelname)s %(message)s') instrument = "600036" bBandsPeriod = 40 feeds = mootdx.build_feed([instrument], 2003, 2018, "histdata/mootdx") strat = BBands(feeds, instrument, bBandsPeriod) sharpeRatioAnalyzer = sharpe.SharpeRatio() strat.attachAnalyzer(sharpeRatioAnalyzer) if plot: plt = plotter.StrategyPlotter(strat, True, True, True) plt.getInstrumentSubplot(instrument).addDataSeries( "upper", strat.getBollingerBands().getUpperBand()) plt.getInstrumentSubplot(instrument).addDataSeries( "middle", strat.getBollingerBands().getMiddleBand()) plt.getInstrumentSubplot(instrument).addDataSeries( "lower", strat.getBollingerBands().getLowerBand()) strat.run() print("Sharpe ratio: %.2f" % sharpeRatioAnalyzer.getSharpeRatio(0.05)) if plot: plt.plot()
def main(): ''' 策略执行 :return: ''' instrument = "600036" feeds = mootdx.build_feed([instrument], 2008, 2018, "histdata/mootdx") # 3.实例化策略 strat = MyStrategy(feeds, instrument) # 4.设置指标和绘图 ratio = sharpe.SharpeRatio() strat.attachAnalyzer(ratio) # plter = plotter.StrategyPlotter(strat) # 4.设置指标和绘图 draws = drawdown.DrawDown() strat.attachAnalyzer(draws) tradeAnalyzer = trades.Trades() strat.attachAnalyzer(tradeAnalyzer) plter = plotter.StrategyPlotter(strat) # 5.运行策略 strat.run() strat.info("最终收益: {}".format(strat.getResult())) # 6.输出夏普率、绘图 strat.info("夏普比率: {}".format(ratio.getSharpeRatio(0))) strat.info("最大回撤: {}".format(draws.getMaxDrawDown())) strat.info("回撤时间: {}".format(draws.getLongestDrawDownDuration())) plter.plot()
def main(): import coloredlogs coloredlogs.install(level='DEBUG', fmt='[%(asctime)s] %(levelname)s %(message)s') instrument = "600036" feeds = mootdx.build_feed([instrument], 2003, 2018, "histdata/mootdx") resample.resample_to_csv(feeds, bar.Frequency.MINUTE * 30, "30min-bitstampUSD.csv")
def main(): instruments = ["600036"] feeds = mootdx.build_feed(instruments, 2003, 2018, "histdata/mootdx") # 3.实例化策略 strat = Strategy(feeds, instruments[0]) # 4.设置指标和绘图 ratio = sharpe.SharpeRatio() strat.attachAnalyzer(ratio) plter = plotter.StrategyPlotter(strat) # 5.运行策略 strat.run() strat.info("最终收益: %.2f" % strat.getResult()) # 6.输出夏普率、绘图 strat.info("夏普比率: " + str(ratio.getSharpeRatio(0))) plter.plot()
def parameters_generator(instrument): instrument = [instrument] entrySMA = list(range(150, 251)) exitSMA = list(range(5, 16)) rsiPeriod = list(range(2, 11)) overBoughtThreshold = list(range(75, 96)) overSoldThreshold = list(range(5, 26)) return itertools.product(instrument, entrySMA, exitSMA, rsiPeriod, overBoughtThreshold, overSoldThreshold) # The if __name__ == '__main__' part is necessary if running on Windows. if __name__ == '__main__': # Load the feed from the CSV files. # feeds = yahoofeed.Feed() # feeds.addBarsFromCSV("dia", "./tests/data/DIA-2009-yahoofinance.csv") # feeds.addBarsFromCSV("dia", "./tests/data/DIA-2010-yahoofinance.csv") # feeds.addBarsFromCSV("dia", "./tests/data/DIA-2011-yahoofinance.csv") instrument = '600036' feeds = mootdx.build_feed([instrument], 2003, 2018, './histdata/mootdx') # Run the server. server.serve(strategyParameters=parameters_generator(instrument), address="0.0.0.0", barFeed=feeds, drivce='zmq', port=5000)