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')
Parameters:
  • mean_returns (Series) – A Series of individual expected returns for all stocks

  • cov_matrix (DataFrame) – Covariance matrix of returns

  • risk_free_rate (FLOAT) – Risk free rate, default: 0.005

  • freq (INT) – Number of trading days in a year, default: 252

  • method (str) –

    Type of solver method to use (default: SLSQP), must be one of:

    • ’Nelder-Mead’

    • ’Powell’

    • ’CG’

    • ’BFGS’

    • ’Newton-CG’

    • ’L-BFGS-B’

    • ’TNC’

    • ’COBYLA’

    • ’SLSQP’

    • ’trust-constr’

    • ’dogleg’

    • ’trust-ncg’

    • ’trust-exact’

    • ’trust-krylov’

    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.

Parameters:

targets (Union[ndarray[Union[floating, float], Any], List[Union[floating, float]], None]) – A list/array: range of target returns, default: None

Return type:

ndarray[float64, Any]

Returns:

Array of (volatility, return) values

efficient_return(target, save_weights=True)

Finds the portfolio with the minimum volatility for a given target return.

Parameters:
  • target (Union[integer, int, floating, float]) – The target return of the optimised portfolio.

  • save_weights (bool) – For internal use only, default: True Whether to save the optimised weights in the instance variable weights (and df_weights). Useful for the case of computing the efficient frontier after doing an optimisation, else the optimal weights are overwritten by the efficient frontier computations. Best to ignore this argument.

Return type:

ARRAY_OR_DATAFRAME

Returns:

  • if save_weights is True:

    a DataFrame of weights/allocation of stocks within the optimised portfolio.

  • if save_weights is False:

    a numpy.ndarray of weights/allocation of stocks within the optimised portfolio.

efficient_volatility(target)

Finds the portfolio with the maximum Sharpe ratio for a given target volatility.

Parameters:

target (Union[integer, int, floating, float]) – The target return of the optimised portfolio.

Return type:

DataFrame

Returns:

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.

Parameters:

save_weights (bool) – For internal use only, default: True Whether to save the optimised weights in the instance variable weights (and df_weights). Useful for the case of computing the efficient frontier after doing an optimisation, else the optimal weights are overwritten by the efficient frontier computations. Best to ignore this argument.

Return type:

ARRAY_OR_DATAFRAME

Returns:

  • if save_weights is True:

    a DataFrame of weights/allocation of stocks within the optimised portfolio.

  • if save_weights is False:

    a numpy.ndarray of weights/allocation of stocks within the optimised portfolio.

minimum_volatility(save_weights=True)

Finds the portfolio with the minimum volatility.

Parameters:

save_weights (bool) – For internal use only, default: True Whether to save the optimised weights in the instance variable weights (and df_weights). Useful for the case of computing the efficient frontier after doing an optimisation, else the optimal weights are overwritten by the efficient frontier computations. Best to ignore this argument.

Return type:

ARRAY_OR_DATAFRAME

Returns:

  • if save_weights is True:

    a DataFrame of weights/allocation of stocks within the optimised portfolio.

  • if save_weights is False:

    a numpy.ndarray of weights/allocation of stocks within the optimised portfolio.

plot_efrontier()

Plots the Efficient Frontier.

Return type:

None

plot_optimal_portfolios()

Plots markers of the optimised portfolios for :rtype: None

  • minimum Volatility, and

  • maximum Sharpe Ratio.

properties(verbose=False)

Calculates and prints out Expected annualised Return, Volatility and Sharpe Ratio of optimised portfolio.

Parameters:

verbose (bool) – Whether to print out properties or not, default: False

Return type:

Tuple[Union[integer, int, floating, float], Union[floating, float], Union[floating, float]]