Lean  $LEAN_TAG$
Crisis.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 
20 {
21  /// <summary>
22  /// Crisis events utility class
23  /// </summary>
24  public class Crisis
25  {
26  /// <summary>
27  /// Crisis events and pre-defined values
28  /// </summary>
29  public static readonly Dictionary<CrisisEvent, Crisis> Events = new Dictionary<CrisisEvent, Crisis>
30  {
31  {CrisisEvent.DotCom, new Crisis("DotCom Bubble 2000", new DateTime(2000, 2, 26), new DateTime(2000, 9, 10)) },
32  {CrisisEvent.SeptemberEleventh, new Crisis("September 11, 2001", new DateTime(2001, 9, 5), new DateTime(2001, 10, 10)) },
33  {CrisisEvent.USHousingBubble2003, new Crisis("U.S. Housing Bubble 2003", new DateTime(2003, 1, 1), new DateTime(2003, 2, 20)) },
34  {CrisisEvent.GlobalFinancialCrisis, new Crisis("Global Financial Crisis 2007", new DateTime(2007, 10, 1), new DateTime(2011, 12, 1))},
35  {CrisisEvent.FlashCrash, new Crisis("Flash Crash 2010", new DateTime(2010, 5, 1), new DateTime(2010, 5, 22))},
36  {CrisisEvent.FukushimaMeltdown, new Crisis("Fukushima Meltdown 2011", new DateTime(2011, 3, 1), new DateTime(2011, 4, 22)) },
37  {CrisisEvent.USDowngradeEuropeanDebt, new Crisis("U.S. Credit Downgrade 2011", new DateTime(2011, 8, 5), new DateTime(2011, 9, 1))},
38  {CrisisEvent.EurozoneSeptember2012, new Crisis("ECB IR Event 2012", new DateTime(2012, 9, 5), new DateTime(2012, 10, 12))},
39  {CrisisEvent.EurozoneOctober2014, new Crisis("European Debt Crisis 2014", new DateTime(2014, 10, 1), new DateTime(2014, 10, 29))},
40  {CrisisEvent.MarketSellOff2015, new Crisis("Market Sell-Off 2015", new DateTime(2015, 8, 10), new DateTime(2015, 10, 10))},
41  {CrisisEvent.Recovery, new Crisis("Recovery 2010-2012", new DateTime(2010, 1, 1), new DateTime(2012, 10, 1))},
42  {CrisisEvent.NewNormal, new Crisis("New Normal 2014-2019", new DateTime(2014, 1, 1), new DateTime(2019, 1, 1))},
43  {CrisisEvent.COVID19, new Crisis("COVID-19 Pandemic 2020", new DateTime(2020, 2, 10), new DateTime(2020, 9, 20))},
44  {CrisisEvent.PostCOVIDRunUp, new Crisis("Post-COVID Run-up 2020-2021", new DateTime(2020, 4, 1), new DateTime(2022, 1, 1))},
45  {CrisisEvent.MemeSeason, new Crisis("Meme Season 2021", new DateTime(2021, 1, 1), new DateTime(2021, 5, 15))},
46  {CrisisEvent.RussiaInvadesUkraine, new Crisis("Russia Invades Ukraine 2022-2023", new DateTime(2022, 2, 1), new DateTime(2024, 1, 1))},
47  {CrisisEvent.AIBoom, new Crisis("AI Boom 2022-Present", new DateTime(2022, 11, 30), DateTime.Now)},
48  };
49 
50  /// <summary>
51  /// Start of the crisis event
52  /// </summary>
53  public DateTime Start { get; }
54 
55  /// <summary>
56  /// End of the crisis event
57  /// </summary>
58  public DateTime End { get; }
59 
60  /// <summary>
61  /// Name of the crisis
62  /// </summary>
63  public string Name { get; }
64 
65  /// <summary>
66  /// Creates a new crisis instance with the given name and start/end date.
67  /// </summary>
68  /// <param name="name">Name of the crisis</param>
69  /// <param name="start">Start date of the crisis</param>
70  /// <param name="end">End date of the crisis</param>
71  public Crisis(string name, DateTime start, DateTime end)
72  {
73  Name = name;
74  Start = start;
75  End = end;
76  }
77 
78  /// <summary>
79  /// Returns a pre-defined crisis event
80  /// </summary>
81  /// <param name="crisisEvent">Crisis Event</param>
82  /// <returns>Pre-defined crisis event</returns>
83  public static Crisis FromCrisis(CrisisEvent crisisEvent)
84  {
85  return Events[crisisEvent];
86  }
87 
88  /// <summary>
89  /// Converts instance to string using the dates in the instance as start/end dates
90  /// </summary>
91  /// <returns></returns>
92  public override string ToString()
93  {
94  return ToString(Start, End);
95  }
96 
97  /// <summary>
98  /// Converts instance to string using the provided dates
99  /// </summary>
100  /// <param name="start">Start date</param>
101  /// <param name="end">End date</param>
102  /// <returns></returns>
103  public string ToString(DateTime start, DateTime end)
104  {
105  return $"{Name}";
106  }
107  }
108 }