#!/usr/bin/env python
# coding:utf-8
from PoboAPI import *
import datetime
import time
import numpy as np
from copy import *#开始时间,用于初始化一些参数
def OnStart(context) :context.myacc = None#登录交易账号if context.accounts["回测期货"].Login() :context.myacc = context.accounts["回测期货"]#每天行情初始化的,获取当前的豆粕期货主力合约作为标的,获取对应的平价期权
def OnMarketQuotationInitialEx(context, exchange,daynight):#过滤掉非大商所的信号if exchange != 'DCE' or daynight!='night':return#获取期权标的g.biaodi = GetMainContract('DCE', 'm',20)klinedata = GetHisData2(g.biaodi, BarType.Day)lastclose = klinedata[-1].close#获取评价期权g.atmopc = GetAtmOptionContract(g.biaodi,None,lastclose,0)#print g.atmopc#订阅日K线用来驱动onbar事件SubscribeBar(g.atmopc,BarType.Day)#在k线出现的时候,如果没持仓就卖开,如果有就平仓
def OnBar(context,code,bartype):posi = context.myacc.GetPositions