Пример #1
0
 def forward(self, close_ts, volume_ts):
     ts = tsf.rolling_corr(close_ts, volume_ts, 2)
     return -1 * (tsf.rank(tsf.rolling_mean_(tsf.shift(close_ts, 5), 20)) *
                  ts * tsf.rank(
                      tsf.rolling_corr(tsf.rolling_sum_(close_ts, 5),
                                       tsf.rolling_sum_(close_ts, 20), 2))
                  )  # .values
Пример #2
0
 def forward(self, close_ts, volume_ts):
     output_tensor = (-1 * (
         (tsf.rank((tsf.rolling_sum_(tsf.shift(close_ts, 5), 20) / 20)) *
          tsf.rolling_corr(close_ts, volume_ts, 2)) * tsf.rank(
              tsf.rolling_corr(tsf.rolling_sum_(close_ts, 5),
                               tsf.rolling_sum_(close_ts, 20), 2))))
     return output_tensor
Пример #3
0
 def forward(self, close_ts, volume_ts):
     output_tensor = (-1 * ((tsf.rank(
         ((torch.sign((close_ts - tsf.shift(close_ts, 1))) + torch.sign(
             (tsf.shift(close_ts, 1) - tsf.shift(close_ts, 2)))) +
          torch.sign((tsf.shift(close_ts, 2) - tsf.shift(close_ts, 3)))))) *
                            tsf.rolling_sum_(volume_ts, 5)) /
                      tsf.rolling_sum_(volume_ts, 20))
     return output_tensor
Пример #4
0
 def forward(self, close_ts, volume_ts):
     delta_close = tsf.diff(close_ts, 1)
     inner = torch.sign(delta_close) + torch.sign(tsf.shift(
         delta_close, 1)) + torch.sign(tsf.shift(delta_close, 2))
     alpha = (
         (1.0 - tsf.rank(inner)) *
         tsf.rolling_sum_(volume_ts, 5)) / tsf.rolling_sum_(volume_ts, 20)
     return alpha
Пример #5
0
 def forward(self, high_ts, low_ts, close_ts):
     zeros = torch.zeros(high_ts.size())
     output_tensor = tsf.rolling_sum_(
         torch.max(zeros, high_ts - tsf.shift(close_ts, 1)),
         20) / tsf.rolling_sum_(
             torch.max(zeros,
                       tsf.shift(close_ts, 1) - low_ts), 20) * 100
     return output_tensor
Пример #6
0
 def forward(self, low_ts, return_ts, volume_ts):
     output_tensor = ((
         ((-1 * tsf.rolling_min(low_ts, 5)) +
          tsf.shift(tsf.rolling_min(low_ts, 5), 5)) * tsf.rank(
              ((tsf.rolling_sum_(return_ts, 240) -
                tsf.rolling_sum_(return_ts, 20)) / 220))) *
                      tsf.rolling_min(volume_ts, 5))
     return output_tensor
Пример #7
0
def mfi(high_ts, low_ts, close_ts, total_turnover_ts, timeperiod=14):
    TP = (high_ts + low_ts + close_ts) / 3
    MF = TP * total_turnover_ts
    zero = torch.zeros_like(high_ts)
    PMF = torch.where(MF > tsf.shift(MF, window=1), MF, zero)
    NMF = torch.where(MF < tsf.shift(MF, window=1), MF, zero)
    MR = tsf.rolling_sum_(PMF, window=timeperiod) / tsf.rolling_sum_(NMF, window=timeperiod)
    MFI = 100 - (100 / (1 + MR))
    return MFI
Пример #8
0
 def forward(self, high_ts, low_ts, volume_ts, vwap_ts, close_ts):
     output_tensor = ((tsf.rank(
         tsf.shift(((high_ts - low_ts) /
                    (tsf.rolling_sum_(close_ts, 5) / 5)), 2)) *
                       tsf.rank(tsf.rank(volume_ts))) /
                      (((high_ts - low_ts) /
                        (tsf.rolling_sum_(close_ts, 5) / 5)) /
                       (vwap_ts - close_ts)))
     return output_tensor
