The Sortino Index is a risk-adjusted return metric that measures the performance of an investment relative to the downside deviation, which is the standard deviation of returns below a specified minimum acceptable return (MAR). It is similar to the Sharpe ratio, but focuses only on downside risk rather than total volatility.
Equation:
Sortino Ratio = (Rp - Rf) / σd
Where:
Downside Deviation:
σd = √[Σ(max(R - MAR, 0))^2 / n]
Where:
Interpretation:
function sortino_ratio(returns, minimum_acceptable_return = 0.0)
"""
Calculates the Sortino Ratio for a given series of returns.
Args:
returns: A vector of returns.
minimum_acceptable_return: The minimum acceptable return for the investment.
Defaults to 0.0.
Returns:
The Sortino Ratio.
"""
# Calculate the average return
avg_return = mean(returns)
# Calculate the downside deviation
downside_deviation = sqrt(mean((returns[returns .< minimum_acceptable_return] .- minimum_acceptable_return) .^ 2))
# Calculate the Sortino Ratio
sortino_ratio = (avg_return - minimum_acceptable_return) / downside_deviation
return sortino_ratio
end
Explanation:
sortino_ratio(returns, minimum_acceptable_return = 0.0)
:
Defines the function with two arguments:
returns
: A vector containing the series of
returns.minimum_acceptable_return
: The minimum acceptable
return for the investment. Defaults to 0.0.avg_return = mean(returns)
: Calculates the average
return of the given series of returns using the mean()
function.downside_deviation = sqrt(mean((returns[returns .< minimum_acceptable_return] .- minimum_acceptable_return) .^ 2))
:
returns[returns .< minimum_acceptable_return]
:
Filters the returns vector to include only those returns that are below
the minimum_acceptable_return
.(returns[returns .< minimum_acceptable_return] .- minimum_acceptable_return)
:
Calculates the difference between each of these filtered returns and the
minimum_acceptable_return
..^ 2
: Squares each of these differences.mean(...)
: Calculates the average of the squared
differences.sqrt(...)
: Takes the square root of the average to
obtain the downside deviation.sortino_ratio = (avg_return - minimum_acceptable_return) / downside_deviation
:
Calculates the Sortino Ratio by dividing the excess return (average
return minus minimum acceptable return) by the downside deviation.return sortino_ratio
: Returns the calculated Sortino
Ratio.How to Use:
minimum_acceptable_return
argument:# Example usage
returns = [0.02, -0.01, 0.03, -0.02, 0.01]
minimum_acceptable_return = 0.01
sortino_ratio_value = sortino_ratio(returns, minimum_acceptable_return)
println("Sortino Ratio: ", sortino_ratio_value)
This will calculate and print the Sortino Ratio for the given return series and minimum acceptable return.
This implementation provides a basic framework for calculating the Sortino Ratio in Julia. You can further enhance it by adding error handling, input validation, and other features as needed.