Beispiel #1
0
    def run(self, hd):
        '''
        Calculate!
        '''
        delay = 1

        rank1 = Op.rank_col(hd['volume'])
        rank2 = Op.rank_col(hd['vwap'])

        corr = rank1.rolling(5).corr(rank2)
        rank3 = Op.rank_col(corr)

        tsmax = rank3.rolling(5).max()

        data = -tsmax

        start = hd['startidx']
        end = hd['endidx']

        for di in range(start, end + 1):
            self._alpha[di - start, :] = data.iloc[di - delay, :]
        print("Alpha is finished!")

        self._alpha = Op.Neutralize('IND', self._alpha, start, end)
        print("Neutralize is finished!")
Beispiel #2
0
    def run(self, hd):
        '''
        Calculate!
        '''
        delay = 1

        data1 = (hd['high'] - hd['low']) / (hd['close'].rolling(5).sum() / 5)

        #rank1 = self.rank_col(data1)
        rank1 = Op.rank_col(data1.shift(2))
        rank2 = Op.rank_col(hd['volume'])

        data3 = data1 / (hd['vwap'] - hd['close'])
        data3[data3 == 0] = np.nan
        data = rank1 * rank2 / data3

        start = hd['startidx']
        end = hd['endidx']

        #self.alpha = data.iloc[start-delay:end+1,:]

        alpha = np.full([self._alpha.shape[0], self._alpha.shape[1]], np.nan)

        for di in range(start, end + 1):
            alpha[di - start, :] = data.iloc[di - delay, :]

        print("Alpha is finished!")

        alpha = Op.Neutralize('IND', alpha, start, end)
        print("Neutralize is finished!")

        self._alpha = Op.personalize(alpha)
        print("Person is finished!")
Beispiel #3
0
    def run(self, hd):
        '''
        Calculate!
        '''
        delay = 1
        #data = self.close.shift(5)-self.close
        data1 = hd['vwap'] - hd['close']
        data1[data1 < 3] = 3
        rank1 = Op.rank_col(data1)

        data2 = hd['vwap'] - hd['close']
        data2[data2 > 3] = 3
        rank2 = Op.rank_col(data2)
        volume = hd['volume']
        volume[volume == 0] = np.nan
        rank3 = Op.rank_col(volume - volume.shift(3))
        data = rank1 + rank2 * rank3

        start = hd['startidx']
        end = hd['endidx']

        #self.alpha = data.iloc[start-delay:end+1,:]

        for di in range(start, end + 1):
            self._alpha[di - start, :] = data.iloc[di - delay, :]
        print("Alpha is finished!")

        self._alpha = Op.Neutralize('IND', self._alpha, start, end)
        print("Neutralize is finished!")

        self._alpha = Op.personalize(self._alpha)
        print("Personize is finished!")
Beispiel #4
0
    def run(self, hd):
        '''
        Calculate!
        '''
        delay = 1
        #data = self.close.shift(5)-self.close
        rank1 = Op.rank_col(hd['volume'])
        rank2 = Op.rank_col(hd['vwap'])
        corr = rank1.rolling(5).corr(rank2)
        rank3 = Op.rank_col(corr)
        data = -1 * rank3.rolling(5).max()
        #for ii in range(window, corr.shape[0]+1):

        start = hd['startidx']
        end = hd['endidx']

        #self.alpha = data.iloc[start-delay:end+1,:]

        for di in range(start, end + 1):
            self._alpha[di - start, :] = data.iloc[di - delay, :]
        print("Alpha is finished!")

        self._alpha = Op.Neutralize('IND', self._alpha, start, end)
        print("Neutralize is finished!")

        self._alpha = Op.personalize(self._alpha)
        print("Personize is finished!")
