Expected Return, Volatility, Sharpe Ratio

The Expected Return, Volatility and Sharpe Ratio of a portfolio are computed with the module finquant.quants.

The module provides functions to compute quantities relevant to financial portfolios, e.g. a weighted average, which is the expected value/return, a weighted standard deviation (volatility), and the Sharpe ratio.

finquant.quants.annualised_portfolio_quantities(weights, means, cov_matrix, risk_free_rate=0.005, freq=252)

Computes and returns the expected annualised return, volatility and Sharpe Ratio of a portfolio.

Parameters:
  • weights (ARRAY_OR_SERIES) – An array of weights

  • means (ARRAY_OR_SERIES) – An array of mean/average values

  • cov_matrix (ARRAY_OR_DATAFRAME) – Covariance matrix

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

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

Return type:

Tuple[FLOAT, FLOAT, FLOAT]

Returns:

Tuple of Expected Return, Volatility, Sharpe Ratio

finquant.quants.downside_risk(data, weights, risk_free_rate=0.005)

Computes the downside risk (target downside deviation of returns).

Parameters:
  • data (DataFrame) – A dataframe of daily stock prices

  • weights (ARRAY_OR_SERIES) – Downside Risk of a portfolio

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

Return type:

FLOAT

Returns:

Target downside deviation np.sqrt(np.mean(np.minimum(0, wtd_daily_mean - risk_free_rate) ** 2))

finquant.quants.sharpe_ratio(exp_return, volatility, risk_free_rate=0.005)

Computes the Sharpe Ratio

Parameters:
  • exp_return (FLOAT) – Expected Return of a portfolio

  • volatility (FLOAT) – Volatility of a portfolio

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

Return type:

FLOAT

Returns:

Sharpe Ratio as a floating point number: (exp_return-risk_free_rate)/float(volatility)

finquant.quants.sortino_ratio(exp_return, downs_risk, risk_free_rate=0.005)

Computes the Sortino Ratio.

Parameters:
  • exp_return (FLOAT) – Expected Return of a portfolio

  • downs_risk (Union[floating, float]) – Downside Risk of a portfolio

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

Return type:

FLOAT

Returns:

Sortino Ratio as a floating point number: (exp_return - risk_free_rate) / float(downs_risk)

finquant.quants.treynor_ratio(exp_return, beta, risk_free_rate=0.005)

Computes the Treynor Ratio.

Parameters:
  • exp_return (FLOAT) – Expected Return of a portfolio

  • beta (FLOAT) – Beta parameter of a portfolio

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

Return type:

FLOAT

Returns:

Treynor Ratio as a floating point number: (exp_return - risk_free_rate) / beta

finquant.quants.value_at_risk(investment, mu, sigma, conf_level=0.95)

Computes and returns the expected value at risk of an investment/assets.

Parameters:
  • investment (NUMERIC) – Total value of the investment

  • mu (FLOAT) – Average/mean return of the investment

  • sigma (FLOAT) – Standard deviation of the investment

  • conf_level (FLOAT, default: 0.95) – Confidence level of the VaR

Return type:

FLOAT

Returns:

Value at Risk (VaR) of the investment: investment*(mu-sigma*norm.ppf(1-conf_level))

finquant.quants.weighted_mean(means, weights)

Computes the weighted mean/average, or in the case of a financial portfolio, it can be used for the Expected Return of said portfolio.

Parameters:
Return type:

FLOAT

Returns:

The weighted mean as a floating point number: np.sum(means*weights)

finquant.quants.weighted_std(cov_matrix, weights)

Computes the weighted standard deviation, or Volatility of a portfolio, which contains several stocks.

Parameters:
Return type:

FLOAT

Returns:

Weighted sigma (standard deviation) as a floating point number: np.sqrt(np.dot(weights.T, np.dot(cov_matrix, weights)))