(self, weights, y)
return -alpha
Compute negative alpha with respect to the benchmark portfolio.

        Parameters
        ----------
        weights : torch.Tensor
            Tensor of shape `(n_samples, n_assets)` representing the predicted weights by our portfolio optimizer.

        y : torch.Tensor
            Tensor of shape `(n_samples, n_channels, horizon, n_assets)` representing the evolution over the next
            `horizon` timesteps.

        Returns
        -------
        torch.Tensor
            Tensor of shape `(n_samples,)` representing the per sample negative alpha.
Compute negative alpha with respect to the benchmark portfolio.
Compute negative alpha with respect to the benchmark portfolio .
def __call__(self, weights, y):
        """Compute negative alpha with respect to the benchmark portfolio.

        Parameters
        ----------
        weights : torch.Tensor
            Tensor of shape `(n_samples, n_assets)` representing the predicted weights by our portfolio optimizer.

        y : torch.Tensor
            Tensor of shape `(n_samples, n_channels, horizon, n_assets)` representing the evolution over the next
            `horizon` timesteps.

        Returns
        -------
        torch.Tensor
            Tensor of shape `(n_samples,)` representing the per sample negative alpha.

        """
        n_samples, n_assets = weights.shape
        device, dtype = weights.device, weights.dtype
        portfolio_rets = portfolio_returns(weights,
                                           y[:, self.returns_channel, ...],
                                           input_type=self.input_type,
                                           output_type='simple')  # (n_samples, horizon)

        if self.benchmark_weights is None:
            benchmark_weights = torch.ones(n_samples, n_assets, dtype=dtype, device=device) / n_assets
        else:
            benchmark_weights = self.benchmark_weights[None, :].repeat(n_samples, 1).to(device=device, dtype=dtype)

        benchmark_rets = portfolio_returns(benchmark_weights,
                                           y[:, self.returns_channel, ...],
                                           input_type=self.input_type,
                                           output_type='simple')  # (n_samples, horizon)

        cov = covariance(benchmark_rets, portfolio_rets)
        beta = cov / benchmark_rets.var(dim=1)
        alpha = portfolio_rets.mean(dim=1) - beta * benchmark_rets.mean(dim=1)

        return -alpha
def __call__ ( self , weights , y ) : n_samples , n_assets = weights . shape device , dtype = weights . device , weights . dtype portfolio_rets = portfolio_returns ( weights , y [ : , self . returns_channel , ... ] , input_type = self . input_type , output_type = 'simple' ) # (n_samples, horizon) if self . benchmark_weights is None : benchmark_weights = torch . ones ( n_samples , n_assets , dtype = dtype , device = device ) / n_assets else : benchmark_weights = self . benchmark_weights [ None , : ] . repeat ( n_samples , 1 ) . to ( device = device , dtype = dtype ) benchmark_rets = portfolio_returns ( benchmark_weights , y [ : , self . returns_channel , ... ] , input_type = self . input_type , output_type = 'simple' ) # (n_samples, horizon) cov = covariance ( benchmark_rets , portfolio_rets ) beta = cov / benchmark_rets . var ( dim = 1 ) alpha = portfolio_rets . mean ( dim = 1 ) - beta * benchmark_rets . mean ( dim = 1 ) return - alpha