<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 每日期權風險數據整理 histDayGreeksIVOpt50ETF(Date(2015,10,12)).head() ``` | | Call | Call-Put | Put | | --- | -- | | | close | iv | delta | theta | gamma | vega | rho | strike | spot | forward | close | iv | delta | theta | gamma | vega | rho | | expDate | | | | | | | | | | | | | | | | | | | 2015-10-28 | 0.4331 | 0.4790 | 0.9830 | -0.1615 | 0.1779 | 0.0208 | 0.0842 | 1.85 | 2.288 | 2.283 | 0.0015 | 0.4793 | -0.0170 | -0.1059 | 0.1783 | 0.0208 | -0.0019 | | 2015-10-28 | 0.3821 | 0.4772 | 0.9692 | -0.2310 | 0.2949 | 0.0343 | 0.0850 | 1.90 | 2.288 | 2.283 | 0.0029 | 0.4765 | -0.0306 | -0.1725 | 0.2939 | 0.0341 | -0.0034 | | 2015-10-28 | 0.3335 | 0.4485 | 0.9568 | -0.2740 | 0.4144 | 0.0453 | 0.0859 | 1.95 | 2.288 | 2.283 | 0.0040 | 0.4473 | -0.0428 | -0.2129 | 0.4124 | 0.0450 | -0.0048 | | 2015-10-28 | 0.2874 | 0.4218 | 0.9381 | -0.3289 | 0.5861 | 0.0603 | 0.0862 | 2.00 | 2.288 | 2.283 | 0.0058 | 0.4220 | -0.0620 | -0.2690 | 0.5866 | 0.0604 | -0.0069 | | 2015-10-28 | 0.2420 | 0.2613 | 0.9773 | -0.1349 | 0.4175 | 0.0266 | 0.0929 | 2.05 | 2.288 | 2.283 | 0.0077 | 0.3873 | -0.0849 | -0.3130 | 0.8130 | 0.0768 | -0.0094 | 期權的隱含波動率微笑 + 下圖中,豎直虛線表示當日的標的50ETF收盤價 + 實際上計算PCIVD就是僅僅考慮豎直虛線附近的平值期權 + 看跌看漲隱含波動率微笑曲線中間的 Gap 的變化,正是我們關注點 ```py histDayPlotSmileVolatilityOpt50ETF(Date(2015,10,12)) ``` ![](https://box.kancloud.cn/2016-07-30_579cbdbccebd1.png) ```py def histDayPCIVD50ETF(date): ## PCIVD: Put Call Implied Volatility Diff; ## 看跌看漲期權隱含波動率價差,選取平值附近的近月和次近月合約構建 ## 看跌和看漲期權的隱含波動率指數,PCIVD即為兩指數之差。 # Uqer 計算期權的風險數據 opt = histDayGreeksIVOpt50ETF(date) # 下面展示波動率微笑 exp_dates = np.sort(opt.index.unique())[0:2] pcivd = pd.DataFrame(0.0, index=map(Date.toDateTime, [date]), columns=['nearPCIVD','nextPCIVD']) pcivd.index.name = 'date' ivd = [] for epd in exp_dates: opt_epd = opt[opt.index==epd] opt_epd[('Call-Put', 'diffKF')] = np.abs(opt_epd[('Call-Put', 'strike')] - opt_epd[('Call-Put', 'spot')]) opt_epd = opt_epd.set_index(('Call-Put', 'strike')) opt_epd.index.name = 'strike' opt_epd = opt_epd.sort([('Call-Put', 'diffKF')]).head(2) ivd_epd = opt_epd[('Put', 'iv')].mean() - opt_epd[('Call', 'iv')].mean() ivd.append(ivd_epd) pcivd.ix[Date.toDateTime(date)] = ivd return pcivd def histDayPCIVD50ETF_check(date): ## PCIVD: Put Call Implied Volatility Diff; ## 看跌看漲期權隱含波動率價差,選取平值附近的近月和次近月合約構建 ## 看跌和看漲期權的隱含波動率指數,PCIVD即為兩指數之差。 # Uqer 計算期權的風險數據 opt = histDayGreeksIVOpt50ETF(date) # 下面展示波動率微笑 exp_dates = np.sort(opt.index.unique())[0:2] pcivd = pd.DataFrame(0.0, index=map(Date.toDateTime, [date]), columns=['nearPCIVD', 'nearPutIV', 'nearCallIV','nextPCIVD', 'nextPutIV', 'nextCallIV']) pcivd.index.name = 'date' ivd = [] for epd in exp_dates: opt_epd = opt[opt.index==epd] opt_epd[('Call-Put', 'diffKF')] = np.abs(opt_epd[('Call-Put', 'strike')] - opt_epd[('Call-Put', 'spot')]) opt_epd = opt_epd.set_index(('Call-Put', 'strike')) opt_epd.index.name = 'strike' opt_epd = opt_epd.sort([('Call-Put', 'diffKF')]).head(2) ivd_epd = opt_epd[('Put', 'iv')].mean() - opt_epd[('Call', 'iv')].mean() ivd.append(ivd_epd) ivd.append(opt_epd[('Put', 'iv')].mean()) ivd.append(opt_epd[('Call', 'iv')].mean()) pcivd.ix[Date.toDateTime(date)] = ivd return pcivd def histPCIVD50ETF(beginDate, endDate): begin = Date.fromDateTime(beginDate) end = Date.fromDateTime(endDate) cal = Calendar('China.SSE') dates = cal.bizDatesList(begin, end) pcivd = pd.DataFrame() for dt in dates: pcivd_dt = histDayPCIVD50ETF(dt) pcivd = concat([pcivd, pcivd_dt]) pcivd['nearDiff'] = pcivd['nearPCIVD'].diff() pcivd['nextDiff'] = pcivd['nextPCIVD'].diff() return pcivd def histPCIVD50ETF_check(beginDate, endDate): begin = Date.fromDateTime(beginDate) end = Date.fromDateTime(endDate) cal = Calendar('China.SSE') dates = cal.bizDatesList(begin, end) pcivd = pd.DataFrame() for dt in dates: pcivd_dt = histDayPCIVD50ETF_check(dt) pcivd = concat([pcivd, pcivd_dt]) pcivd['nearPutDiff'] = pcivd['nearPutIV'].diff() pcivd['nearCallDiff'] = pcivd['nearCallIV'].diff() pcivd['nextPutDiff'] = pcivd['nextPutIV'].diff() pcivd['nextCallDiff'] = pcivd['nextCallIV'].diff() return pcivd ``` 計算PCIVD + 期權自15年2月9號上市 + 此處計算得到的數據可以用在后面幾條策略中 結果中的列分別為: + nearPCIVD:當月PCIVD + nextPCIVD:次月PCIVD + nearDiff:當月PCIVD與前一日值的變化量 + nextDiff:次月PCIVD與前一日值的變化量 ```py ## PCIVD計算示例 start = datetime(2015, 2, 9) # 回測起始時間 end = datetime(2015, 10, 12) # 回測結束時間 pcivd = histPCIVD50ETF(start, end) pcivd.tail() ``` | | nearPCIVD | nextPCIVD | nearDiff | nextDiff | | --- | --- | | date | | | | | | 2015-09-29 | 0.15540 | 0.15915 | 0.02660 | 0.0073 | | 2015-09-30 | 0.10205 | 0.14915 | -0.05335 | -0.0100 | | 2015-10-08 | 0.08845 | 0.10645 | -0.01360 | -0.0427 | | 2015-10-09 | 0.08320 | 0.10375 | -0.00525 | -0.0027 | | 2015-10-12 | 0.04635 | 0.07065 | -0.03685 | -0.0331 | ### 2.1 結合使用當月、次月 PCIVD 的擇時策略 策略思路:考慮當月 PCIVD 和 次月 PCIVD 的日變化量 + 當月 PCIVD 和 次月 PCIVD 同時變小(當月和次月的 PCIVDDiff 同時小于0),則今天全倉50ETF + 否則,清倉觀望 ```py start = datetime(2015, 2, 9) # 回測起始時間 end = datetime(2015, 10, 8) # 回測結束時間 benchmark = '510050.XSHG' # 策略參考標準 universe = ['510050.XSHG'] # 股票池 capital_base = 100000 # 起始資金 commission = Commission(0.0,0.0) refresh_rate = 1 # pcivd = histPCIVD50ETF(start, end) def initialize(account): # 初始化虛擬賬戶狀態 account.fund = universe[0] def handle_data(account): # 每個交易日的買入賣出指令 fund = account.fund # 獲取回測當日的前一天日期 dt = Date.fromDateTime(account.current_date) cal = Calendar('China.IB') last_day = cal.advanceDate(dt,'-1B',BizDayConvention.Preceding) #計算出倒數第一個交易日 last_day_str = last_day.strftime("%Y-%m-%d") # 計算買入賣出信號 try: # 拿取PCIVD數據 pcivd_near = pcivd.nearDiff.loc[last_day_str] pcivd_next = pcivd.nextDiff.loc[last_day_str] long_flag = True if pcivd_near < 0 and pcivd_next < 0 else False except: long_flag = False if long_flag: # 買入時,全倉殺入 try: approximationAmount = int(account.cash / account.referencePrice[fund] / 100.0) * 100 order(fund, approximationAmount) except: return else: # 賣出時,全倉清空 order_to(fund, 0) ``` ![](https://box.kancloud.cn/2016-07-30_579cbdbcea261.jpg) PCR 和 PCIVD 的良好擇時效果表明,雖然回測時間短,但它們均可以通過期權市場的信息來給出在現貨市場的買賣擇時信號,必要時建議我們空倉 ## 3. 監視最近 PCR 和 PCIVD 走勢 + 每日監視 PCR 和 PCIVD 近期走勢,指導次日操作 + 如果 PCR 和 PCIVD 的值降低,那么我們就在第二天買入 ```py cal = Calendar('China.IB') # Dates end = Date.todaysDate() end = cal.advanceDate(end,'-1B',BizDayConvention.Preceding) # 這里結束點選擇昨天,因為DataAPI的今日數據要到收盤后比較晚才能拿到;實際中可以自己調整 start = cal.advanceDate(end,'-15B',BizDayConvention.Preceding) # 開始點為七天前 ## 計算 PCR 和 PCIVD start = start.toDateTime() end = end.toDateTime() hist_pcr = histPCR50ETF(start, end) # 計算PCR hist_pcivd = histPCIVD50ETF(start, end) # 計算PCIVD hist_pcr[['nearVolPCR', 'nearValuePCR']].plot(style='s-') hist_pcivd[['nearPCIVD', 'nextPCIVD']].plot(style='s-') <matplotlib.axes.AxesSubplot at 0x852ba90> ``` ![](https://box.kancloud.cn/2016-07-30_579cbdbd11845.png) ![](https://box.kancloud.cn/2016-07-30_579cbdbd27bc2.png) PCIVD 圖中,近月期權的 PCIVD 在行權日為0,需要注意;行權日附近,可以以次近月期權的 PCIVD 走勢為參考
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看