Пример #9
0
 def forward(self, close_ts):
     cond = ((tsf.diff((tsf.rolling_sum_(close_ts, 100) / 100), 100) /
              tsf.shift(close_ts, 100)) < 0.05) | (
                  (tsf.diff((tsf.rolling_sum_(close_ts, 100) / 100), 100) /
                   tsf.shift(close_ts, 100)) == 0.05)
     consequence1 = (-1 * (close_ts - tsf.rolling_min(close_ts, 100)))
     consequence2 = (-1 * tsf.diff(close_ts, 3))
     output_tensor = torch.where(cond, consequence1, consequence2)
     return output_tensor
Пример #10
0
 def forward(self, vwap_ts, volume_ts, low_ts):
     output_tensor = (tsf.rank(
         tsf.rolling_corr(
             tsf.rolling_sum_(((low_ts * 0.35) + (vwap_ts * 0.65)), 20),
             tsf.rolling_sum_(tsf.rolling_mean_(volume_ts, 40), 20), 7)) +
                      tsf.rank(
                          tsf.rolling_corr(tsf.rank(vwap_ts),
                                           tsf.rank(volume_ts), 6)))
     return output_tensor
Пример #11
0
 def forward(self, high_ts, close_ts, volume_ts, vwap_ts):
     output_tensor = ((((tsf.rank(
         (1 / close_ts)) * volume_ts) / tsf.rolling_mean_(volume_ts, 20)) *
                       ((high_ts * tsf.rank((high_ts - close_ts))) /
                        (tsf.rolling_sum_(high_ts, 5) / 5))) - tsf.rank(
                            (vwap_ts - tsf.shift(vwap_ts, 5))))
     return output_tensor
Пример #12
0
def ad(high_ts, low_ts, close_ts, volume_ts, fastperiod=3, slowperiod=10):
    zero = torch.zeros_like(high_ts, dtype=high_ts.dtype, device=high_ts.device)
    CLV = torch.where(high_ts == low_ts, zero, (2*close_ts-high_ts-low_ts)/(high_ts-low_ts))
    AD = tsf.rolling_sum_(volume_ts*CLV, window=2)
    AD[0] = CLV[0]
    ADOSC = tsf.ema(AD, window=fastperiod) - tsf.ema(AD, window=slowperiod)
    return AD, ADOSC
Пример #13
0
 def forward(self, open_ts, low_ts):
     cond = open_ts >= tsf.shift(open_ts, 1)
     zeros = torch.zeros(open_ts.size())
     inner = torch.where(
         cond, zeros,
         torch.max((open_ts - low_ts), (open_ts - tsf.shift(open_ts, 1))))
     output_tensor = tsf.rolling_sum_(inner, 20)
     return output_tensor
Пример #14
0
 def forward(self, close_ts, volume_ts):
     cond1 = close_ts > tsf.shift(close_ts, 1)
     zeros = torch.zeros(close_ts.size())
     inner1 = torch.where(cond1, volume_ts, zeros)
     cond2 = close_ts <= tsf.shift(close_ts, 1)
     inner2 = tsf.rolling_sum_(torch.where(cond2, volume_ts, zeros), self.window)
     output_tensor = inner1 / inner2
     return output_tensor
Пример #15
0
 def forward(self, close_ts, low_ts, high_ts):
     cond1 = tsf.diff(close_ts, 1) > 0
     zeros = torch.zeros(close_ts.size())
     inner = torch.where(cond1, torch.min(low_ts, tsf.shift(close_ts, 1)),
                         torch.max(high_ts, tsf.shift(close_ts, 1)))
     cond2 = tsf.diff(close_ts, 1) == 0
     inner = torch.where(cond2, zeros, inner)
     output_tensor = tsf.rolling_sum_(inner, 20)
     return output_tensor
Пример #16
0
 def forward(self, close_ts, returns_ts):
     return tsf.rolling_min(
         tsf.rank(
             tsf.rank(
                 tsf.rolling_scale(
                     torch.log(
                         tsf.rolling_sum_(
                             tsf.rank(
                                 tsf.rank(-1 * tsf.rank(
                                     tsf.diff((close_ts - 1), 5)))), 2))))),
         5) + tsf.ts_rank(tsf.shift((-1 * returns_ts), 6), 5)
