コード例 #1
0
 def forward(self, high_ts, low_ts, close_ts, volume_ts):
     output_tensor = tsf.rolling_corr(
         tsf.rank((
             (close_ts - tsf.rolling_min(low_ts, 12)) /
             (tsf.rolling_max(high_ts, 12) - tsf.rolling_min(low_ts, 12)))),
         tsf.rank(volume_ts), 6)
     return output_tensor
コード例 #2
0
def kdj(high_ts, low_ts, close_ts, fastk_period=9, slowk_period=3, slowd_period=3):
    range_ts = tsf.rolling_max(high_ts, window=fastk_period) - tsf.rolling_min(low_ts, window=fastk_period)
    RSV = (close_ts - tsf.rolling_min(low_ts, fastk_period).squeeze(-1)) / torch.clamp(range_ts.squeeze(-1),min=1)
    K = tsf.ema(RSV, window=slowk_period).squeeze(-1) 
    D = tsf.ema(K, slowd_period).squeeze(-1)
    J = 3*K - 2*D
    return RSV, K, D, J
コード例 #3
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
コード例 #4
0
 def forward(self, high_ts, low_ts, close_ts, volume_ts):
     divisor = (tsf.rolling_max(high_ts, 12) -
                tsf.rolling_min(low_ts, 12)).replace(0, 0.0001)
     inner = (close_ts - tsf.ts_min(low_ts, 12)) / (divisor)
     ts = tsf.rolling_corr(tsf.rank(inner), tsf.rank(volume_ts), 6)
     output_tensor = -1 * ts
     return output_tensor
コード例 #5
0
 def forward(self, close_ts):
     cond = (tsf.diff(tsf.rolling_mean_(close_ts, 100), 100) /
             tsf.shift(close_ts, 100) <= 0.05).squeeze()
     alpha = -1 * tsf.diff(close_ts, 3).squeeze()
     result = torch.where(
         cond, -1 * (close_ts - tsf.rolling_min(close_ts, 100)).squeeze(),
         alpha)
     return result
コード例 #6
0
 def forward(self, volume_ts, vwap_ts):
     output_tensor = ((tsf.rank(
         (vwap_ts - tsf.rolling_min(vwap_ts, 12)))**tsf.ts_rank(
             tsf.rolling_corr(
                 tsf.ts_rank(vwap_ts, 20),
                 tsf.ts_rank(tsf.rolling_mean_(volume_ts, 60), 2), 18), 3))
                      * -1)
     return output_tensor
コード例 #7
0
 def forward(self, tensor_x, tensor_y):
     if tensor_x.dim() < tensor_y.dim():
         tensor_x = tensor_x.expand_as(tensor_y)
     residual = calc_residual3d(tensor_x,
                                tensor_y,
                                window=self._window_train,
                                keep_first_nan=True)
     residual = residual.squeeze(-1).transpose(0, 1)
     return tsf.rolling_min(residual, self._window)
コード例 #8
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
コード例 #9
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)
コード例 #10
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)
コード例 #11
0
def wr(high_ts, low_ts, close_ts, timeperiod=14):
    HT = tsf.rolling_max(high_ts, window=timeperiod)
    LT = tsf.rolling_min(low_ts, window=timeperiod)
    WR = (HT - close_ts) / (HT - LT) * 100
    return WR
コード例 #12
0
def natr(high_ts, low_ts, close_ts, timeperiod=14):
    true_range = torch.max(high_ts, tsf.shift(close_ts, window=1)) - torch.min(low_ts, tsf.shift(close_ts, window=1))
    TRange_max = tsf.rolling_max(true_range, window=timeperiod)
    TRange_min = tsf.rolling_min(true_range, window=timeperiod)
    natr = tsf.rolling_mean_((true_range - TRange_min) / (TRange_max - TRange_min), window=timeperiod)
    return natr
コード例 #13
0
 def forward(self, tensor: torch.tensor) -> torch.tensor:
     return tsf.rolling_min(data_ts=tensor, window=self._window)