jankrepl / deepdow

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

AssertionError: when using BachelierNet #73

Closed gmgreg closed 3 years ago

gmgreg commented 3 years ago

I'm able to get the out-of-the box examples to execute successfully (getting_started and iid) when using the generated data but when using differenty toy datasets I get an AssertionError in the cvxcpy module.

/opt/conda/lib/python3.6/site-packages/cvxpy/cvxcore/python/canonInterface.py in nonzero_csc_matrix(A)
    162     # this function returns (rows, cols) corresponding to nonzero entries in
    163     # A; an entry that is explicitly set to zero is treated as nonzero
--> 164     assert not np.isnan(A.data).any()
    165 
    166     # scipy drops rows, cols with explicit zeros; use nan as a sentinel

AssertionError:

Steps to reproduce:

  1. Start with getting_started.ipynb
  2. Replace the data generation logic with loading data as described in this issue (I've used this as well as larger data sets)
  3. Replace the Network Definition with:
from deepdow.nn import BachelierNet

n_channels = X.shape[1]
lookback = X.shape[2]
n_assets = X.shape[3]
max_weight = 0.5
hidden_size = 32

network = BachelierNet(n_channels, n_assets, hidden_size=hidden_size, max_weight=max_weight)

print(network)

Same error occurs even if reducing channels to 1, increasing number of samples, keeping lookback, gap, horizion small (5,0,1).

jankrepl commented 3 years ago

I would imagine this error comes out when trying to train the network / do the forward pass, right?

Anyway, it is hard to debug without the actual sample that it failed on. However, looking at the traceback, make sure that there is no NaNs in your data. If that is not helpful, just try to find a single X (of shape (n_samples, n_channels, lookback, n_assets)) such that network(X) gives you the above error and post it here!

gmgreg commented 3 years ago

Not sure what the issue is/was. I was able to avoid the issue by re-writing my code. I also eliminated raw_to_Xy in my data loading. At this point I've been able to increase my dataset size and run through BachelierNet. It appears to be functional but I'm not fully understanding some of the nuances of DeepDow yet. More questions to come.

Thank you again for your patience.

jankrepl commented 3 years ago

Perfect!