Measures of Riskadjusted Return
This article is a supplement to some of the topics presented in Dr. Tucker Balch's online MOOC, Computational Investing. Financial markets are complex adaptive systems which are almost always indistinguishable from random processes. That said markets do exhibit quantifiable factors such as the value, meanreversion, firmsize, and momentum factors, which are believed to drive the returns in the market. Fundamentally this is because they drive supply and demand for securities. Computational finance is about building computational models which can be used to predict, with some error margin, what the markets are likely to do given a number of inputs.
Most machine learning models are optimization models. A simple optimization problem will consist of input variables (model parameters), and output quantities, and constraints on either the inputs, outputs, or both. Essentially the problem becomes, how can we adjust the model parameters in such a way that the output quantity is optimized. For most financial models the quantity being optimized is a measure of riskadjusted return.
Riskadjusted returns measure how many units of excess return are expected to be generated from however many units of risk. Excess return is the return of the investment above either a benchmark, riskfree rate of return, or some minimum required rate of return. Risk has many faces and most measures of riskadjusted return will differ only in their definition and treatment of risk popular measures include beta, volatility, shortfall risk, drawdown risk, and lower partial moments. That said, generally speaking risk in any investment is the probability of loss.
Note that the rest of this article refers specifically to portfolio risks and returns.
Portfolio Optimization
Portfolio optimization is the problem of allocating capital between the constituent assets of the portfolio. For example, given a simple twostock $100 portfolio which is invested in Apple and Google, how many dollars should be allocated to Apple and how many should be allocated to Google. In the 1950's Harry Markowitz proposed meanvariance optimization as the solution to this problem. Meanvariance optimization seeks to maximize the expected return for any given level of risk (risk tolerance) or minimize the risk for any given level of expected return. Another approach is to maximize the riskadjusted expected return of the portfolio.
The inputs into the portfolio optimization problem are the expected returns for each asset, the risk of each asset, and correlations between the assets. Correlation measures the linear relationship between variables and relates to diversification. The set of nondominated optimal portfolios (portfolios which optimize risk and return) is called the efficient frontier. For more information about the portfolio optimization problem click here and for information about the problems associated with financial modelling (such as the use of historical correlations) click here.
Expected Return
A portfolio can have multiple sources of return including interest received on fixed income, dividends received on shares or preference shares, and capital gains from the disposal of securities (fixed income and equities). Capital gains are affected by the market returns, changes in interest rates, and possibly foreign exchange rate fluctuations. All of these factors need to be incorporated into one or more financial models which can be used to estimate what the expected return on a portfolio i.e. the weighted sum of the expected returns of the portfolio's constituent assets. For this an investor could use traditional equity and fixed income valuation models (discounted cash flow models), statistical valuation models, or even computational models such as neural networks.
Definitions of Risk
Different definitions of risk have been proposed over the years including volatility of historical returns, expected shortfalls, lower partial moments, and drawdown risk. Volatility assumes that the riskiness of a security is how much much it moves around i.e. it's volatility. The most common volatility based measure of risk is the standard deviation of historical returns. Expected shortfall argues that the risk of a portfolio is the dollar value which could reasonably be expected to be lost over a specified period of time given a prespecified confidence interval. The most popular measure of expected shortfall risk is Value at Risk (VaR). Lower partial moments argue that risk is only captured in the downside of the historical volatility of the portfolio. An example of a lower partial moment would be the standard deviation of negative returns. Lastly, drawdown risk is the maximum historical 'drawdown' of the portfolio. A drawdown is the percentage loss between peak and trough.
Volatility
For a given period of time standard deviation, , measures the historical variance (average of the squared deviations) of the returns from the mean return, , over that period of time. The formula for this is,
where
Beta measures the relationship between the security returns, and the market, . High beta stocks are considered to be more risk whereas low beta stocks are considered to be less risky. The formula for this is,
where is the covariance of and and is the variance of the .
Expected Shortfall
Value at Risk (VaR) is the most popular measure of expected shortfall. Expected shortfall works as follows: given a specific time period, , and confidence interval, , expected shortfall tells us what the maximum probable loss scenario is over that period of time (usually one day a.k.a. 1day VaR) with a probability of . There are three approaches to calculating VaR, historical simulation VaR, deltanormal VaR, and Monte Carlo VaR.
Historical simulation VaR takes historical period returns, orders then, and takes the loss at the point in the list which corresponds to . For example, if , , and we have the following 10 returns: , then the item in the list which corresponds to is 4.5%. This can be interpreted as us either being 90% sure that 4.5% is our expected 1day shortfall for the portfolio or, alternatively, that 90% of the time a 1day loss experienced by the portfolio won't exceed 4.5%.
Deltanormal VaR assumes that the returns generated by the assets in the portfolio follow a prespecified distribution. Unfortunately a popular assumption is that returns are normally distributed despite the fact that in reality portfolio returns exhibit fatter tails meaning that the probability of outliers (significant gains and losses) is higher. Given these assumptions it is possible to calculate what the returns and standard deviation of the portfolio should be as a whole. From this the worst case scenario for the portfolio can be estimated.
Monte Carlo VaR works by simulating the portfolio using stochastic processes. This can be done in two ways. Either a stochastic process is calibrated to each asset in the portfolio, return paths for each asset are simulated, and then these paths are combined given some correlation matrix using the Cholesky Decomposition; or a stochastic process is calibrated to the historical returns of the portfolio and return paths for the portfolio are simulated. Depending on your application one method may be considerably more or less computational expensive. Once returns have been simulated for the portfolio the "historical simulation" VaR method is applied to the returns.
There are many problems with Value at Risk. One problem with VaR is that it violates the subadditive rule of risk which requires that the risk of a portfolio cannot exceed the risk of it's constituent assets i.e. diversification cannot be negative. For this reason variants of VaR such as Conditional VaR and Extreme VaR have been proposed.
Lower Partial Moments
Whereas measures of riskadjusted return based on volatility treat all deviations from the mean as risk, measures of riskadjusted return based on lower partial moments consider only deviations below some predefined minimum return threshold, as risk. For example, negative deviations from the mean is risky whereas positive deviations are not. A lower partial moment of order can be estimated from a sample of returns as follows,
where is historical returns.
A useful classification of measures of riskadjusted returns based on lower partial moments in by their order. The larger the order the greater the weighting will be on returns that fall below the target threshold, meaning that larger orders result in more riskaverse measures. In addition to lower partial moment which can be a measure of downside risk in a portfolio, higher partial moments can be measures of the upside potential of a portfolio,
In some ways, Value at Risk (VaR) is similar to a lower partial moment, except that VaR is of order 2 only and is a more probabilistic view of loss as the risk of a portfolio. Personally I prefer lower partial moments as risk.
Drawdowns
The final measure of risk is the drawdown. A drawdown is the maximum decrease in the value of the portfolio over a specific period of time. Given the historical prices (values) for a portfolio, , and a period of time, , the drawdown of length over that period of time is the maximum distance between a previous two values and ,
The maximum drawdown can be thought of as a list of drawdowns calculated from the same historical portfolio values, , but for different time periods. The maximum drawdown of a portfolio is the maximum decrease in portfolio value from a previous high to a new low. This is illustrated below,
Measures of Riskadjusted Return
When we "discount" expected return generated from our valuation model, by different quantities of risk we get measures of riskadjusted return. Some measures of risk adjusted return are discussed below. If you find any mistakes in either the formula's or the code please let me know in the comment section below, thanks!
Measures of Riskadjusted Return based on Volatility
The Treynor ratio was one of the first measures of riskadjusted return. It was originally published in 1965 in the Harvard Business Review as a metric for rating the performance of investment funds. Given a riskfree rate of return, , the Treynor ratio calculates the excess returns generated by a portfolio, , and discounts it by the portfolio's beta, ,
The Sharpe ratio, originally called the rewardtovariability ratio, was introduced in 1966 by William Sharpe as an extension of the Treynor ratio. The Sharpe ratio discounts the expected excess returns of a portfolio by the volatility of the returns,
The information ratio is an extension of the Sharpe ratio which replaces the riskfree rate of return with the scalar expected return of a benchmark portfolio, ,
Last, but not least, the Modigliani ratio a.k.a the M2 ratio, is a combination the Sharpe and information ratio in that it adjusts the expected excess returns of the portfolio above the risk free rate by the expected excess returns of a benchmark portfolio, , or the market , above the risk free rate,
Measure of Riskadjusted Return based on Value at Risk
The excess return on Value at Risk discounts the excess return of the portfolio above the riskfree rate by the Value at Risk of the portfolio,
And the "conditional Sharpe ratio" discounts the excess return of the portfolio above the riskfree rate by the Conditional Value at Risk of the portfolio,
Measures of Riskadjusted Return based on Partial Moments
The Omega ratio discounts the excess returns of a portfolio above the target threshold, usually the riskfree rate, by the firstorder lower partial moment of the returns. The firstorder lower partial moment corresponds to the average expected loss also known as downside risk,
The Sortino ratio was proposed as a modification to the Sharpe ratio by Sortino and van der Meer in 1991. The Sortino ratio discounts the excess return of a portfolio above a target threshold by the volatility of downside returns, , instead of the volatility of all returns, . The volatility of downside returns is equivalent to the squareroot secondorder lower partial moment of returns,
The Kappa ratio is a generalization of Omega and Sortino ratios first proposed in 2004 by Kaplan and Knowles. It was shown that when the parameter of the Kappa ratio is set to one or two you get the Omega or Sortino ratio. The Kappa ratio is most often used with which is why it is often referred to as the Kappa 3 ratio,
The gainloss ratio was first presented by Bernardo Ledoit in 2000. It discounts the firstorder higher partial moment of a portfolio's returns, upside potential, by the firstorder lower partial moment of a portfolio's returns, downside risk,
The upsidepotential ratio was first presented by Sortino van der Meer and Plantinga in 1999. It discounts the firstorder higher partial moment of a portfolio's returns, upside potential, by the square root of the secondorder lower partial moment of a portfolio's returns, downside variation,
Measures of Riskadjusted Return based on Drawdown Risk
The Calmar ratio discounts the expected excess return of a portfolio by the worst expected maximum draw down for that portfolio,
The Sterling ratio discounts the expected excess return of a portfolio by the average of the worst expected maximum drawdowns for that portfolio,
The Burke ratio is similar to the Sterling ratio except that it is less sensitive to outliers. It discounts the expected excess return of a portfolio by the square root of the average of the worst expected maximum drawdowns squared for that portfolio,
Python Code for Everything
The Gist below contains all the code presented in this article plus two example usage methods.

