           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, mean-reversion, firm-size, 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 risk-adjusted return.

Risk-adjusted 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, risk-free rate of return, or some minimum required rate of return. Risk has many faces and most measures of risk-adjusted return will differ only in their definition and treatment of risk popular measures include beta, volatility, shortfall risk, draw-down 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 two-stock \$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 mean-variance optimization as the solution to this problem. Mean-variance 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 risk-adjusted 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 non-dominated 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 pre-specified 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, $\sigma$, measures the historical variance (average of the squared deviations) of the returns from the mean return, $\mu$, over that period of time. The formula for this is,

$\sigma = \sqrt{\sigma^2} = \sqrt{\frac{1}{N} \sum^N_{i=1} (r_i - \mu)^2}$ where $\mu = \frac{1}{N} \sum^N_{i=1} r_i$

Beta measures the relationship between the security returns, $r_S$ and the market, $r_M$. High beta stocks are considered to be more risk whereas low beta stocks are considered to be less risky. The formula for this is,

$\beta = \frac{COV(r_S, r_M)}{VAR(r_M)}$ where $COV(r_S, r_M)$ is the covariance of $r_S$ and $r_M$ and $VAR(r_M)$ is the variance of the $R_M$.

##### Expected Shortfall

Value at Risk (VaR) is the most popular measure of expected shortfall. Expected shortfall works as follows: given a specific time period, $\tau$, and confidence interval, $\alpha$, expected shortfall tells us what the maximum probable loss scenario is over that period of time (usually one day a.k.a. 1-day VaR) with a probability of $1 - \alpha$. There are three approaches to calculating VaR, historical simulation VaR, delta-normal VaR, and Monte Carlo VaR.

Historical simulation VaR takes historical $\tau$ period returns, orders then, and takes the loss at the point in the list which corresponds to $\alpha$. For example, if $\tau = 1\ day$, $\alpha = 10\%$, and we have the following 10 returns: $\{ -7\%, -4.5\%, -2\%, -1.5\%, -1\%, 0\%, 2.5\%, 5\%, 7.5\%, 9\% \}$, then the item in the list which corresponds to $\alpha$ is -4.5%. This can be interpreted as us either being 90% sure that -4.5% is our expected 1-day shortfall for the portfolio or, alternatively, that 90% of the time a 1-day loss experienced by the portfolio won't exceed -4.5%.

Delta-normal VaR assumes that the returns generated by the assets in the portfolio follow a pre-specified 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 $1 - \alpha$ 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 sub-additive 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 risk-adjusted return based on volatility treat all deviations from the mean as risk, measures of risk-adjusted return based on lower partial moments consider only deviations below some predefined minimum return threshold, $\tau$ as risk. For example, negative deviations from the mean is risky whereas positive deviations are not. A lower partial moment of order $j$ can be estimated from a sample of $k$ returns as follows,

$LPM_j(\tau) = \frac{1}{k} \sum^k_{i=1} max(\tau - r_i, 0)^j$ where $r$ is historical returns.

A useful classification of measures of risk-adjusted 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 risk-averse 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,

$HPM_j(\tau) = \frac{1}{k} \sum^k_{i=1} max(r_i - \tau, 0)^j$

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, $S$, and a period of time, $t$, the drawdown of length $t$ over that period of time is the maximum distance between a previous two values $S_x$ and $S_{x - t}$,