Beispiel #5
0
    def run(self, hd):
        '''
        Calculate!
        '''
        delay = 1
        #data = self.close.shift(5)-self.close
        lnvol = np.log(hd['volume'])
        lnvol_d = lnvol - lnvol.shift()
        rank1 = Op.rank_col(lnvol_d)
        rank2 = Op.rank_col((hd['close'] - hd['open']) / hd['open'])
        corr = rank1.rolling(6).corr(rank2)
        data = -corr
        #data = self.Rank(data)

        start = hd['startidx']
        end = hd['endidx']

        #self.alpha = data.iloc[start-delay:end+1,:]

        for di in range(start, end + 1):
            self._alpha[di - start, :] = data.iloc[di - delay, :]
        print("Alpha is finished!")

        self._alpha = Op.Neutralize('IND', self._alpha, start, end)
        print("Neutralize is finished!")

        self._alpha = Op.personalize(self._alpha)
        print("Personize is finished!")
Beispiel #6
0
    def run(self, hd):
        '''
        Calculate!
        '''
        delay = 1

        self.volume[self.volume == 0] = np.nan

        data1 = self.volume.rolling(5).mean()
        data1 = data1.rolling(26).sum()
        corr = self.vwap.rolling(5).corr(data1)
        data1 = corr.ewm(7).mean()
        rank1 = self.rank_col(data1)
        rank1 = np.array(rank1)
        rank2 = self.rank_col(self.open)
        rank3 = self.rank_col(self.volume.rolling(15).mean())
        corr2 = rank2.rolling(21).corr(rank3)
        window = 7
        rank4 = Op.tsrank(corr2, window)
        #rank4 = np.full([corr2.shape[0], corr2.shape[1]], np.nan)
        #for ii in range(window, corr2.shape[0]+1):
        #    tmp = corr2.iloc[ii-window:ii,:]
        #    rank4[ii-1,:] = self.rank_row(tmp).iloc[-1,:]

        data2 = pd.DataFrame(rank4)
        data2 = data2.ewm(8).mean()
        rank5 = self.rank_col(data2)
        rank5 = np.array(rank5)
        data = rank5 - rank1
        data = pd.DataFrame(data)
        #start = np.where(data.index == self.start)[0].tolist()[0]
        #end = np.where(data.index == self.end)[0].tolist()[0]

        #self.alpha = data.iloc[start-delay:end+1,:]

        start = hd['startidx']
        end = hd['endidx']

        for di in range(start, end + 1):
            self.alpha[di - start, :] = data.iloc[di - delay, :]
        print("Alpha is finished!")

        self._alpha = Op.Neutralize('IND', self._alpha, start, end)
        print("Neutralize is finished!")
Beispiel #7
0
    def run(self, hd):
        '''
        Calculate!
        '''
        delay = 1
        #data = self.close.shift(5)-self.close
        data = hd['close'].rolling(10).corr(hd['volume'])
        data = -Op.rank_col(data)

        start = hd['startidx']
        end = hd['endidx']

        #self.alpha = data.iloc[start-delay:end+1,:]

        for di in range(start, end + 1):
            self._alpha[di - start, :] = data.iloc[di - delay, :]
        print("Alpha is finished!")

        self._alpha = Op.Neutralize('IND', self._alpha, start, end)
        print("Neutralize is finished!")
Beispiel #8
0
    def run(self, hd):
        '''
        Calculate!
        '''
        delay = 1
        #data = self.close.shift(5)-self.close
        data = -hd['amount'].rolling(10).std()
        #data = self.Rank(data)

        start = hd['startidx']
        end = hd['endidx']

        #self.alpha = data.iloc[start-delay:end+1,:]

        for di in range(start, end + 1):
            self._alpha[di - start, :] = data.iloc[di - delay, :]
        print("Alpha is finished!")

        self._alpha = Op.Neutralize('IND', self._alpha, start, end)
        print("Neutralize is finished!")

        self._alpha = Op.personalize(self._alpha)
        print("Personize is finished!")
Beispiel #9
0
    def predict(self):
        nums = self.col  #each time feed how much data

        for key, model in self._models.items():
            for ii in range(self.row):
                x = self._x[ii * nums:(ii + 1) * nums, :]
                xnanrow = np.where(pd.isnull(x))[0]
                nanrow = np.unique(xnanrow)
                x[pd.isnull(x)] = 0
                y = model.predict(x)
                y[nanrow] = np.nan
                self._alpha[ii, :] = y.reshape(1, -1)

        self._alpha = Op.Neutralize('IND', self._alpha, self.start, self.end)
        print("Neutralize is finished!")
