stefan-jansen / machine-learning-for-trading

Code for Machine Learning for Algorithmic Trading, 2nd edition.
https://ml4trading.io
12.87k stars 4.11k forks source link

RuntimeError: Cannot set name on a level of a MultiIndex. . Use 'MultiIndex.set_names' instead. #248

Closed lumiereUmbra closed 1 year ago

lumiereUmbra commented 2 years ago

Describe the bug I am getting the above runtime error while executing alphalens_signals_quality.ipynb in line from Alphalens library function factor_data = get_clean_factor_and_forward_returns(factor=factor, prices=trade_prices,quantiles=5, periods=(1, 5, 10, 21)) . Appears to be a compatibility issue with pandas library .

To Reproduce

Steps to reproduce the behavior:

  1. Go to ' https://github.com/PacktPublishing/Machine-Learning-for-Algorithmic-Trading-Second-Edition/blob/master/11_decision_trees_random_forests/06_alphalens_signals_quality.ipynb'
  2. Execute the above file
  3. Scroll down to statement -
    factor_data = get_clean_factor_and_forward_returns(factor=factor, prices=trade_prices,quantiles=5, periods=(1, 5, 10, 21)) .
  4. See error [ attached screenshot ]

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Environment

I am using - OS: Windows 10 alphalens-0.3.6 pandas 1.3.5 python 3.7

error_alphalens_utils_get_clean_factor_and_forward_returns

Additional context Add any other context about the problem here.

stefan-jansen commented 1 year ago

Due to incompatiblitly with more recent pandas version; either downgrade or modify the library accordingly.