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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 用5日均線和10日均線進行判斷 --- 改進版 > 來源:https://uqer.io/community/share/561e3a65f9f06c4ca82fb5ec ## 1、 修改Adobe同學的代碼 ```py data=DataAPI.MktEqudGet(ticker="600030",beginDate="20131001") #選取600030股票 a = data.closePrice B = [] n = len(a) for i in range(10, n): x5 = a[i-5:i].mean() #5日均線值 x10 = a[i-10:i].mean() #10日均線值 B.append(x5 > x10) ``` ```py import matplotlib.pyplot as plt o = data.openPrice m = len(B) w = 0 #利潤 cash = 1000000 #操作金額1億,但考慮買的份額為100的整數,取1百萬 amount = 0 PL = [] #利潤w的數組 for i in range(1, m): k = i + 10 if B[i-1] == 0 and B[i] == 1 and not amount: amount = cash // o[k] #買入份額 cash -= o[k] * amount elif B[i-1] == 1 and B[i]==0 and amount: cash += o[k] * amount #賣出的金額 amount = 0 # print cash, amount PL.append(cash + o[k] * amount) print("利潤:{}".format(PL[-1])) plt.plot(PL,color="green",label="Profit and Loss") plt.xlabel("Date") plt.ylabel("Price") plt.show() plt.plot(a[10:], color="red",label="Profit and Loss") plt.show() 利潤:1559132.78 ``` ![](https://box.kancloud.cn/2016-07-30_579cbb01c8f63.png) ![](https://box.kancloud.cn/2016-07-30_579cbb01dc6ef.png) ## 2、 Uqer框架相同策略 ```py import numpy as np start = '2013-10-01' # 回測起始時間 end = '2015-10-13' # 回測結束時間 benchmark = 'SH50' # 策略參考標準 universe = ['600030.XSHG'] # 股票池 中信證券 capital_base = 100000 # 起始資金 commission = Commission(0.0,0.0) window_short = 5 # 短均線周期 window_long = 10 # 長均線周期 def initialize(account): # 初始化虛擬賬戶狀態 account.fund = universe[0] def handle_data(account): # 每個交易日的買入賣出指令 cp_hist = account.get_attribute_history('closePrice', window_long)[account.fund] short_mean = np.mean(cp_hist[-window_short:]) # 計算短均線值 long_mean = np.mean(cp_hist[-window_long:]) #計算長均線值 # 計算買入賣出信號 if short_mean - long_mean > 0: if account.fund not in account.valid_secpos: # 空倉時全倉買入,買入股數為100的整數倍 approximationAmount = int(account.cash / account.referencePrice[account.fund] / 100) * 100 order(account.fund, approximationAmount) else: # 賣出時,全倉清空 if account.fund in account.valid_secpos: order_to(account.fund, 0) ``` ![](https://box.kancloud.cn/2016-07-30_579cbb01f01db.jpg)
                  <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>

                              哎呀哎呀视频在线观看