#本文分析牛市看张价差和熊市看跌价差的组合策略效果: #牛市看涨价差采用买入平值看涨期权, sell a call option #熊市看跌价差组合采用买入平值看跌期权 with a higher right price, and sell a put option that has a lower line of right price ##### In fact, there are many different ways to construct the price difference combination ################################### Import pandas as PD import NumPy as NP import Matplotlib.pyplot as Plt from Lib.qiquan import* ###################################################################################### ##### #读取50etf标的 df=pd.read_excel (' 50etf_fund.xlsx ') df.index=df[' tradedate '] #获取交易日期 date=list (df[' tradedate ']) ### ################################################################# profit=[] for I in range (1,len (date)): Day=dat E[i] Etf_price_close=float (df[df[' tradedate '].isin ([day]) [' Close ']] etf_price_open=float (df[df[' tradedate
'].isin ([day]] [' open ']] secid_data_low=list (Get_low (df,day) [' Secid ']) #print data #获取近月代码 Near_c_low=secid_data_low[-2] near_p_low=secid_data_low[-1] ##### secid_data_high=list (Get_high ( Df,day) [' Secid ']) #print data #获取近月代码 NEar_c_high=secid_data_high[-2] near_p_high=secid_data_high[-1] #获取近月价格 secid_data_near=list (get_n Ear (Df,day) [' Secid ']) #print data #获取近月代码 near_c_near=secid_data_near[-2] Near_p_near=seci
D_data_near[-1] ##### option_c_data_low=dataapi.mktoptdget (Tradedate=day, Secid=near_c_low,optid=u "", Ticker=u "", Begindate=u "", Enddate=u "", Field=u "", pandas= "1") option_p_data_l Ow=dataapi.mktoptdget (Tradedate=day,secid=near_p_low, Optid=u "", Ticker=u "", be
Gindate=u "", Enddate=u "", Field=u "", pandas= "1") Option_c_data_high=dataapi.mktoptdget (Tradedate=day,
Secid=near_c_high,optid=u "", Ticker=u "", Begindate=u "", Enddate=u "", Field=u "", pandas= "1") Option_p_data_high=dataapi.mktoptdget (Tradedate=day,secid=near_p_high, OptI D=u "", Ticker=u "", BegindaTe=u "", Enddate=u "", Field=u "", pandas= "1") Option_c_data_near=dataapi.mktoptdget (Tradedate=day, Secid=near_c_near,optid=u "", Ticker=u "", Begindate=u "", Enddate=u "", Field=u "", pandas= "1") opt Ion_p_data_near=dataapi.mktoptdget (Tradedate=day,secid=near_p_near, Optid=u "" , Ticker=u "", Begindate=u "", Enddate=u "", Field=u "", pandas= "1") buy_condition=get_up (df,date,i,20) #print Buy_ condition if buy_condition==false:money= (float (option_p_data_near[' closeprice '))-float (Option_p_data_ near[' Openprice '])-float (option_c_data_low[' Closeprice ']) +float (option_c_data_low[' Openprice ')) *10000 profit. Append (Money) if buy_condition==true:money= (float (option_c_data_near[' closeprice '))-float (Option_c_da ta_near[' Openprice '])-float (option_c_data_high[' Closeprice ']) +float (option_c_data_high[' OpenPrice ')) *10000 PR Ofit.append (Money) all_pROFIT=PD. Series (Profit). Cumsum ()
Note: The code is for reference only, please do not use directly, there is a bug. There is also no question of handling fees.