(self, weights, y)
return -mdd
Compute maximum drawdown.

        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 maximum drawdown.
Compute maximum drawdown.
Compute maximum drawdown .
def __call__(self, weights, y):
        """Compute maximum drawdown.

        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 maximum drawdown.

        """
        cumrets = 1 + portfolio_cumulative_returns(weights,
                                                   y[:, self.returns_channel, ...],
                                                   input_type=self.input_type,
                                                   output_type='simple')

        cummax = torch.cummax(cumrets, 1)[0]  # (n_samples, n_timesteps)

        div = (cumrets / cummax) - 1  # (n_samples, n_timesteps)

        end = div.argmin(dim=1)  # (n_samples,)
        mdd = div.gather(1, end.view(-1, 1)).view(-1)

        return -mdd
def __call__ ( self , weights , y ) : cumrets = 1 + portfolio_cumulative_returns ( weights , y [ : , self . returns_channel , ... ] , input_type = self . input_type , output_type = 'simple' ) cummax = torch . cummax ( cumrets , 1 ) [ 0 ] # (n_samples, n_timesteps) div = ( cumrets / cummax ) - 1 # (n_samples, n_timesteps) end = div . argmin ( dim = 1 ) # (n_samples,) mdd = div . gather ( 1 , end . view ( - 1 , 1 ) ) . view ( - 1 ) return - mdd