Lean  $LEAN_TAG$
SortinoRatioReportElement.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 
16 using System;
17 using System.Globalization;
18 using QuantConnect.Packets;
19 using System.Collections.Generic;
20 
22 {
23  internal sealed class SortinoRatioReportElement : SharpeRatioReportElement
24  {
25  /// <summary>
26  /// Sortino ratio from a backtest
27  /// </summary>
28  public override decimal? BacktestResultValue => BacktestResult?.TotalPerformance?.PortfolioStatistics?.SortinoRatio;
29 
30  /// <summary>
31  /// Estimate the Sortino ratio of the strategy.
32  /// </summary>
33  /// <param name="name">Name of the widget</param>
34  /// <param name="key">Location of injection</param>
35  /// <param name="backtest">Backtest result object</param>
36  /// <param name="live">Live result object</param>
37  /// <param name="tradingDaysPerYear">The number of trading days per year to get better result of statistics</param>
38  public SortinoRatioReportElement(string name, string key, BacktestResult backtest, LiveResult live, int tradingDaysPerYear)
39  : base(name, key, backtest, live, tradingDaysPerYear)
40  {
41  }
42 
43  /// <summary>
44  /// Get annual standard deviation
45  /// </summary>
46  /// <param name="trailingPerformance">The performance for the last period</param>
47  /// <param name="tradingDaysPerYear">The number of trading days per year to get better result of statistics</param>
48  /// <returns>Annual downside standard deviation.</returns>
49  public override double GetAnnualStandardDeviation(List<double> trailingPerformance, double tradingDaysPerYear)
50  {
51  return Statistics.Statistics.AnnualDownsideStandardDeviation(trailingPerformance, tradingDaysPerYear);
52  }
53  }
54 }