Nice to see a work inspired by Tucker´s intro into Computational Investing.
Hope you will enjoy the further lectures and fabulous course discussions as the course takesoff on the full throttle & afterburners, Stuart. Glad to see Sortino Ratio (as it tries not to deform performance comparison from the investor´s point of view) right together with Sharpe Ratio and guess why Calmar Ratio (which goes a bit farther in this,even at a cost of a need to have more inputs to get) fell out of your focus. Hope you can get and attach more data into the greater picture
FYI: some SharpeR v/s returns maps for selected Funds, Indices and FXTraders ( both for a microCosmos and a macroCosmos scales ) are
posted in Computational Investment I, Spring 2013 Piazza: Kindly ref.: >>> https://piazza.com/class/hbi3elzedu247p?cid=996 
Very informative and concise description of necessary parameters for risk return analysis. Could you please point me to the Gist mentioned with the Python code? I would be very interested to understand your implementation. Thanks!

Nice

Hi Stuart,
First of all thanks for your articles, very interesting! 🙂
I believe there is an error in the prices() function, resulting in a wrong drawdown result. The vector 'values' used in the drawdown function shoud be the cumulative product of the returns :
def prices(returns, base):
return hstack((base, base*cumproduct(1+returns)))Cheers,
Olivier 
Thank you for the nice article and source code.
There is an error in line 171:def kappa_three_ratio(er, returns, rf, target=0):
return (er  rf) / math.pow(lpm(returns, target, 3), float(1/3))The expression float(1/3) will always return zero. You might try float(1)/3, or simply 1./3 instead.

