jankrepl / deepdow

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

calling plot_weight_heatmap multiple times adds 1 to sum column of weight_table each time #93

Closed turmeric-blend closed 3 years ago

turmeric-blend commented 3 years ago

hi just a minor detail, I found out that calling plot_weight_heatmap N times would increase the sum column by N times. For example running in jupyter notebook:

weight_table = generate_weights_table(network, dataloader_test, device=device)

print(weight_table)

      asset_A    asset_B ... asset_Z
day_1   0.54       0.21   ...  0.002
day_2   0.45       0.32   ...  0.01

plot_weight_heatmap(weight_table, add_sum_column=True, time_format=None, time_skips=None)

print(weight_table)

      asset_A    asset_B ... asset_Z *sum*
day_1   0.54       0.21   ...  0.002  1.0
day_2   0.45       0.32   ...  0.010  1.0   

# calling plot_weight_heatmap() again

plot_weight_heatmap(weight_table, add_sum_column=True, time_format=None, time_skips=None)

# printing weight_table again

print(weight_table)

      asset_A    asset_B ... asset_Z *sum*
day_1   0.54       0.21   ...  0.002  2.0   <--- I think this behaviour was not intended
day_2   0.45       0.32   ...  0.010  2.0   
jankrepl commented 3 years ago

Very nice find! This is a bug! Really appreciate all this help and questions!:) A quick fix is to pass a copy of the weight_table into the function, i.e. weight_table.copy(). That is more or less what I am going to do in the background when fixing this bug.