'USDT')['available'] / current_price if amount < 0.001: continue log.info(('buy:', cheap_btc_ticker, account_name, current_price, amount)) accounts[account_name].buy(ticker, current_price, amount * 0.99) else: amount = accounts[account_name].get_position('BTC')['available'] if amount < 0.001: continue log.info(('sell:', cheap_btc_ticker, ticker, account_name, current_price, amount)) accounts[account_name].sell(ticker, current_price, amount * 0.99) # 配置策略参数如:基准、回测数据级别等 my_strategy = ai.create_strategy(initialize, handle_data, universe=universe, benchmark='csi5', freq='d', refresh_rate=1) # 配置回测参数如:回测日期、手续费率 ai.backtest(strategy=my_strategy, start='2018-03-10', end='2018-05-29', commission={ 'taker': 0.0002, 'maker': 0.0002 })
# log.info("价格突破10日均线, 买入BTC, 价格:%d" % (asks_1_price)) # 如果跌破5000分钟均线卖出0.2BTC elif (current_price< MA10_1): context.account_1.sell("BTC/USDT.poloniex", bids_1_price, 0.2) # log.info("价格跌破10日均线, 卖出BTC, 价格:%d" % (bids_1_price)) # 可以直接指定universe,或者通过筛选条件选择universe池,这里直接指定binance交易所的BTC/USDT、ETH/USDT universe = ai.create_universe(['BTC/USDT.poloniex']) #,'ETH/USDT.binance' # 配置策略参数如:基准、回测数据级别等 my_strategy = ai.create_strategy( initialize, handle_data, universe=universe, benchmark='csi5', freq='5m', refresh_rate=1 ) # 配置回测参数如:回测日期、所在时区、手续费率 #(默认timezone是北京时区,其他时区请手动输入,如timezone='America/New_York',timezone='Asia/Tokyo'等) ai.backtest( strategy=my_strategy, start='2018-10-10 00:00:00', end='2018-11-10 00:00:00', commission={'taker': 0.0002, 'maker': 0.0002} )
current_available_btc = position_btc['available'] position_usdt = context.account.get_position('USDT') current_available_usdt = position_usdt['available'] current_price = context.get_price('BTC/USDT.binance') # 当RSI信号小于30,且拥有的BTC数量大于0时,卖出所有BTC if rsi < context.LOW_RSI and current_available_btc > 0: context.account.sell_pct('BTC/USDT.binance', current_price, 1) # 当RSI信号大于70, 且拥有的USDT数量为0时,则全仓买入 elif rsi > context.HIGH_RSI and current_available_usdt > 0: context.account.buy_pct('BTC/USDT.binance', current_price, 1) my_strategy = ai.create_strategy( initialize, handle_data, universe=universe, benchmark='csi5', freq='d', refresh_rate=1, ) ai.backtest(strategy=my_strategy, start='2017-09-01', end='2019-11-30', commission={ 'taker': 0.001, 'maker': 0.001 })