(self, x)
return weights
Perform forward pass.

        Parameters
        ----------
        x : torch.Tensor
            Of shape (n_samples, n_channels, lookback, n_assets).

        Returns
        -------
        weights : torch.Torch
            Tensor of shape (n_samples, n_assets).
Perform forward pass.
Perform forward pass .
def forward(self, x):
        """Perform forward pass.

        Parameters
        ----------
        x : torch.Tensor
            Of shape (n_samples, n_channels, lookback, n_assets).

        Returns
        -------
        weights : torch.Torch
            Tensor of shape (n_samples, n_assets).

        """
        # Normalize
        x = self.norm_layer(x)

        # Covmat
        rets = x[:, 0, :, :]
        covmat = self.covariance_layer(rets)

        # expected returns
        x = self.transform_layer(x)
        x = self.dropout_layer(x)
        x = self.time_collapse_layer(x)
        exp_rets = self.channel_collapse_layer(x)

        # gamma
        gamma_sqrt_all = torch.ones(len(x)).to(device=x.device, dtype=x.dtype) * self.gamma_sqrt
        alpha_all = torch.ones(len(x)).to(device=x.device, dtype=x.dtype) * self.alpha

        # weights
        weights = self.portfolio_opt_layer(exp_rets, covmat, gamma_sqrt_all, alpha_all)

        return weights
def forward ( self , x ) : # Normalize x = self . norm_layer ( x ) # Covmat rets = x [ : , 0 , : , : ] covmat = self . covariance_layer ( rets ) # expected returns x = self . transform_layer ( x ) x = self . dropout_layer ( x ) x = self . time_collapse_layer ( x ) exp_rets = self . channel_collapse_layer ( x ) # gamma gamma_sqrt_all = torch . ones ( len ( x ) ) . to ( device = x . device , dtype = x . dtype ) * self . gamma_sqrt alpha_all = torch . ones ( len ( x ) ) . to ( device = x . device , dtype = x . dtype ) * self . alpha # weights weights = self . portfolio_opt_layer ( exp_rets , covmat , gamma_sqrt_all , alpha_all ) return weights