(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).

        """
        n = len(x)

        covariance = torch.mm(self.matrix, torch.t(self.matrix)) if self.force_symmetric else self.matrix

        exp_returns_all = torch.repeat_interleave(self.exp_returns[None, ...], repeats=n, dim=0)
        covariance_all = torch.repeat_interleave(covariance[None, ...], repeats=n, dim=0)
        gamma_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 = self.portfolio_opt_layer(exp_returns_all, covariance_all, gamma_all, alpha_all)

        return weights
def forward ( self , x ) : n = len ( x ) covariance = torch . mm ( self . matrix , torch . t ( self . matrix ) ) if self . force_symmetric else self . matrix exp_returns_all = torch . repeat_interleave ( self . exp_returns [ None , ... ] , repeats = n , dim = 0 ) covariance_all = torch . repeat_interleave ( covariance [ None , ... ] , repeats = n , dim = 0 ) gamma_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 = self . portfolio_opt_layer ( exp_returns_all , covariance_all , gamma_all , alpha_all ) return weights