jankrepl / deepdow

Portfolio optimization with deep learning.
https://deepdow.readthedocs.io
Apache License 2.0
875 stars 136 forks source link

FlexibleDataLoader doctest failing for py37 and py38 #79

Closed jankrepl closed 3 years ago

jankrepl commented 3 years ago
from deepdow.data import FlexibleDataLoader                                

torch.manual_seed(3)               
batch_size = 4          

dataloader = FlexibleDataLoader(dataset,                                   
                                batch_size=batch_size,                                                                                                     
                                n_assets_range=(2, 3),  # keep n_assets = 2 but shuffle randomly                                                           
                                lookback_range=(2, 6),  # sampled uniformly from [2, 6)                                                                    
                                horizon_range=(2, 5))   # sampled uniformly from [2, 5)                                                                    

for X_batch, y_batch, timestamps_batch, asset_names_batch in dataloader:
    print(X_batch.shape)
    print(y_batch.shape) 
    print(asset_names_batch)       
    print(list(map(str, timestamps_batch)))                                
    print()

Expected

    torch.Size([4, 2, 5, 2])
    torch.Size([4, 2, 2, 2])
    ['AAPL', 'MSFT']
    ['2016-01-20 00:00:00', '2016-01-15 00:00:00', '2016-01-13 00:00:00', '2016-01-22 00:00:00']
    torch.Size([4, 2, 4, 2])
    torch.Size([4, 2, 2, 2])
    ['MSFT', 'AAPL']
    ['2016-01-12 00:00:00', '2016-01-18 00:00:00', '2016-01-11 00:00:00', '2016-01-21 00:00:00']
    torch.Size([2, 2, 4, 2])
    torch.Size([2, 2, 3, 2])
    ['AAPL', 'MSFT']
    ['2016-01-19 00:00:00', '2016-01-14 00:00:00']

With p36

    torch.Size([4, 2, 4, 2])
    torch.Size([4, 2, 3, 2])
    ['MSFT', 'AAPL']
    ['2016-01-20 00:00:00', '2016-01-15 00:00:00', '2016-01-13 00:00:00', '2016-01-22 00:00:00']
    torch.Size([4, 2, 2, 2])
    torch.Size([4, 2, 2, 2])
    ['AAPL', 'MSFT']
    ['2016-01-12 00:00:00', '2016-01-18 00:00:00', '2016-01-11 00:00:00', '2016-01-21 00:00:00']
    torch.Size([2, 2, 2, 2])
    torch.Size([2, 2, 4, 2])
    ['AAPL', 'MSFT']
    ['2016-01-19 00:00:00', '2016-01-14 00:00:00']

With p37

    torch.Size([4, 2, 4, 2])
    torch.Size([4, 2, 3, 2])
    ['MSFT', 'AAPL']
    ['2016-01-20 00:00:00', '2016-01-15 00:00:00', '2016-01-13 00:00:00', '2016-01-22 00:00:00']
    torch.Size([4, 2, 2, 2])
    torch.Size([4, 2, 2, 2])
    ['AAPL', 'MSFT']
    ['2016-01-12 00:00:00', '2016-01-18 00:00:00', '2016-01-11 00:00:00', '2016-01-21 00:00:00']
    torch.Size([2, 2, 2, 2])
    torch.Size([2, 2, 4, 2])
    ['AAPL', 'MSFT']
    ['2016-01-19 00:00:00', '2016-01-14 00:00:00']

It is most likely caused by newer versions in one of the dependencies, since the source code did not change.