首页 期货交易规则文章正文

期货量化交易平台推荐---掘金量化

期货交易规则 2021年01月17日 22:20 122 期舟

网址:www.myquant.cn

支持语言:python,c++

支持版本:   3.6,3.7

     在研究量化的过程中首先选择python语言,这个是确定的,其次是C++,最后是专门的语言。

     在此之前等待文华财经10的出台。聚宽语法复杂。研究从第一个策略开始。

          alpha期货+股票

importgm.apiasg

definit(context):

schedule(schedule_func=algo,date_rule='1m',time_rule='09:40:00')    

context.percentage_stock=0.4

context.percentage_futures=0.4

defalgo(context):

now=context.now

last_day=get_previous_trading_date(exchange='SHSE',date=now)

stock300=get_history_constituents(index='SHSE.000300',start_date=last_day,end_date=last_day)[0]['constituents'].keys()

index_futures=get_continuous_contracts(csymbol='CFFEX.IF',start_date=last_day,end_date=last_day)[-1]['symbol']

not_suspended_info=get_history_instruments(symbols=stock300,start_date=now,end_date=now)

not_suspended_symbols=[item['symbol']foriteminnot_suspended_infoifnotitem['is_suspended']]

fin=get_fundamentals(table='trading_derivative_indicator',symbols=not_suspended_symbols,start_date=now,end_date=now,fields='EVEBITDA',

filter='EVEBITDA>0',order_by='EVEBITDA',limit=30,df=True)

fin.index=fin.symbol

positions=context.account().positions()

forpositioninpositions:

symbol=position['symbol']

sec_type=get_instrumentinfos(symbols=symbol)[0]['sec_type']

ifsec_type==SEC_TYPE_FUTUREandsymbol!=index_futures:

order_target_percent(symbol=symbol,percent=0,order_type=OrderType_Market, position_side=PositionSide_Short)

print('市价单平不在标的池的',symbol)

elifsymbolnotinfin.index:

order_target_percent(symbol=symbol,percent=0,order_type=OrderType_Market, position_side=PositionSide_Long)

print('市价单平不在标的池的',symbol)

percent=context.percentage_stock/len(fin.index)

forsymbolinfin.index:

order_target_percent(symbol=symbol,percent=percent,order_type=OrderType_Market,position_side=PositionSide_Long)

print(symbol,'以市价单调多仓到仓位',percent)

ratio=get_history_instruments(symbols=index_futures,start_date=last_day,end_date=last_day)[0]['margin_ratio']

percent=context.percentage_futures*ratio

order_target_percent(symbol=index_futures,percent=percent,order_type=OrderType_Market,position_side=PositionSide_Short)

print(index_futures,'以市价单调空仓到仓位',percent)

if__name__=='__main__':    

g.run(

token='6b0e617adc69a9703aebed1609a75de60e5d909e',

strategy_id='993b5d0b-8ecb-11ea-91d4-80fa5b309fe8',

filename='main.py',

mode=g.MODE_BACKTEST,

backtest_adjust=g.ADJUST_PREV,

backtest_start_time='2019-01-02 08:00:00',

backtest_end_time='2020-05-08 16:00:00',        

backtest_initial_cash=1000000,

backtest_commission_ratio=0.0001,

backtest_slippage_ratio=0.0001)

标签: 期货量化 期货程序化

发表评论

期货代理网 备案号:鲁ICP备17043400号 期舟强力驱动 免责声明:本站所发布的内容仅供参考,不对您构成任何投资建议,据此操作风险自担,特此声明。本站部分内容源自网络,如有侵权请联系删除,对此我们深表歉意!