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

EfficientFrontier Plotting doesn't work when an EfficientFrontier object is inputted #359

Closed shyen1998 closed 3 years ago

shyen1998 commented 3 years ago

Describe the bug pypfopt.plotting.plot_efficient_frontier() doesn't work when the input is a EfficientFrontier object. (It worked when CLA is used)

Expected behavior pypfopt.plotting.plot_efficient_frontier() should produce an efficient frontier just like CLA.

Code sample import yfinance as yf import matplotlib.pyplot as plt import pandas as pd import numpy as np

tickers = ["GOOG", "AMZN", "AAPL", "FB", "NFLX"] ohlc = yf.download(tickers, period="max") prices = ohlc["Adj Close"].dropna(how="all")

from pypfopt import expected_returns from pypfopt import risk_models from pypfopt import plotting from pypfopt import EfficientFrontier

mu = expected_returns.capm_return(prices) S = risk_models.CovarianceShrinkage(prices).ledoit_wolf()

ef_mv = EfficientFrontier(mu, S) ef_mv.efficient_return(0.15) ax = plotting.plot_efficient_frontier(ef_mv, showfig=False)

Operating system, python version, PyPortfolioOpt version e.g Windows 10 Home, python 3.8.8, PyPortfolioOpt 1.4.2