Lean  $LEAN_TAG$
LiquidETFUniverse.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.Linq;
17 using System.Collections.Generic;
18 
20 {
21  /// <summary>
22  /// Universe Selection Model that adds the following ETFs at their inception date
23  /// </summary>
25  {
26  /// <summary>
27  /// Represents the Energy ETF Category which can be used to access the list of Long and Inverse symbols
28  /// </summary>
29  public static readonly Grouping Energy = new Grouping(
30  new[]
31  {
32  "VDE", "USO", "XES", "XOP", "UNG", "ICLN", "ERX",
33  "UCO", "AMJ", "BNO", "AMLP", "UGAZ", "TAN"
34  },
35  new[] {"ERY", "SCO", "DGAZ" }
36  );
37 
38  /// <summary>
39  /// Represents the Metals ETF Category which can be used to access the list of Long and Inverse symbols
40  /// </summary>
41  public static readonly Grouping Metals = new Grouping(
42  new[] {"GLD", "IAU", "SLV", "GDX", "AGQ", "PPLT", "NUGT", "USLV", "UGLD", "JNUG"},
43  new[] {"DUST", "JDST"}
44  );
45 
46  /// <summary>
47  /// Represents the Technology ETF Category which can be used to access the list of Long and Inverse symbols
48  /// </summary>
49  public static readonly Grouping Technology = new Grouping(
50  new[] {"QQQ", "IGV", "QTEC", "FDN", "FXL", "TECL", "SOXL", "SKYY", "KWEB"},
51  new[] {"TECS", "SOXS"}
52  );
53 
54  /// <summary>
55  /// Represents the Treasuries ETF Category which can be used to access the list of Long and Inverse symbols
56  /// </summary>
57  public static readonly Grouping Treasuries = new Grouping(
58  new[]
59  {
60  "IEF", "SHY", "TLT", "IEI", "TLH", "BIL", "SPTL",
61  "TMF", "SCHO", "SCHR", "SPTS", "GOVT"
62  },
63  new[] {"SHV", "TBT", "TBF", "TMV"}
64  );
65 
66  /// <summary>
67  /// Represents the Volatility ETF Category which can be used to access the list of Long and Inverse symbols
68  /// </summary>
69  public static readonly Grouping Volatility = new Grouping(
70  new[] {"TVIX", "VIXY", "SPLV", "UVXY", "EEMV", "EFAV", "USMV"},
71  new[] {"SVXY"}
72  );
73 
74  /// <summary>
75  /// Represents the SP500 Sectors ETF Category which can be used to access the list of Long and Inverse symbols
76  /// </summary>
77  public static readonly Grouping SP500Sectors = new Grouping(
78  new[] {"XLB", "XLE", "XLF", "XLI", "XLK", "XLP", "XLU", "XLV", "XLY"},
79  new string[0]
80  );
81 
82  /// <summary>
83  /// Initializes a new instance of the LiquidETFUniverse class
84  /// </summary>
85  public LiquidETFUniverse() :
86  base(
87  "qc-liquid-etf-basket",
89  .Concat(Energy)
90  .Concat(Metals)
91  .Concat(Technology)
92  .Concat(Treasuries)
93  .Concat(Volatility)
94  // Convert the concatenated list of Symbol into a Dictionary of DateTime keyed by Symbol
95  // For equities, Symbol.ID is the first date the security is traded.
96  .ToDictionary(x => x.Value, x => x.ID.Date)
97  )
98  {
99 
100  }
101 
102  /// <summary>
103  /// Represent a collection of ETF symbols that is grouped according to a given criteria
104  /// </summary>
105  public class Grouping : List<Symbol>
106  {
107  /// <summary>
108  /// List of Symbols that follow the components direction
109  /// </summary>
110  public readonly List<Symbol> Long;
111 
112  /// <summary>
113  /// List of Symbols that follow the components inverse direction
114  /// </summary>
115  public readonly List<Symbol> Inverse;
116 
117  /// <summary>
118  /// Creates a new instance of <see cref="Grouping"/>.
119  /// </summary>
120  /// <param name="longTickers">List of tickers of ETFs that follows the components direction</param>
121  /// <param name="inverseTickers">List of tickers of ETFs that follows the components inverse direction</param>
122  public Grouping(IEnumerable<string> longTickers, IEnumerable<string> inverseTickers)
123  {
124  Long = longTickers.Select(x => Symbol.Create(x, SecurityType.Equity, Market.USA)).ToList();
125  Inverse = inverseTickers.Select(x => Symbol.Create(x, SecurityType.Equity, Market.USA)).ToList();
126  AddRange(Long);
127  AddRange(Inverse);
128  }
129 
130  /// <summary>
131  /// Returns a string that represents the current object.
132  /// </summary>
133  /// <returns>
134  /// A string that represents the current object.
135  /// </returns>
136  public override string ToString()
137  {
138  if (Count == 0)
139  {
140  return "No Symbols";
141  }
142 
143  var longSymbols = Long.Count == 0
144  ? string.Empty
145  : $" Long: {string.Join(",", Long.Select(x => x.Value))}";
146 
147  var inverseSymbols = Inverse.Count == 0
148  ? string.Empty
149  : $" Inverse: {string.Join(",", Inverse.Select(x => x.Value))}";
150 
151  return $"{Count} symbols:{longSymbols}{inverseSymbols}";
152  }
153  }
154  }
155 }