Пример #17
0
def uos(high_ts, low_ts, close_ts, timeperiod1=7, timeperiod2=14, timeperiod3=28, timeperiod4=6):
    TH = torch.max(high_ts, tsf.shift(close_ts, window=1))
    TL = torch.min(low_ts, tsf.shift(close_ts, window=1))
    ACC1 = tsf.rolling_sum_(close_ts-TL, window=timeperiod1) / tsf.rolling_sum_(TH-TL, window=timeperiod1)
    ACC2 = tsf.rolling_sum_(close_ts-TL, window=timeperiod2) / tsf.rolling_sum_(TH-TL, window=timeperiod2)
    ACC3 = tsf.rolling_sum_(close_ts-TL, window=timeperiod3) / tsf.rolling_sum_(TH-TL, window=timeperiod3)
    UOS = (ACC1*timeperiod2*timeperiod3 + ACC2*timeperiod1*timeperiod3 + ACC3*timeperiod1*timeperiod2) * 100 / (timeperiod1*timeperiod2 + timeperiod1*timeperiod3 + timeperiod2*timeperiod3)
    MAUOS = tsf.ema(UOS, window=timeperiod4)
    return UOS, MAUOS
Пример #18
0
 def forward(self, close_ts, open_ts, high_ts, low_ts):
     inner1 = tsf.rolling_sum_(
         16 * (close_ts - tsf.shift(close_ts, 1) +
               (close_ts - open_ts) / 2 + tsf.shift(close_ts, 1) -
               tsf.shift(open_ts, 1)))
     cond1 = (torch.abs(high_ts - tsf.shift(close_ts, 1)) >
              torch.abs(low_ts - tsf.shift(close_ts, 1))) & (
                  torch.abs(high_ts - tsf.shift(close_ts, 1)) >
                  torch.abs(high_ts - tsf.shift(low_ts, 1)))
     sequence1 = torch.abs(high_ts - tsf.shift(close_ts, 1)) + torch.abs(
         low_ts - tsf.shift(close_ts, 1)) / 2 + torch.abs(
             tsf.shift(close_ts, 1) - tsf.shift(open_ts, 1)) / 4
     cond2 = (torch.abs(low_ts - tsf.shift(close_ts, 1)) >
              torch.abs(high_ts - tsf.shift(low_ts, 1))) & (
                  torch.abs(low_ts - tsf.shift(close_ts, 1)) >
                  torch.abs(high_ts - tsf.shift(close_ts, 1)))
     sequence2 = torch.abs(high_ts - tsf.shift(low_ts, 1)) + torch.abs(
         tsf.shift(close_ts, 1) - tsf.shift(open_ts, 1)) / 4
     inner2 = torch.where((~cond1 & ~cond2), sequence2, sequence1)
     output_tensor = inner1 / inner2
     return output_tensor
Пример #19
0
 def forward(self, high_ts, low_ts, close_ts):
     zeros = torch.zeros(high_ts.size())
     LD = tsf.shift(low_ts, 1) - low_ts
     HD = high_ts - tsf.shift(high_ts, 1)
     TR = torch.max(
         torch.max(high_ts - low_ts,
                   torch.abs(high_ts - tsf.shift(close_ts, 1))),
         torch.abs(low_ts - tsf.shift(close_ts, 1)))
     cond1 = (LD > 0) & (LD > HD)
     inner1 = torch.where(cond1, LD, zeros)
     cond2 = (HD > 0) & (HD > LD)
     inner2 = torch.where(cond2, HD, zeros)
     cond3 = (LD > 0) & (LD > HD)
     inner3 = torch.where(cond3, LD, zeros)
     cond4 = (HD > 0) & (HD > LD)
     inner4 = torch.where(cond4, HD, zeros)
     output_tensor = tsf.rolling_mean_(
         tsf.rolling_sum_(inner1, 14) * 100 / tsf.rolling_sum_(TR, 14) -
         tsf.rolling_sum_(inner2, 14) * 100 / tsf.rolling_sum_(TR, 14) /
         (tsf.rolling_sum_(inner3, 14) * 100 / tsf.rolling_sum_(TR, 14) +
          tsf.rolling_sum_(inner4, 14) * 100 / tsf.rolling_sum_(TR, 14)) *
         100, 6)
     return output_tensor
