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 weightsmeans (
ARRAY_OR_SERIES
) – An array of mean/average valuescov_matrix (
ARRAY_OR_DATAFRAME
) – Covariance matrixrisk_free_rate (
FLOAT
, default: 0.005) – Risk free ratefreq (
INT
, default: 252) – Number of trading days in a year
- Return type:
- 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 pricesweights (
ARRAY_OR_SERIES
) – Downside Risk of a portfoliorisk_free_rate (
FLOAT
, default: 0.005) – Risk free rate
- Return type:
- 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
- finquant.quants.sortino_ratio(exp_return, downs_risk, risk_free_rate=0.005)
Computes the Sortino Ratio.
- Parameters:
- Return type:
- 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.
- 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:
- Return type:
- 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:
means (
ARRAY_OR_SERIES
) – An array representing mean/average valuesweights (
ARRAY_OR_SERIES
) – An array representing weights
- Return type:
- 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:
cov_matrix (
ARRAY_OR_DATAFRAME
) – Covariance matrixweights (
ARRAY_OR_SERIES
) – An array representing weights
- Return type:
- Returns:
Weighted sigma (standard deviation) as a floating point number:
np.sqrt(np.dot(weights.T, np.dot(cov_matrix, weights)))