<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國際加速解決方案。 廣告
                # 基于Random Forest的決策策略 > 來源:https://uqer.io/community/share/54a10ef8f9f06c4bb886324b 版本:1.0 作者:李丞 聯系:cheng.li@datayes.com 利用隨機樹分類算法,通過歷史價格的上升狀態變化規律,預測下一日股價變動的方向。預測上漲則買入,下跌則賣出(如果可以的話); ```py from sklearn.ensemble import RandomForestClassifier from collections import deque import pandas as pd import numpy as np start = pd.datetime(2010, 4, 1) end = pd.datetime(2014, 9, 16) longest_history = 1 bm = 'HS300' universe = ['600000.XSHG'] csvs = [] capital_base = 1e5 refresh_rate = 1 window_length = 10 def initialize(account): account.security = universe[0] account.window_length = window_length account.classifier = RandomForestClassifier() # 先進先出的deque序列,設定了最長的長度,在序列超過最長長度的時候,會將頭部序列移出 account.recent_prices = deque(maxlen=account.window_length+2) # 保存最近的股價 account.X = deque(maxlen=100) # 自變量 account.Y = deque(maxlen=100) # 應變量 account.prediction = 0 # 保存最近的預測值 def handle_data(account): hist = account.get_history(1) if account.security in hist: account.recent_prices.append(hist[account.security]['closePrice'][0]) # 更新最近的股價 if len(account.recent_prices) >= account.window_length+2: # 如果我們已經獲取了足夠的股價 RecentPrice=list(account.recent_prices) # 將deque轉換為對應的list # 制作一組1和0,標記股價是否相對于上一日價格上升。 changes = np.diff(RecentPrice) > 0 account.X.append(RecentPrice[1:-1]) account.Y.append(changes[-1]) if len(account.Y) >= 100: # 已經擁有足夠的數據im account.classifier.fit(account.X, account.Y) # 設定模型 account.prediction = account.classifier.predict(changes[1:]) # 預測 # 如果過大0.5,買入;小于0.5,賣出 if account.prediction > 0.5: buyAmount = int(account.position.cash / hist[account.security]['closePrice'][0]) order(account.security, buyAmount) else: order_to(account.security, 0) ``` ![](https://box.kancloud.cn/2016-07-30_579cbdac47ad8.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>

                              哎呀哎呀视频在线观看