(benchmarks, dataloader, device=None, dtype=None, returns_channel=0,
                     input_type='log', output_type='log')
return cumrets_dict
Generate cumulative returns over the horizon for all benchmarks.

    Parameters
    ----------
    benchmarks : dict
        Dictionary where keys are benchmark names and values are instances of `Benchmark` (possible
        also `torch.nn.Network`).

    dataloader : deepdow.data.RigidDataLoader
        Dataloader that we will fully iterate over.

    device : torch.device or None
        Device to be used. If not specified defaults to `torch.device('cpu')`.

    dtype : torch.dtype or None
        Dtype to be used. If not specified defaults to `torch.float`.

    returns_channel : int
        What channel in `y` represents the returns.

    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.

    Returns
    -------
    cumrets_dict : dict
       Keys are benchmark names and values are ``pd.DataFrame`` with index equal to timestamps,
       columns horizon timesteps and values cumulative returns.
Generate cumulative returns over the horizon for all benchmarks.
Generate cumulative returns over the horizon for all benchmarks .
def generate_cumrets(benchmarks, dataloader, device=None, dtype=None, returns_channel=0,
                     input_type='log', output_type='log'):
    """Generate cumulative returns over the horizon for all benchmarks.

    Parameters
    ----------
    benchmarks : dict
        Dictionary where keys are benchmark names and values are instances of `Benchmark` (possible
        also `torch.nn.Network`).

    dataloader : deepdow.data.RigidDataLoader
        Dataloader that we will fully iterate over.

    device : torch.device or None
        Device to be used. If not specified defaults to `torch.device('cpu')`.

    dtype : torch.dtype or None
        Dtype to be used. If not specified defaults to `torch.float`.

    returns_channel : int
        What channel in `y` represents the returns.

    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.

    Returns
    -------
    cumrets_dict : dict
       Keys are benchmark names and values are ``pd.DataFrame`` with index equal to timestamps,
       columns horizon timesteps and values cumulative returns.
    """
    # checks
    if not all(isinstance(bm, Benchmark) for bm in benchmarks.values()):
        raise TypeError('The values of benchmarks need to be of type Benchmark')

    if not isinstance(dataloader, RigidDataLoader):
        raise TypeError('The type of dataloader needs to be RigidDataLoader')

    device = device or torch.device('cpu')
    dtype = dtype or torch.float

    all_entries = {}
    for bm_name, bm in benchmarks.items():
        all_entries[bm_name] = []
        if isinstance(bm, torch.nn.Module):
            bm.eval()

    for batch_ix, (X_batch, y_batch, timestamps, _) in enumerate(dataloader):
        # Get batch
        X_batch, y_batch = X_batch.to(device).to(dtype), y_batch.to(device).to(dtype)
        for bm_name, bm in benchmarks.items():
            weights = bm(X_batch)
            cumrets = portfolio_cumulative_returns(weights,
                                                   y_batch[:, returns_channel, ...],
                                                   input_type=input_type,
                                                   output_type=output_type)

            all_entries[bm_name].append(pd.DataFrame(cumrets.detach().cpu().numpy(),
                                                     index=timestamps))

    cumrets_dict = {bm_name: pd.concat(entries).sort_index() for bm_name, entries in all_entries.items()}

    return cumrets_dict
def generate_cumrets ( benchmarks , dataloader , device = None , dtype = None , returns_channel = 0 , input_type = 'log' , output_type = 'log' ) : # checks if not all ( isinstance ( bm , Benchmark ) for bm in benchmarks . values ( ) ) : raise TypeError ( 'The values of benchmarks need to be of type Benchmark' ) if not isinstance ( dataloader , RigidDataLoader ) : raise TypeError ( 'The type of dataloader needs to be RigidDataLoader' ) device = device or torch . device ( 'cpu' ) dtype = dtype or torch . float all_entries = { } for bm_name , bm in benchmarks . items ( ) : all_entries [ bm_name ] = [ ] if isinstance ( bm , torch . nn . Module ) : bm . eval ( ) for batch_ix , ( X_batch , y_batch , timestamps , _ ) in enumerate ( dataloader ) : # Get batch X_batch , y_batch = X_batch . to ( device ) . to ( dtype ) , y_batch . to ( device ) . to ( dtype ) for bm_name , bm in benchmarks . items ( ) : weights = bm ( X_batch ) cumrets = portfolio_cumulative_returns ( weights , y_batch [ : , returns_channel , ... ] , input_type = input_type , output_type = output_type ) all_entries [ bm_name ] . append ( pd . DataFrame ( cumrets . detach ( ) . cpu ( ) . numpy ( ) , index = timestamps ) ) cumrets_dict = { bm_name : pd . concat ( entries ) . sort_index ( ) for bm_name , entries in all_entries . items ( ) } return cumrets_dict