: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead inon line

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

View the code on Gist.

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. 1-day VaR) with a probability of . There are three approaches to calculating VaR, historical simulation VaR, delta-normal 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 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 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.

View the code on Gist.

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, 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 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,

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.

View the code on Gist.

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,

View the code on Gist.

Measures of Risk-adjusted Return

When we "discount" expected return generated from our valuation model, 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, , 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 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,

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, ,

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,

View the code on Gist.

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,

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,

View the code on Gist.

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,

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 square-root second-order 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 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,

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,

View the code on Gist.

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,

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,

View the code on Gist.

Python Code for Everything

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