Beta = Cov(a, mkt) / VAR(mkt)
It says STD...
Regards,
Shane 
Hello!
Thanks for the article.My question is about Sortino ratio: should't we construct and fit probability distribution of downside risk and apply integral calculus to measure it, instead of using lpm()?
As stated in https://en.wikipedia.org/wiki/Sortino_ratio :
"As a caveat, some practitioners have fallen into the habit of using discrete periodic returns to compute downside risk. This method is conceptually and operationally incorrect and negates the foundational statistic of postmodern portfolio theory as developed by Brian M. Rom and Frank A. Sortino." 
Thanks for the valuable information and the source code.

Dear Stuart,
I used the python code you were mentioned on this Website:
http://www.turingfinance.com/computationalinvestingwithpythonweekone/
Instead of using your code like:
r=nrand.uniform(1, 1, 50)
m= nrand.uniform(1, 1, 50)
I replaced „r“ with returns which some return figures which are coming from my MySQL database as:query_risk_figures = SQLStatement
cur.execute(query_risk_figures)
results = cur.fetchall()
num_rows = int(cur.rowcount)
x = map(list, list(results))
x = sum(x, [])
D = np.fromiter(iter=x, dtype=float, count=1)
D = D.reshape(num_rows, 1)
D_len= len(D)
D = np.reshape(D, D_len)
D = np.round(D, 8, out=None)r = D
m = nrand.uniform(1, 1, D_len)
e = numpy.mean(r)
f = 0.06As I would NOT get any errors after compiling the code (in Spyder for Python 3.6).
It seems like something has been calculating if I let compile the code but the figures never change and stay all the time the same. Moreover I receive even some negative figures. I think the figrues aren’t right. Do you have any idea what I am doing wrong?I receive this figures after compiling the code:
_______________________________________________________________________________________
IRR 0.01
NPV 1.7
Cumulative PnL 1.0
Logarithmic PnL 0.0
Variance 0.12
Mean 0.02
Positive Trades 1465.
Negatives Trades 859.
All Trades 2324.
Positive Trades % 63.04
Negative Trades % 36.96
Skewness 67.35
Kurtosis 3.27
Volatility 0.35
Beta 0.01
HPM 0.14
LPM 0.12
VaR(0.05) 0.4
CVaR(0.05) 0.64
Drawdown(5) 10.46
Max Drawdown 18.22
Treynor Ratio 4.3
Sharpe Ratio 0.12
Information Ratio 0.04
Excess VaR 0.11
Conditional Sharpe Ratio 0.07
Omega Ratio 0.36
Sortino Ratio 0.2
Kappa 3 Ratio 0.14
Gain Loss Ratio 1.14
Upside Potential Ratio 0.64
Calmar Ratio 0.0
Sterling Ratio 0.19
Burke Ratio 0.16
______________________________________________________________________________________If I use your code for this example:
r=nrand.uniform(1, 1, 50)
m= nrand.uniform(1, 1, 50)I do NOT get any errors after compiling the code, also. But very curious figures, too:
_________________________________________________________________________________________
IRR nan
NPV 3.91
Cumulative PnL 1.0
Logarithmic PnL 0.0
Variance 0.32
Mean 0.1
Positive Trades 1465.
Negatives Trades 859.
All Trades 2324.
Positive Trades % 63.04
Negative Trades % 36.96
Skewness 40.31
Kurtosis 0.9
Volatility 0.56
Beta 0.02
HPM 0.29
LPM 0.19
VaR(0.05) 0.92
CVaR(0.05) 0.97
Drawdown(5) 0.92
Max Drawdown 0.99
Treynor Ratio 1.88
Sharpe Ratio 0.07
Information Ratio 0.02
Excess VaR 0.04
Conditional Sharpe Ratio 0.04
Omega Ratio 0.2
Sortino Ratio 0.11
Kappa 3 Ratio 0.08
Gain Loss Ratio 1.51
Upside Potential Ratio 0.8
Calmar Ratio 0.04
Sterling Ratio 0.2
Burke Ratio 0.15
__________________________________________________________________________________________Many thanks,
Best regards,
Robert P.
Comments