Closed homerokzam closed 1 year ago
Hi @homerokzam. Thank you, glad you like the project. :)
Currently FinQuant has some methods defined in the class EfficientFrontier
that let you automatically plot using matplotlib. I guess you have seen that, that is why you are asking for plotly.
When you follow the example Example-Optimisation, you end up with an object for your portfolio. In the example it is called pf
.
Through that, you have access to the data you want to plot. pf.ef
holds all of the portfolio's efficient frontier properties.
To plot the values you asked for (in plotly), you first need to get the values out of the object. Here is an example on how to do that:
pf.ef_efficient_frontier()
weights
: pf.ef_minimum_volatility()
. With those weights
, you can then compute the portfolio that aims for the minimum volatility.The following code snippet should get you all the data you need to plot it in plotly:
from finquant.quants import annualised_portfolio_quantities
# efficient frontier data:
ef_data = pf.ef_efficient_frontier()
# minimum volatility:
min_vol_weights = pf.ef_minimum_volatility()
min_vol_vals = list(
annualised_portfolio_quantities(
min_vol_weights , pf.ef.mean_returns, pf.ef.cov_matrix, freq= pf.ef.freq
)
)[0:2]
min_vol_vals.reverse()
# maximum sharpe ratio:
max_sharpe_weights = pf.ef_maximum_sharpe_ratio()
max_sharpe_vals = list(
annualised_portfolio_quantities(
max_sharpe_weights, self.mean_returns, self.cov_matrix, freq=self.freq
)
)[0:2]
max_sharpe_vals.reverse()
In the above code snippet:
ef_data
is the data to plot the efficient frontiermin_vol_vals
is a list of x and y coordinates of your minimum volatilitymax_sharpe_vals
is a list of x and y coordinates of your maximum sharpe ratioI have not used plotly in a long time, but I guess you know how to use that data to plot it in plotly yourself.
That's just what I needed! Thank you very much.
Congratulations for the work. Excellent library!
How to use the efficient frontier data to plot in the plotly library the EF Min Volatility and EF Max Sharpe Ratio?
Thanks