Efficient Frontier¶
FinQuant allows to optimise a given portfolio by minimising a cost/objective function. The module finquant.efficient_frontier
contains a class EfficientFrontier
that provides public functions to compute and visualise optimised portfolios.

class
finquant.efficient_frontier.
EfficientFrontier
(mean_returns, cov_matrix, risk_free_rate=0.005, freq=252, method='SLSQP')¶ An object designed to perform optimisations based on minimising a cost/objective function. It can find parameters for portfolios with
 minimum volatility
 maximum Sharpe ratio
 minimum volatility for a given target return
 maximum Sharpe ratio for a given target volatility
It also provides functions to compute the Efficient Frontier between a range of Returns, plot the Efficient Frontier, plot the optimal portfolios (minimum Volatility and maximum Sharpe Ratio).

__init__
(mean_returns, cov_matrix, risk_free_rate=0.005, freq=252, method='SLSQP')¶ Input: mean_returns: pandas.Series
, individual expected returns for all stocks in the portfoliocov_matrix: pandas.DataFrame
, covariance matrix of returnsrisk_free_rate: int
/float
(default=0.005
), risk free ratefreq: int
(default=252
), number of trading days, default value corresponds to trading days in a yearmethod: string
(default="SLSQP"
), type of solver method to use, must be one of: ‘NelderMead’
 ‘Powell’
 ‘CG’
 ‘BFGS’
 ‘NewtonCG’
 ‘LBFGSB’
 ‘TNC’
 ‘COBYLA’
 ‘SLSQP’
 ‘trustconstr’
 ‘dogleg’
 ‘trustncg’
 ‘trustexact’
 ‘trustkrylov’
all of which are officially supported by scipy.optimize.minimize

efficient_frontier
(targets=None)¶ Gets portfolios for a range of given target returns. If no targets were provided, the algorithm will find the minimum and maximum returns of the portfolio’s individual stocks, and set the target range according to those values. Results in the Efficient Frontier.
Input: targets: list
/numpy.ndarray
(default=None
) offloats
, range of target returns.Output: efrontier: numpy.ndarray
of (volatility, return) values

efficient_return
(target, save_weights=True)¶ Finds the portfolio with the minimum volatility for a given target return.
Input: target: float
, the target return of the optimised portfolio.save_weights: boolean
(default=True
), for internal use only. Whether to save the optimised weights in the instance variableweights
(anddf_weights
). Useful for the case of computing the efficient frontier after doing an optimisation, else the optimal weights would be overwritten by the efficient frontier computations. Best to ignore this argument.Output: df_weights:  if “save_weights” is True: a
pandas.DataFrame
of weights/allocation of stocks within the optimised portfolio.
weights:  if “save_weights” is False: a
numpy.ndarray
of weights/allocation of stocks within the optimised portfolio.
 if “save_weights” is True: a

efficient_volatility
(target)¶ Finds the portfolio with the maximum Sharpe ratio for a given target volatility.
Input: target: float
, the target volatility of the optimised portfolio.Output: df_weights: a pandas.DataFrame
of weights/allocation of stocks within the optimised portfolio.

maximum_sharpe_ratio
(save_weights=True)¶ Finds the portfolio with the maximum Sharpe Ratio, also called the tangency portfolio.
Input: save_weights: boolean
(default=True
), for internal use only. Whether to save the optimised weights in the instance variableweights
(anddf_weights
). Useful for the case of computing the efficient frontier after doing an optimisation, else the optimal weights would be overwritten by the efficient frontier computations. Best to ignore this argument.Output: df_weights:  if “save_weights” is True: a
pandas.DataFrame
of weights/allocation of stocks within the optimised portfolio.
weights:  if “save_weights” is False: a
numpy.ndarray
of weights/allocation of stocks within the optimised portfolio.
 if “save_weights” is True: a

minimum_volatility
(save_weights=True)¶ Finds the portfolio with the minimum volatility.
Input: save_weights: boolean
(default=True
), for internal use only. Whether to save the optimised weights in the instance variableweights
(anddf_weights
). Useful for the case of computing the efficient frontier after doing an optimisation, else the optimal weights would be overwritten by the efficient frontier computations. Best to ignore this argument.Output: df_weights:  if “save_weights” is True: a
pandas.DataFrame
of weights/allocation of stocks within the optimised portfolio.
weights:  if “save_weights” is False: a
numpy.ndarray
of weights/allocation of stocks within the optimised portfolio.
 if “save_weights” is True: a

plot_efrontier
()¶ Plots the Efficient Frontier.

plot_optimal_portfolios
()¶ Plots markers of the optimised portfolios for
 minimum Volatility, and
 maximum Sharpe Ratio.

properties
(verbose=False)¶ Calculates and prints out Expected annualised Return, Volatility and Sharpe Ratio of optimised portfolio.
Input: verbose: boolean
(default=False
), whether to print out properties or not