(weights, y, input_type='log', output_type='simple', rebalance=False)
Compute cumulative portfolio returns.

    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, horizon, n_assets)` representing the log return evolution over the next
        `horizon` timesteps.

    input_type : str, {'log', 'simple'}
        What type of returns are we dealing with in `y`.

    output_type : str, {'log', 'simple'}
        What type of returns are we dealing with in the output.

    rebalance : bool
        If True, each timestep the weights are adjusted to be equal to be equal to the original ones. Note that
        this assumes that we tinker with the portfolio. If False, the portfolio evolves untouched.

    Returns
    -------
    torch.Tensor
        Tensor of shape `(n_samples, horizon)`.
Compute cumulative portfolio returns.
Compute cumulative portfolio returns .
def portfolio_cumulative_returns(weights, y, input_type='log', output_type='simple', rebalance=False):
    """Compute cumulative portfolio returns.

    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, horizon, n_assets)` representing the log return evolution over the next
        `horizon` timesteps.

    input_type : str, {'log', 'simple'}
        What type of returns are we dealing with in `y`.

    output_type : str, {'log', 'simple'}
        What type of returns are we dealing with in the output.

    rebalance : bool
        If True, each timestep the weights are adjusted to be equal to be equal to the original ones. Note that
        this assumes that we tinker with the portfolio. If False, the portfolio evolves untouched.

    Returns
    -------
    torch.Tensor
        Tensor of shape `(n_samples, horizon)`.

    """
    prets = portfolio_returns(weights, y, input_type=input_type, output_type='log', rebalance=rebalance)
    log_prets = torch.cumsum(prets, dim=1)  # we can aggregate log returns over time by sum

    if output_type == 'log':
        return log_prets

    elif output_type == 'simple':
        return log2simple(log_prets)

    else:
        raise ValueError('Unsupported output type: {}'.format(output_type))
def portfolio_cumulative_returns ( weights , y , input_type = 'log' , output_type = 'simple' , rebalance = False ) : prets = portfolio_returns ( weights , y , input_type = input_type , output_type = 'log' , rebalance = rebalance ) log_prets = torch . cumsum ( prets , dim = 1 ) # we can aggregate log returns over time by sum if output_type == 'log' : return log_prets elif output_type == 'simple' : return log2simple ( log_prets ) else : raise ValueError ( 'Unsupported output type: {}' . format ( output_type ) )