iT邦幫忙

2021 iThome 鐵人賽

DAY 22
0
AI & Data

從零開始的套牢生活 - AI股票預測系統系列 第 22

[Day 22] 籌碼策略

第九章更新

由於之前寫第9天的時候還是股市小白,籌碼資料直接照搬了,
今天由於要處理籌碼資料所以乾脆整個打掉重寫了,
仿照第18天的格式,一樣把資料整理完後暫存,之後直接撈就可以了。
第九天完整程式碼

跟著大盤走

法人大量買超跟著買,賣超反之。

何謂「大量」

為了避免參雜人性因素,我採用標準差來定義「大量」,
只要超過2個標準差,即視為「異常值」
以投信為例:

class FollowerCheckCons(ConsStrategy):
    # Class variable for parameters tuning
    check_ratio = 0.3

    def init(self):
        super().init()
        self.Dealer_self_Balance = self.I(
            lambda buy, sell: buy - sell,
            self.data.df.Dealer_self_buy,
            self.data.df.Dealer_self_sell,
            plot=True,
        )

        self.Foreign_Investor_Balance = self.I(
            lambda buy, sell: buy - sell,
            self.data.df.Foreign_Investor_buy,
            self.data.df.Foreign_Investor_sell,
            plot=True,
        )

        self.Investment_Trust_Balance = self.I(
            lambda buy, sell: buy - sell,
            self.data.df.Investment_Trust_buy,
            self.data.df.Investment_Trust_sell,
            plot=True,
        )

        self.conservative = True

    def next(self):
        if self.Investment_Trust_Balance[-1] > (
            self.Investment_Trust_Balance.mean()
            + 2 * self.Investment_Trust_Balance.std()
        ):
            if len(self.trades) > 0:
                self.trades[0].close()

            self.buy()
        elif self.Investment_Trust_Balance[-1] < (
            self.Investment_Trust_Balance.mean()
            - 2 * self.Investment_Trust_Balance.std()
        ):
            if len(self.trades) > 0:
                self.trades[0].close()

            if self.conservative == False:
                self.sell()


class FollowerCheck(FollowerCheckCons):
    def init(self):
        super().init()

        self.conservative = False

上一篇
[Day 21] 策略(Strategy)
下一篇
[Day 23] 究竟AI能不能預測股價?
系列文
從零開始的套牢生活 - AI股票預測系統30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言