def forward(self, close_ts): cond1 = (tsf.rolling_mean_(close_ts, self.window) + tsf.rolling_std(close_ts, self.window)) < close_ts cond2 = close_ts < (tsf.rolling_mean_(close_ts, self.window) - tsf.rolling_std(close_ts, self.window)) ones = torch.ones(close_ts.size()) zeros = torch.zeros(close_ts.size()) output_tensor = torch.where((cond1 & cond2), ones, zeros) return output_tensor
def forward(self, close_ts, volume_ts): cond_1 = ( tsf.rolling_mean_(close_ts, 8) + tsf.rolling_std(close_ts, 8) < tsf.rolling_mean_(close_ts, 2)).squeeze() cond_2 = (tsf.rolling_mean_(volume_ts, 20) / volume_ts < 1).squeeze() cond_3 = ( tsf.rolling_mean_(close_ts, 8) - tsf.rolling_std(close_ts, 8) < tsf.rolling_mean_(close_ts, 2)).squeeze() ones = torch.ones(close_ts.size()).squeeze() result = torch.where((cond_1 | (cond_2 & cond_3)), -1 * ones, ones) return result
def forward(self, close_ts, volume_ts): cond1 = (tsf.rolling_mean_(close_ts, 8) + tsf.rolling_std(close_ts, 8)) < tsf.rolling_mean_( close_ts, 2) cond2 = tsf.rolling_mean_(close_ts, 2) < ( tsf.rolling_mean_(close_ts, 8) - tsf.rolling_std(close_ts, 8)) cond3 = (volume_ts / tsf.rolling_mean_(volume_ts, 20)) >= 1 ones = torch.ones(close_ts.size()) output_tensor = torch.where((cond1 | ~(cond1 & cond2 & cond3)), -1 * ones, ones) return output_tensor
def forward(self, tensor): """defalt input is close""" returns = tsf.pct_change(tensor, period=1) sharp_ratio = tsf.rolling_mean_(returns, window=self._window) / tsf.rolling_std( returns, window=self._window) return tsf.shift(sharp_ratio, window=self._lag_window).squeeze(-1)
def forward(self, close_ts, volume_ts): output_tensor = tsf.rolling_std( torch.abs((close_ts / tsf.shift(close_ts, 1) - 1)) / volume_ts, 20) / tsf.rolling_mean_( torch.abs( (close_ts / tsf.shift(close_ts, 1) - 1)) / volume_ts, 20) return output_tensor
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_std(residual, self._window)
def forward(self, high_ts, volume_ts): alpha = -1 * tsf.rank(tsf.rolling_std(high_ts, 10)) * tsf.rolling_corr( high_ts, volume_ts, 10) return alpha #
def forward(self, close_ts, returns_ts): inner = tsf.rolling_std(returns_ts, 2) / tsf.rolling_std(returns_ts, 5) return tsf.rank(2 - tsf.rank(inner) - tsf.rank(tsf.diff(close_ts, 1))) # .values
def forward(self, high_ts, close_ts, volume_ts): ts = tsf.rolling_cov(high_ts, volume_ts, 5) alpha = -1 * tsf.diff(ts, 5) * tsf.rank(tsf.rolling_std(close_ts, 20)) return alpha
def forward(self, open_ts, close_ts): ts = tsf.rolling_cov(close_ts, open_ts, 10) alpha = -1 * (tsf.rank((tsf.rolling_std(abs((close_ts - open_ts)), 5) + (close_ts - open_ts)) + ts)) return alpha
def cci(high_ts, low_ts, close_ts, timeperiod=14): TP = (high_ts + low_ts + close_ts) / 3 cci = (TP - tsf.rolling_mean_(TP, window=timeperiod)) / (0.015 * tsf.rolling_std(TP, window=timeperiod)) return cci
def forward(self, tensor): """input tensor is returns""" return tsf.rolling_std(tensor, window=self._window).squeeze(-1)
def forward(self, high_ts, volume_ts, close_ts): output_tensor = ( -1 * (tsf.diff(tsf.rolling_corr(high_ts, volume_ts, 5), 5) * tsf.rank(tsf.rolling_std(close_ts, 20)))) return output_tensor
def forward(self, amount_ts): output_tensor = tsf.rolling_std(amount_ts, 20) return output_tensor
def forward(self, volume_ts): output_tensor = tsf.rolling_std(volume_ts, self.window) return output_tensor
def forward(self, tensor): return tsf.rolling_mean(tensor, window=self._window) / tsf.rolling_std( tensor, window=self._window)
def forward(self, high_ts, volume_ts): output_tensor = ((-1 * tsf.rank(tsf.rolling_std(high_ts, 10))) * tsf.rolling_corr(high_ts, volume_ts, 10)) return output_tensor