<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Competitive Securities > 來源:https://uqer.io/community/share/54b5c373f9f06c276f651a18 ## 策略實現: + 計算三只同一行業股票過去4天內前3天的平均成交價(VWAP),這里選用的是中國平安 (601318.XSHG)、中國太保 (601601.XSHG)和中國人壽 (601628.XSHG) + 當某兩只股票的價格低于`0.995 * VWAP`,同時另一只股票價格高于VWAP時,買入后者 + 當某兩只股票的價格高于`1.025 * VWAP`,同時另一只股票價格低于VWAP時,清空后者 ```py import pandas as pd import numpy as np from datetime import datetime from matplotlib import pylab import quartz import quartz.backtest as qb import quartz.performance as qp from quartz.api import * ``` ```py "Competitive Securities" start = pd.datetime(2012, 1, 1) end = pd.datetime(2014, 12, 1) bm = 'HS300' universe = ['601601.XSHG', '601318.XSHG', '601628.XSHG'] csvs = [] capital_base = 5000 window = 4 threshold_dn = 0.995 threshold_up = 1.025 refresh_rate = 4 def initialize(account): account.amount = 1000 account.universe = universe add_history('hist', window) def handle_data(account): vwap3, price = {}, {} for stk in account.universe: if stk not in account.hist: continue vwap3[stk] = sum(account.hist[stk]['turnoverValue'][:3])/sum(account.hist[stk]['turnoverVol'][:3]) price[stk] = account.hist[stk].iloc[window-1,:]['closePrice'] if len(vwap3)!=3: return stk_0 = account.universe[0] stk_1 = account.universe[1] stk_2 = account.universe[2] if price[stk_1] <= threshold_dn * vwap3[stk_1] and price[stk_2] <= threshold_dn * vwap3[stk_2] and price[stk_0] > vwap3[stk_0]: order(stk_0, account.amount) if price[stk_2] <= threshold_dn * vwap3[stk_2] and price[stk_0] <= threshold_dn * vwap3[stk_0] and price[stk_1] > vwap3[stk_1]: order(stk_1, account.amount) if price[stk_0] <= threshold_dn * vwap3[stk_0] and price[stk_1] <= threshold_dn * vwap3[stk_1] and price[stk_2] > vwap3[stk_2]: order(stk_2, account.amount) if price[stk_1] >= threshold_up * vwap3[stk_1] and price[stk_2] >= threshold_up * vwap3[stk_2] and price[stk_0] < vwap3[stk_0]: order_to(stk_0, 0) if price[stk_2] >= threshold_up * vwap3[stk_2] and price[stk_0] >= threshold_up * vwap3[stk_0] and price[stk_1] < vwap3[stk_1]: order_to(stk_1, 0) if price[stk_0] >= threshold_up * vwap3[stk_0] and price[stk_1] >= threshold_up * vwap3[stk_1] and price[stk_2] < vwap3[stk_2]: order_to(stk_2, 0) ``` ![](https://box.kancloud.cn/2016-07-30_579cbdb31c0e7.jpg) ```py perf = qp.perf_parse(bt) out_keys = ['annualized_return', 'volatility', 'information', 'sharpe', 'max_drawdown', 'alpha', 'beta'] for k in out_keys: print '%s: %s' % (k, perf[k]) annualized_return: 0.14708285 volatility: 0.285959506628 information: 0.525131029268 sharpe: 0.395275720443 max_drawdown: 0.391931712536 alpha: 0.089663482291 beta: 1.15117691695 ``` ```py perf['cumulative_return'].plot() perf['benchmark_cumulative_return'].plot() pylab.legend(['current_strategy','HS300']) <matplotlib.legend.Legend at 0x55bf290> ``` ![](img/xn6FvydrLyNAAAAAElFTkSuQmCC.png)
                  <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>

                              哎呀哎呀视频在线观看