(self, x)
return optlayer(covmat_sqrt_estimates)[0]
Predict weights.

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

        Returns
        -------
        weights : torch.Tensor
            Tensor of shape `(n_samples, n_assets)` representing the predicted weights.
Predict weights.
Predict weights .
def __call__(self, x):
        """Predict weights.

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

        Returns
        -------
        weights : torch.Tensor
            Tensor of shape `(n_samples, n_assets)` representing the predicted weights.

        """
        n_samples, _, lookback, n_assets = x.shape

        # Problem setup
        if self.optlayer is not None:
            if self.n_assets != n_assets:
                raise ValueError('Incorrect number of assets: {}, expected: {}'.format(n_assets, self.n_assets))

            optlayer = self.optlayer
        else:
            optlayer = self._construct_problem(n_assets, self.max_weight)

        # problem solver
        covmat_sqrt_estimates = CovarianceMatrix(sqrt=True)(x[:, self.returns_channel, :, :])

        return optlayer(covmat_sqrt_estimates)[0]
def __call__ ( self , x ) : n_samples , _ , lookback , n_assets = x . shape # Problem setup if self . optlayer is not None : if self . n_assets != n_assets : raise ValueError ( 'Incorrect number of assets: {}, expected: {}' . format ( n_assets , self . n_assets ) ) optlayer = self . optlayer else : optlayer = self . _construct_problem ( n_assets , self . max_weight ) # problem solver covmat_sqrt_estimates = CovarianceMatrix ( sqrt = True ) ( x [ : , self . returns_channel , : , : ] ) return optlayer ( covmat_sqrt_estimates ) [ 0 ]