Lean  $LEAN_TAG$
SortinoRatio.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
17 {
18  /// <summary>
19  /// Calculation of the Sortino Ratio, a modification of the <see cref="SharpeRatio"/>.
20  ///
21  /// Reference: https://www.cmegroup.com/education/files/rr-sortino-a-sharper-ratio.pdf
22  /// Formula: S(x) = (R - T) / TDD
23  /// Where:
24  /// S(x) - Sortino ratio of x
25  /// R - the average period return
26  /// T - the target or required rate of return for the investment strategy under consideration. In
27  /// Sortino’s early work, T was originally known as the minimum acceptable return, or MAR. In his
28  /// more recent work, MAR is now referred to as the Desired Target Return.
29  /// TDD - the target downside deviation. <see cref="TargetDownsideDeviation"/>
30  /// </summary>
31  public class SortinoRatio : SharpeRatio
32  {
33  /// <summary>
34  /// Creates a new Sortino Ratio indicator using the specified periods
35  /// </summary>
36  /// <param name="name">The name of this indicator</param>
37  /// <param name="period">Period of historical observation for Sortino ratio calculation</param>
38  /// <param name="minimumAcceptableReturn">Minimum acceptable return for Sortino ratio calculation</param>
39  public SortinoRatio(string name, int period, double minimumAcceptableReturn = 0)
40  : base(name, period, minimumAcceptableReturn.SafeDecimalCast())
41  {
42  var denominator = new TargetDownsideDeviation(period, minimumAcceptableReturn).Of(RateOfChange);
43  Ratio = Numerator.Over(denominator);
44  }
45 
46  /// <summary>
47  /// Creates a new SortinoRatio indicator using the specified periods
48  /// </summary>
49  /// <param name="period">Period of historical observation for Sortino ratio calculation</param>
50  /// <param name="minimumAcceptableReturn">Minimum acceptable return for Sortino ratio calculation</param>
51  public SortinoRatio(int period, double minimumAcceptableReturn = 0)
52  : this($"SORTINO({period},{minimumAcceptableReturn})", period, minimumAcceptableReturn)
53  {
54  }
55  }
56 }