robertmartin8 / PyPortfolioOpt

Financial portfolio optimisation in python, including classical efficient frontier, Black-Litterman, Hierarchical Risk Parity
https://pyportfolioopt.readthedocs.io/
MIT License
4.38k stars 940 forks source link

Black Litterman not working #392

Closed Ann-eat-apple closed 2 years ago

Ann-eat-apple commented 2 years ago

What are you trying to do? Clear description of the problem you are trying to solve with PyPortfolioOpt

from pypfopt import black_litterman from pypfopt.black_litterman import BlackLittermanModel from pypfopt.efficient_frontier import EfficientFrontier

# viewdict = {"AAPL": 0.20, "BBY": -0.30, "BAC": 0, "SBUX": -0.2, "T": 0.15}
S =  risk_models.risk_matrix(market_prices)
bl = BlackLittermanModel(S). #### HERE IS THE ERROR 

# rets = bl.bl_returns()
# ef = EfficientFrontier(rets, cov_matrix)

# OR use return-implied weights
delta = black_litterman.market_implied_risk_aversion(market_prices)
bl.bl_weights(delta)
weights = bl.clean_weights()

It gave me this error: *** TypeError: Q must be an array or dataframe on line 3

What have you tried?

What data are you using? What asset class, how many assets, how many data points. Preferably provide a sample of the dataset as a csv attachment.

Ann-eat-apple commented 2 years ago

can you please give us an example usage of BlackLittermanModel?

robertmartin8 commented 2 years ago

Hi @Ann-eat-apple,

There is a walkthrough in the docs. Could you let me know if that doesn't work for you?

Cheers, Robert

Ann-eat-apple commented 2 years ago
# viewdict = {"AAPL": 0.20, "BBY": -0.30, "BAC": 0, "SBUX": -0.2, "T": 0.15}
S =  risk_models.risk_matrix(market_prices)
bl = BlackLittermanModel(S)  #### HERE IS THE ERROR 

Error is:

*** TypeError: Q must be an array or dataframe

Ann-eat-apple commented 2 years ago

@robertmartin8

robertmartin8 commented 2 years ago

Have you had a chance to look at the docs? You aren’t passing any views to BlackLittermanModel. Please check this section: https://pyportfolioopt.readthedocs.io/en/latest/BlackLitterman.html#views

robertmartin8 commented 2 years ago

Closing for now as I believe this is addressed in the docs and example notebooks Feel free to reopen if not