17 using System.Collections;
18 using System.Collections.Generic;
35 private readonly Dictionary<Type, Dictionary<Symbol, List<BaseData>>> _auxiliaryData =
new Dictionary<Type, Dictionary<Symbol, List<BaseData>>>();
36 private readonly Lazy<PyObject> _dataframe;
98 _dataframe =
new Lazy<PyObject>(() =>
new PandasConverter().GetDataFrame(
this, symbolOnlyIndex:
true), isThreadSafe:
false);
110 Symbol = canonicalOptionSymbol;
130 public OptionChain(
Symbol canonicalOptionSymbol, DateTime time,
BaseData underlying, IEnumerable<BaseData> trades, IEnumerable<BaseData> quotes, IEnumerable<OptionContract> contracts, IEnumerable<Symbol> filteredContracts)
135 Symbol = canonicalOptionSymbol;
144 foreach (var trade
in trades)
146 var tick = trade as
Tick;
150 if (!
Ticks.TryGetValue(tick.Symbol, out ticks))
152 ticks =
new List<Tick>();
153 Ticks[tick.Symbol] = ticks;
165 foreach (var quote
in quotes)
167 var tick = quote as
Tick;
171 if (!
Ticks.TryGetValue(tick.Symbol, out ticks))
173 ticks =
new List<Tick>();
174 Ticks[tick.Symbol] = ticks;
186 foreach (var contract
in contracts)
200 : this(canonicalOptionSymbol, time)
203 Symbol = canonicalOptionSymbol;
211 foreach (var contractData
in contracts)
227 Dictionary<Symbol, List<BaseData>> dictionary;
228 if (!_auxiliaryData.TryGetValue(typeof(T), out dictionary) || !dictionary.TryGetValue(symbol, out list))
232 return list.OfType<T>().LastOrDefault();
242 Dictionary<Symbol, List<BaseData>> d;
243 if (!_auxiliaryData.TryGetValue(typeof(T), out d))
248 foreach (var kvp
in d)
250 var item = kvp.Value.OfType<T>().LastOrDefault();
253 dictionary.Add(kvp.Key, item);
266 Dictionary<Symbol, List<BaseData>> dictionary;
267 if (!_auxiliaryData.TryGetValue(typeof(T), out dictionary))
269 return new Dictionary<Symbol, List<BaseData>>();
283 Dictionary<Symbol, List<BaseData>> dictionary;
284 if (!_auxiliaryData.TryGetValue(typeof(T), out dictionary) || !dictionary.TryGetValue(symbol, out list))
286 return new List<T>();
288 return list.OfType<T>().ToList();
308 IEnumerator IEnumerable.GetEnumerator()
338 internal void AddAuxData(
BaseData baseData)
340 var type = baseData.GetType();
341 Dictionary<Symbol, List<BaseData>> dictionary;
342 if (!_auxiliaryData.TryGetValue(type, out dictionary))
344 dictionary =
new Dictionary<Symbol, List<BaseData>>();
345 _auxiliaryData[type] = dictionary;
349 if (!dictionary.TryGetValue(baseData.
Symbol, out list))
351 list =
new List<BaseData>();
352 dictionary[baseData.
Symbol] = list;