$D(t) = \max \bigg\{0, \max_{t_i \in (0, t} \big\{ S_{t_i} - S_{t_i - t} \big\} \bigg\}$

The maximum drawdown can be thought of as a list of drawdowns calculated from the same historical portfolio values, $S$, 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, When we "discount" expected return generated from our valuation model, $E(r)$ by different quantities of risk we get measures of risk-adjusted 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 Risk-adjusted Return based on Volatility

The Treynor ratio was one of the first measures of risk-adjusted return. It was originally published in 1965 in the Harvard Business Review as a metric for rating the performance of investment funds. Given a risk-free rate of return, $r_f$, the Treynor ratio calculates the excess returns generated by a portfolio, $E(r_e) = E(r) - r_f$, and discounts it by the portfolio's beta, $\beta$,

$T = \frac{E(r_e)}{\beta} = \frac{E(r) - r_f}{\beta}$

The Sharpe ratio, originally called the reward-to-variability 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,

$S = \frac{E(r_e)}{\sigma_r} = \frac{E(r) - r_f}{\sigma_r}$

The information ratio is an extension of the Sharpe ratio which replaces the risk-free rate of return with the scalar expected return of a benchmark portfolio, $E(r_b)$,

$IR = \frac{E(r_e)}{E(\sigma_e)} = \frac{E(r) - E(r_b)}{\sqrt{var\big(E(r) - E(r_b)\big)}}$

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, $E(r_b)$, or the market $E(r_M)$, above the risk free rate,

$M^2 = E(r_e) \times \frac{E(\sigma_b)}{E(\sigma_e)} + r_f$

$M^2 = \big(E(r) - r_f\big) \times \frac{\sqrt{var\big(E(r_b) - R_f\big)}}{\sqrt{var\big(E(r) - r_f\big)}} + r_f$

##### Measure of Risk-adjusted Return based on Value at Risk

The excess return on Value at Risk discounts the excess return of the portfolio above the risk-free rate by the Value at Risk of the portfolio,

$EVaR = \frac{E(r_e)}{VaR_r} = \frac{E(r) - r_f}{VaR_r}$

And the "conditional Sharpe ratio" discounts the excess return of the portfolio above the risk-free rate by the Conditional Value at Risk of the portfolio,

$CSR = \frac{E(r_e)}{CVaR_r} = \frac{E(r) - r_f}{CVaR_r}$

##### Measures of Risk-adjusted Return based on Partial Moments

The Omega ratio discounts the excess returns of a portfolio above the target threshold, usually the risk-free rate, by the first-order lower partial moment of the returns. The first-order lower partial moment corresponds to the average expected loss also known as downside risk,

$\Omega(\tau) = \frac{E(r_e)}{LPM_{1(\tau)}} = \frac{E(r) - \tau}{LPM_1(\tau)}$

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, $\delta^2$, instead of the volatility of all returns, $\sigma^2$. The volatility of downside returns is equivalent to the square-root second-order lower partial moment of returns,

$SOR(\tau) = \frac{E(r_e)}{\delta^2} = \frac{E(r) - \tau}{\delta^2} = \frac{E(r) - \tau}{\sqrt{LPM_2(\tau)}}$

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 $j$ 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 $j=3$ which is why it is often referred to as the Kappa 3 ratio,

$K_j(\tau) = \frac{E(r_e)}{\sqrt[j]{LPM_j(\tau)}} = \frac{E(r) - \tau}{\sqrt[j]{LPM_j(\tau)}}$

The gain-loss ratio was first presented by Bernardo Ledoit in 2000. It discounts the first-order higher partial moment of a portfolio's returns, upside potential, by the first-order lower partial moment of a portfolio's returns, downside risk,

$GLR(\tau) = \frac{HPM_1(\tau)}{LPM_1(\tau)}$

The upside-potential ratio was first presented by Sortino van  der Meer and Plantinga in 1999. It discounts the first-order higher partial moment of a portfolio's returns, upside potential, by the square root of the second-order lower partial moment of a portfolio's returns, downside variation,

$UPR(\tau) = \frac{HPM_1(\tau)}{\sqrt{LPM_2(\tau)}}$

##### Measures of Risk-adjusted 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,

$CR = \frac{E(r_e)}{MD_1} = \frac{E(r) - r_f}{MD_1}$

The Sterling ratio discounts the expected excess return of a portfolio by the average of the $N$ worst expected maximum drawdowns for that portfolio,

$CR = \frac{E(r_e)}{\frac{1}{N} \sum^N_{i=1} MD_i} = \frac{E(r) - r_f}{\frac{1}{N} \sum^N_{i=1} MD_i}$

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 $N$ worst expected maximum drawdowns squared for that portfolio,

$BR = \frac{E(r_e)}{\sqrt{\frac{1}{N} \sum^N_{i=1} MD^2_i}} = \frac{E(r) - r_f}{\sqrt{\frac{1}{N} \sum^N_{i=1} MD^2_i}}$

# Python Code for Everything

The Gist below contains all the code presented in this article plus two example usage methods.

1. 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 takes-off 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 FX-Traders ( 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

2. 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!

• Hi Charu, all of the code is made available in the last Gist so I'm not sure where the confusion is 🙂 sorry.

3. Nice

4. 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

5. 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.

6. Beta = Cov(a, mkt) / VAR(mkt)

It says STD...

Regards,
Shane

7. 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 post-modern portfolio theory as developed by Brian M. Rom and Frank A. Sortino."

8. Thanks for the valuable information and the source code.

### Submit a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.