bigquant支持期货量化交易和回测么?


(rjj510) #1

bigquant支持期货量化交易和回测么?


(rjj510) #2

简单的写了一个和期货相关的。写的对么

克隆策略
In [64]:
#symbol = D.instruments(start_date='2017-07-01', end_date='2017-07-02', market="CN_FUTURE")
#symbol[:len(symbol)]
start_date='2016-07-01'
end_date  ='2017-07-02'
instruments=['RB000.SHF']
capital_base =30000
benchmark = 'RB000.SHF'


def initialize(context):
    context.set_commission(PerOrder(buy_cost=0,sell_cost=0,min_cost=0))
    context.instruments=instruments
    context.trading_period = 5 
    
def handle_data(context,data):   
     if context.trading_day_index < context.trading_period :
        return 
     sid = context.symbol('RB000.SHF')
     price = data.current(sid,'price')
     mavg  = data.history(sid,'price',context.trading_period,'1d').mean()
     cur_position=context.portfolio.positions[sid].amount
    
     if mavg>price and cur_position ==0 and data.can_trade(sid):
        context.order_target_percent(sid,1)
     elif cur_position>0:
        context.order_target_percent(sid,0)

m = M.trade.v1(
    instruments=instruments,
    start_date=start_date,
    end_date=end_date,
    initialize=initialize,
    handle_data=handle_data,
    # 买入订单以开盘价成交
    order_price_field_buy='close',
    # 卖出订单以开盘价成交
    order_price_field_sell='close',
    capital_base=capital_base,
    benchmark=benchmark,
    # 传入数据给回测模块,所有回测函数里用到的数据都要从这里传入,并通过 context.options 使用,否则可能会遇到缓存问题
    options={},
)

#D.history_data(['RB000.SHF'], '2017-08-22', '2017-08-26', ['open','close'])
[2017-08-26 01:45:27.314433] INFO: bigquant: backtest.v6 start ..
[2017-08-26 01:45:28.882055] INFO: Performance: Simulated 243 trading days out of 243.
[2017-08-26 01:45:28.883244] INFO: Performance: first open: 2016-07-01 13:30:00+00:00
[2017-08-26 01:45:28.884187] INFO: Performance: last close: 2017-06-30 19:00:00+00:00
  • 收益率44.12%
  • 年化收益率46.08%
  • 基准收益率42.46%
  • 阿尔法0.05
  • 贝塔0.91
  • 夏普比率1.15
  • 收益波动率36.07%
  • 信息比率0.18
  • 最大回撤20.6%
[2017-08-26 01:45:29.714662] INFO: bigquant: backtest.v6 end [2.400162s].


(iQuant) #3

支持期货。
建议将

order_price_field_buy='close',order_price_field_sell='close'

改成:

order_price_field_buy='open',order_price_field_sell='open'

(rjj510) #5

买入时候,杠杆率 一手的吨数这些都在哪些函数中设置呀