Lean  $LEAN_TAG$
CrisisReportElement.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.Collections.Generic;
18 using System.Linq;
19 using Deedle;
20 using Python.Runtime;
21 using QuantConnect.Packets;
22 
24 {
25  internal sealed class CrisisReportElement : ChartReportElement
26  {
27  private const string _emptyChart = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABZ8AAAQPCAYAAAB/ZZXyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAewgAAHsIBbtB1PgAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAf+0lEQVR4nOzYwQkAIBDAMHX/nc8lCoIkE/TdPTOzAAAAAAAgdF4HAAAAAADwH/MZAAAAAICc+QwAAAAAQM58BgAAAAAgZz4DAAAAAJAznwEAAAAAyJnPAAAAAADkzGcAAAAAAHLmMwAAAAAAOfMZAAAAAICc+QwAAAAAQM58BgAAAAAgZz4DAAAAAJAznwEAAAAAyJnPAAAAAADkzGcAAAAAAHLmMwAAAAAAOfMZAAAAAICc+QwAAAAAQM58BgAAAAAgZz4DAAAAAJAznwEAAAAAyJnPAAAAAADkzGcAAAAAAHLmMwAAAAAAOfMZAAAAAICc+QwAAAAAQM58BgAAAAAgZz4DAAAAAJAznwEAAAAAyJnPAAAAAADkzGcAAAAAAHLmMwAAAAAAOfMZAAAAAICc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E4+AwAAAACwk88AAAAAAOzkMwAAAAAAO/kMAAAAAMBOPgMAAAAAsJPPAAAAAADs5DMAAAAAADv5DAAAAADATj4DAAAAALCTzwAAAAAA7OQzAAAAAAA7+QwAAAAAwE4+AwAAAACwk88AAAAAAOzkMwAAAAAAO/kMAAAAAMBOPgMAAAAAsJPPAAAAAADs5DMAAAAAADv5DAAAAADATj4DAAAAALCTzwAAAAAA7OQzAAAAAAA7+QwAAAAAwE4+AwAAAACwk88AAAAAAOzkMwAAAAAAO/kMAAAAAMBOPgMAAAAAsJPPAAAAAADs5DMAAAAAADv5DAAAAADATj4DAAAAALCTzwAAAAAA7OQzAAAAAAA7+QwAAAAAwE4+AwAAAACwk88AAAAAAOzkMwAAAAAAO/kMAAAAAMBOPgMAAAAAsJPPAAAAAADs5DMAAAAAADv5DAAAAADATj4DAAAAALCTzwAAAAAA7OQzAAAAAAA7+QwAAAAAwE4+AwAAAACwk88AAAAAAOzkMwAAAAAAO/kMAAAAAMBOPgMAAAAAsJPPAAAAAADs5DMAAAAAADv5DAAAAADATj4DAAAAALCTzwAAAAAA7OQzAAAAAAA7+QwAAAAAwE4+AwAAAACwk88AAAAAAOzkMwAAAAAAO/kMAAAAAMBOPgMAAAAAsJPPAAAAAADs5DMAAAAAADv5DAAAAADATj4DAAAAALCTzwAAAAAA7OQzAAAAAAA7+QwAAAAAwE4+AwAAAACwk88AAAAAAOzkMwAAAAAAO/kMAAAAAMBOPgMAAAAAsJPPAAAAAADsAtkSDBqxWCsiAAAAAElFTkSuQmCC";
28  private LiveResult _live;
29  private BacktestResult _backtest;
30  private string _template;
31 
32  /// <summary>
33  /// Create a new array of crisis event plots
34  /// </summary>
35  /// <param name="name">Name of the widget</param>
36  /// <param name="key">Location of injection</param>
37  /// <param name="backtest">Backtest result object</param>
38  /// <param name="live">Live result object</param>
39  /// <param name="template">HTML template to use</param>
40  public CrisisReportElement(string name, string key, BacktestResult backtest, LiveResult live, string template)
41  {
42  _live = live;
43  _backtest = backtest;
44  _template = template;
45  Name = name;
46  Key = key;
47  }
48 
49  /// <summary>
50  /// The generated output string to be injected
51  /// </summary>
52  public override string Render()
53  {
54  var backtestPoints = ResultsUtil.EquityPoints(_backtest);
55  var backtestBenchmarkPoints = ResultsUtil.BenchmarkPoints(_backtest);
56 
57  var backtestSeries = new Series<DateTime, double>(backtestPoints.Keys, backtestPoints.Values);
58  var backtestBenchmarkSeries = new Series<DateTime, double>(backtestBenchmarkPoints.Keys, backtestBenchmarkPoints.Values);
59 
60  var html = new List<string>();
61 
62  foreach (var crisisEvent in Crisis.Events)
63  {
64  using (Py.GIL())
65  {
66  var crisis = crisisEvent.Value;
67  var data = new PyList();
68  var frame = Frame.CreateEmpty<DateTime, string>();
69 
70  // The two following operations are equivalent to Pandas' `df.resample("D").sum()`
71  frame["Backtest"] = backtestSeries.ResampleEquivalence(date => date.Date, s => s.LastValue());
72  frame["Benchmark"] = backtestBenchmarkSeries.ResampleEquivalence(date => date.Date, s => s.LastValue());
73 
74  var crisisFrame = frame.Where(kvp => kvp.Key >= crisis.Start && kvp.Key <= crisis.End);
75  crisisFrame = crisisFrame.Join("BacktestPercent", crisisFrame["Backtest"].CumulativeReturns());
76  crisisFrame = crisisFrame.Join("BenchmarkPercent", crisisFrame["Benchmark"].CumulativeReturns());
77 
78  // Pad out all missing values to start from 0 for nice plots
79  crisisFrame = crisisFrame.FillMissing(Direction.Forward).FillMissing(0.0);
80 
81  data.Append(crisisFrame.RowKeys.ToList().ToPython());
82  data.Append(crisisFrame["BacktestPercent"].Values.ToList().ToPython());
83  data.Append(crisisFrame["BenchmarkPercent"].Values.ToList().ToPython());
84 
85  var base64 = (string)Charting.GetCrisisEventsPlots(data, crisis.Name.Replace("/", "").Replace(".", "").Replace(" ", ""));
86 
87  if (base64 == _emptyChart)
88  {
89  continue;
90  }
91 
92  if (!crisisFrame.IsEmpty)
93  {
94  var contents = _template.Replace(ReportKey.CrisisTitle, crisis.ToString(crisisFrame.GetRowKeyAt(0), crisisFrame.GetRowKeyAt(crisisFrame.RowCount - 1)));
95  contents = contents.Replace(ReportKey.CrisisContents, base64);
96 
97  html.Add(contents);
98  }
99  }
100  }
101 
102  if (Key == ReportKey.CrisisPageStyle)
103  {
104  if (html.Count == 0)
105  {
106  return "display: none;";
107  }
108 
109  return string.Empty;
110  }
111 
112  return string.Join("\n", html);
113  }
114  }
115 }