Lean  $LEAN_TAG$
FuturesOptionsSymbolMappings.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.Collections.Generic;
17 using System.Linq;
18 
20 {
21  /// <summary>
22  /// Provides conversions from a GLOBEX Futures ticker to a GLOBEX Futures Options ticker
23  /// </summary>
24  public static class FuturesOptionsSymbolMappings
25  {
26  /// <summary>
27  /// Defines Futures GLOBEX Ticker -> Futures Options GLOBEX Ticker
28  /// </summary>
29  private static Dictionary<string, string> _futureToFutureOptionsGLOBEX = new Dictionary<string, string>
30  {
31  { "EH", "OEH" },
32  { "KE", "OKE" },
33  { "TN", "OTN" },
34  { "UB", "OUB" },
35  { "YM", "OYM" },
36  { "ZB", "OZB" },
37  { "ZC", "OZC" },
38  { "ZF", "OZF" },
39  { "ZL", "OZL" },
40  { "ZM", "OZM" },
41  { "ZN", "OZN" },
42  { "ZO", "OZO" },
43  { "ZS", "OZS" },
44  { "ZT", "OZT" },
45  { "ZW", "OZW" },
46  { "RTY", "RTO" },
47  { "GC", "OG" },
48  { "HG", "HXE" },
49  { "SI", "SO" },
50  { "CL", "LO" },
51  { "HCL", "HCO" },
52  { "HO", "OH" },
53  { "NG", "ON" },
54  { "PA", "PAO" },
55  { "PL", "PO" },
56  { "RB", "OB" },
57  { "YG", "OYG" },
58  { "ZG", "OZG" },
59  { "ZI", "OZI" }
60  };
61 
62  private static Dictionary<string, string> _futureOptionsToFutureGLOBEX = _futureToFutureOptionsGLOBEX
63  .ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
64 
65  /// <summary>
66  /// Returns the futures options ticker for the given futures ticker.
67  /// </summary>
68  /// <param name="futureTicker">Future GLOBEX ticker to get Future Option GLOBEX ticker for</param>
69  /// <returns>Future option ticker. Defaults to future ticker provided if no entry is found</returns>
70  public static string Map(string futureTicker)
71  {
72  futureTicker = futureTicker.ToUpperInvariant();
73 
74  string result;
75  if (!_futureToFutureOptionsGLOBEX.TryGetValue(futureTicker, out result))
76  {
77  return futureTicker;
78  }
79 
80  return result;
81  }
82 
83  /// <summary>
84  /// Maps a futures options ticker to its underlying future's ticker
85  /// </summary>
86  /// <param name="futureOptionTicker">Future option ticker to map to the underlying</param>
87  /// <returns>Future ticker</returns>
88  public static string MapFromOption(string futureOptionTicker)
89  {
90  futureOptionTicker = futureOptionTicker.ToUpperInvariant();
91 
92  string result;
93  if (!_futureOptionsToFutureGLOBEX.TryGetValue(futureOptionTicker, out result))
94  {
95  return futureOptionTicker;
96  }
97 
98  return result;
99  }
100  }
101 }