#!/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["回测期权"]
fee = PBObj();
fee.OpenUnit = 1
fee.CloseRate = 0.000023
fee.CloseTodayRate = 0.000345
fee.MiniFee = 0
#每天行情初始化的,获取当前的50etf对应的平值期权
def OnMarketQuotationInitialEx(context, exchange,daynight):
#过滤掉非上交所的信号
if exchange != 'SHSE':
return
#获取期权标的
g.biaodi = '510050.SHSE'
klinedata = GetHisData2(g.biaodi,BarType.Day)
lastclose = klinedata[-1].close
#获取当月平价认购期权
g.atmopc = GetAtmOptionContract(g.biaodi,0,lastclose,0)
#订阅日K线用来驱动onbar事件
SubscribeBar(g.atmopc,BarType.Day)
#在k线出现的时候,如果没持仓就卖开,如果有就平仓
def OnBar(context,code,ba
|