robertmartin8 / PyPortfolioOpt

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

Cannot get the market prior #469

Closed hahahahah321 closed 1 year ago

hahahahah321 commented 1 year ago

Started to use PyPortfolioOpt for several weeks. Everything has been great since I started to try bl model. I tried the codes to come up with market prior:

from pypfopt import black_litterman, risk_models from pypfopt import BlackLittermanModel, plotting S = risk_models.CovarianceShrinkage(raw2).ledoit_wolf() delta = black_litterman.market_implied_risk_aversion(market_prices) delta

And I got my delta:

沪深300 1.286431 dtype: float64

And I also inputted mcaps:

mcaps={'陕西煤业':191300000000, '保利发展': 190600000000, '淮北矿业': 33800000000, '山煤国际': 30200000000, '潞安环能': 40800000000, '金地集团': 56700000000, '万科A': 214400000000, '新城控股': 50500000000, '平煤股份': 28400000000, '山西焦煤': 51300000000, '贵州茅台': 2475100000000, '招商银行': 998400000000, '腾讯控股': 3287000000000, '海康威视': 310500000000, '泸州老窖': 345100000000, '五粮液': 735400000000, '香港交易所': 461500000000, '洋河股份': 264000000000, '美团-W': 1120000000000}

but when I tried to get market_prior: market_prior = black_litterman.market_implied_prior_returns(mcaps, delta, S) market_prior 万科A NaN 五粮液 NaN 保利发展 NaN 山煤国际 NaN 山西焦煤 NaN 平煤股份 NaN 招商银行 NaN 新城控股 NaN 沪深300 NaN 泸州老窖 NaN 洋河股份 NaN 海康威视 NaN 淮北矿业 NaN 潞安环能 NaN 美团-W NaN 腾讯控股 NaN 贵州茅台 NaN 金地集团 NaN 陕西煤业 NaN 香港交易所 NaN

It gets NaN for every stock and my market_prices (沪深300 NaN)got into the market_pror. Is it because my input file type of market_prices? What is the correct file type for it? Thanks

robertmartin8 commented 1 year ago

As per the docs, it should be a pd.Series or {str: float} dict.

This error is probably due to missing data in your mcaps or covariance matrix S

robertmartin8 commented 1 year ago

Closing because stale