(returns, lookback=10, horizon=10, gap=0)
return X[:, np.newaxis, :, :], timestamps, y[:, np.newaxis, :, :]
Create a deep learning dataset (in memory).

    Parameters
    ----------
    returns : pd.DataFrame
        Returns where columns represent assets and rows timestamps. The last row
        is the most recent.

    lookback : int
        Number of timesteps to include in the features.

    horizon : int
        Number of timesteps to inclued in the label.

    gap : int
        Integer representing the number of time periods one cannot act after observing the features.

    Returns
    -------
    X : np.ndarray
        Array of shape `(N, 1, lookback, n_assets)`. Generated out of the entire dataset.

    timestamps : pd.DateTimeIndex
        Index corresponding to the feature matrix `X`.

    y : np.ndarray
        Array of shape `(N, 1, horizon, n_assets)`. Generated out of the entire dataset.
Create a deep learning dataset (in memory).
Create a deep learning dataset ( in memory ) .
def returns_to_Xy(returns, lookback=10, horizon=10, gap=0):
    """Create a deep learning dataset (in memory).

    Parameters
    ----------
    returns : pd.DataFrame
        Returns where columns represent assets and rows timestamps. The last row
        is the most recent.

    lookback : int
        Number of timesteps to include in the features.

    horizon : int
        Number of timesteps to inclued in the label.

    gap : int
        Integer representing the number of time periods one cannot act after observing the features.

    Returns
    -------
    X : np.ndarray
        Array of shape `(N, 1, lookback, n_assets)`. Generated out of the entire dataset.

    timestamps : pd.DateTimeIndex
        Index corresponding to the feature matrix `X`.

    y : np.ndarray
        Array of shape `(N, 1, horizon, n_assets)`. Generated out of the entire dataset.

    """
    n_timesteps = len(returns.index)

    if lookback >= n_timesteps - horizon - gap + 1:
        raise ValueError('Not enough timesteps to extract X and y.')

    X_list = []
    timestamps_list = []
    y_list = []

    for i in range(lookback, n_timesteps - horizon - gap + 1):
        X_list.append(returns.iloc[i - lookback: i, :].values)
        timestamps_list.append(returns.index[i - 1])
        y_list.append(returns.iloc[i + gap: i + gap + horizon, :].values)

    X = np.array(X_list)
    timestamps = pd.DatetimeIndex(timestamps_list, freq=returns.index.freq)
    y = np.array(y_list)

    return X[:, np.newaxis, :, :], timestamps, y[:, np.newaxis, :, :]
def returns_to_Xy ( returns , lookback = 10 , horizon = 10 , gap = 0 ) : n_timesteps = len ( returns . index ) if lookback >= n_timesteps - horizon - gap + 1 : raise ValueError ( 'Not enough timesteps to extract X and y.' ) X_list = [ ] timestamps_list = [ ] y_list = [ ] for i in range ( lookback , n_timesteps - horizon - gap + 1 ) : X_list . append ( returns . iloc [ i - lookback : i , : ] . values ) timestamps_list . append ( returns . index [ i - 1 ] ) y_list . append ( returns . iloc [ i + gap : i + gap + horizon , : ] . values ) X = np . array ( X_list ) timestamps = pd . DatetimeIndex ( timestamps_list , freq = returns . index . freq ) y = np . array ( y_list ) return X [ : , np . newaxis , : , : ] , timestamps , y [ : , np . newaxis , : , : ]