#!/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["回测期权"]#每天行情初始化的,获取当前的50etf对应的平值期权
def OnMarketQuotationInitialEx(context, exchange,daynight):#过滤掉非上交所的信号if exchange != 'SHSE':return#获取期权标的g.code = '510050.SHSE'klinedata = GetHisData2(g.code,BarType.Day)lastclose = klinedata[-1].close#获取当月平价认购期权g.atmopc = GetAtmOptionContract(g.code,0,lastclose,0)#订阅日K线用来驱动onbar事件SubscribeBar(g.atmopc,BarType.Day)
#获取期权合约,包括call和put合约
def Getop(code):dyndata = GetQuote(code)#获取标的价格并计算实值期权价格now1 = dyndata.nownow50 = round(now1,1) + 0.05#计算期权合约的到期年月cutime = GetCurr