Beispiel #10
0
    def run(self, hd):
        '''
        Calculate!
        '''
        delay = 1
        #data = self.close.shift(5)-self.close
        data1 = ((hd['close'] - hd['low']) -
                 (hd['high'] - hd['close'])) / (hd['high'] - hd['low'])
        data = (data1 - data1.shift()) * -1
        #data = self.Rank(data)

        start = hd['startidx']
        end = hd['endidx']

        for di in range(start, end + 1):
            self._alpha[di - start, :] = data.iloc[di - delay, :]
        print("Alpha is finished!")

        self._alpha = Op.Neutralize('IND', self._alpha, start, end)
        print("Neutralize is finished!")
Beispiel #11
0
    def run(self, hd):
        '''
        Calculate!
        '''
        delay = 0
        #data = self.close.shift(5)-self.close
        data = hd['close'] - hd['open']

        start = hd['startidx']
        end = hd['endidx']
        #start = np.where(data.index == self.start)[0].tolist()[0]
        #end = np.where(data.index == self.end)[0].tolist()[0]

        #self.alpha = data.iloc[start-delay:end+1,:]

        for di in range(start, end + 1):
            self._alpha[di - start, :] = data.iloc[di - delay, :]
        print("Alpha is finished!")

        self._alpha = Op.Neutralize('IND', self._alpha, start, end)
Beispiel #12
0
def run():
    pro = ts.pro_api()
    today = time.strftime('%Y.%m.%d', time.localtime(time.time()))
    today = today.replace('.', '')  #consider +1
    lastMonth = time.strftime('%Y.%m.%d',
                              time.localtime(time.time() - 2592000))
    lastMonth = lastMonth.replace('.', '')
    close = pd.DataFrame()
    volume = pd.DataFrame()

    stkdata = pro.query('stock_basic',
                        exchange='',
                        list_status='L',
                        fields='ts_code, name, industry')
    i = 1
    for code in stkdata['ts_code']:
        if (i % 1000 == 0):
            print("finish", i // 1000, "* 25% work")
        i = i + 1
        try:
            df = ts.pro_bar(ts_code=code,
                            adj='hfq',
                            start_date=lastMonth,
                            end_date=today)
            close[code] = df['close'].iloc[::-1]
            volume[code] = (df['amount'] / df['close'] * 10).iloc[::-1]
        except Exception as e:
            print(e)

    # close = oclose.copy()
    # volume = ovolume.copy()

    cols = np.where(pd.isnull(close) | pd.isnull(volume))[1]
    colnames = close.columns[cols].unique()
    for name in colnames:
        del close[name]
        del volume[name]

    rank1 = Op.rank_col(volume)
    rank2 = Op.rank_col(close)

    corr = rank1.rolling(5).corr(rank2)
    rank3 = Op.rank_col(corr)

    tsmax = rank3.rolling(5).max()

    data = -tsmax

    #alpha = np.full([1, close.shape[1]], np.nan)
    alpha = data.iloc[-1, :]
    print("Alpha is finished!")

    alpha = Neutralize(alpha, stkdata)
    #print("Neutralize is finished!")
    alpha[pd.isnull(alpha)] = -10
    idx = np.argpartition(alpha, -5)[-5:]

    stks = alpha[idx]

    inx = pro.index_daily(ts_code='000905.SH',
                          start_date=lastMonth,
                          end_date=today)['close'][::-1]

    trend = (inx.rolling(5).mean() - 1.01 * inx.rolling(10).mean()).iloc[-1]

    content = 'trend: ' + str(trend) + '\n'
    for ii in range(stks.shape[0]):
        content = content + str(stks.index[ii]) + ':' + str(
            stks.iloc[ii]) + '\n'

    send(content)

    return
Beispiel #13
0
 def __init__(self, v: Operator.Op, pos: int = None) -> None:
     super().__init__(v, pos)
     self.__chd: List[Tok] = []
     self.__argc: int = v.argc()
Beispiel #14
0
 def v(self, v: Operator.Op) -> None:
     Tok.v.fset(self, v)
     self.__argc: int = v.argc()