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.
Input: weights: numpy.ndarray
/pd.Series
of weightsmeans: numpy.ndarray
/pd.Series
of mean/average valuescov_matrix: numpy.ndarray
/pandas.DataFrame
, covariance matrixrisk_free_rate: float
(default=0.005
), risk free ratefreq: int
(default=252
), number of trading days, default value corresponds to trading days in a yearOutput: (Expected Return, Volatility, Sharpe Ratio): tuple of those three quantities
-
finquant.quants.
sharpe_ratio
(exp_return, volatility, risk_free_rate=0.005)¶ Computes the Sharpe Ratio
Input: exp_return: int
/float
, Expected Return of a portfoliovolatility: int
/float
, Volatility of a portfoliorisk_free_rate: int
/float
(default=0.005
), risk free rateOutput: sharpe ratio: float
(exp_return - risk_free_rate)/float(volatility)
-
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.
Input: means: numpy.ndarray
/pd.Series
of mean/average valuesweights: numpy.ndarray
/pd.Series
of weightsOutput: weighted mu: numpy.ndarray
:(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.
Input: cov_matrix: numpy.ndarray
/pandas.DataFrame
, covariance matrixweights: numpy.ndarray
/pd.Series
of weightsOutput: weighted sigma: numpy.ndarray
:np.sqrt(np.dot(weights.T, np.dot(cov_matrix, weights)))