Пример #20
0
 def forward(self, high_ts, close_ts, low_ts):
     output_tensor = (close_ts - tsf.rolling_sum_(
         torch.min(low_ts, tsf.shift(close_ts, 1)), 6)) / tsf.rolling_sum_(
             torch.max(high_ts, tsf.shift(close_ts, 1)) -
             torch.min(low_ts, tsf.shift(close_ts, 1)), 6) * 12 * 24 + (
                 close_ts - tsf.rolling_sum_(
                     torch.min(low_ts, tsf.shift(close_ts, 1)), 12)
             ) / tsf.rolling_sum_(
                 torch.max(high_ts, tsf.shift(close_ts, 1)) -
                 torch.min(low_ts, tsf.shift(close_ts, 1)),
                 12) * 6 * 24 + (close_ts - tsf.rolling_sum_(
                     torch.min(low_ts, tsf.shift(close_ts, 1)),
                     24)) / tsf.rolling_sum_(
                         torch.max(high_ts, tsf.shift(close_ts, 1)) -
                         torch.min(low_ts, tsf.shift(close_ts, 1)),
                         24) * 6 * 24 * 100 / (6 * 12 + 6 * 24 + 12 * 24)
     return output_tensor
Пример #21
0
 def forward(self, high_ts, low_ts, close_ts, volume_ts):
     output_tensor = tsf.rolling_sum_(((close_ts - low_ts) - (high_ts - close_ts)) / (high_ts - low_ts) * volume_ts,
                                      self.window)
     return output_tensor
Пример #22
0
 def forward(self, close_ts):
     cond = tsf.diff(close_ts, 1) > 0
     zeros = torch.zeros(close_ts.size())
     output_tensor = tsf.rolling_sum_(torch.where(cond, close_ts - tsf.shift(close_ts, 1), zeros), self.window)
     return output_tensor
Пример #23
0
 def forward(self, high_ts, close_ts):
     zeros = torch.zeros(high_ts.size())
     cond = tsf.diff(close_ts, 1) < 0
     output_tensor = tsf.rolling_sum_(torch.where(cond, torch.abs(tsf.diff(close_ts, 1)), zeros), self.window)
     return output_tensor
Пример #24
0
 def forward(self, close_ts, volume_ts):
     sign = torch.sign(tsf.diff(close_ts, 1))
     output_tensor = tsf.rolling_sum_(sign * volume_ts, self.window)
     return output_tensor
Пример #25
0
 def forward(self, open_ts, returns_ts):
     output_tensor = -1 * (tsf.rank(
         ((tsf.rolling_sum_(open_ts, 5) * tsf.rolling_sum_(returns_ts, 5)) -
          tsf.shift((tsf.rolling_sum_(open_ts, 5) *
                     tsf.rolling_sum_(returns_ts, 5)), 10))))
     return output_tensor
Пример #26
0
 def forward(self, low_ts, volume_ts, returns_ts):
     return ((-1 * tsf.diff(tsf.rolling_min(low_ts, 5), 5)) * tsf.rank(
         ((tsf.rolling_sum_(returns_ts, 60) - tsf.rolling_sum_(
             returns_ts, 20)) / 55))) * tsf.ts_rank(volume_ts, 5)
Пример #27
0
 def forward(self, high_ts, low_ts, open_ts):
     output_tensor = tsf.rolling_sum_(high_ts - open_ts,
                                      20) / tsf.rolling_sum_(
                                          open_ts - low_ts, 20) * 100
     return output_tensor
Пример #28
0
 def forward(self, close_ts, returns_ts):
     alpha = ((-1 * torch.sign(
         (close_ts - tsf.shift(close_ts, 7)) + tsf.diff(close_ts, 7))) *
              (1 + tsf.rank(1 + tsf.rolling_sum_(returns_ts, 210))))
     return alpha
Пример #29
0
 def forward(self, high_ts, volume_ts):
     df = tsf.rolling_cov(tsf.rank(high_ts), tsf.rank(volume_ts), 3)
     alpha = -1 * tsf.rolling_sum_(tsf.rank(df), 3)
     return alpha
Пример #30
0
def obv(close_ts, volume_ts):
    zero = torch.zeros_like(volume_ts, dtype=volume_ts.dtype, device=volume_ts.device)
    volume_new = torch.where(close_ts == tsf.shift(close_ts, window=1), zero, torch.where(close_ts > tsf.shift(close_ts, window=1), volume_ts, -volume_ts))
    volume_new[0] = volume_ts[0]
    OBV = tsf.rolling_sum_(volume_new, window=2)
    return OBV