示例#1
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!")
示例#2
0
    def run(self, hd):
        '''
        Calculate!
        '''
        delay = 1

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

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

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

        data = -tsmax

        startdate = hd['startdate']
        enddate = hd['enddate']
        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!")

        self._alpha = Op.personalize(self._alpha)
        print("Person is finished!")

        self._alpha, self.trend = Op.trend(self._alpha, startdate, enddate)
        print("Trend is finished!")
示例#3
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!")
示例#4
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!")
示例#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!")
示例#6
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!")
示例#7
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