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;
37 private readonly
bool _flatten;
106 _dataframe =
new Lazy<PyObject>(
109 if (!PythonEngine.IsInitialized)
113 return new PandasConverter().GetDataFrame(
new[] {
this }, symbolOnlyIndex:
true, flatten: _flatten);
115 isThreadSafe:
false);
128 Symbol = canonicalOptionSymbol;
150 IEnumerable<BaseData> quotes, IEnumerable<OptionContract> contracts, IEnumerable<Symbol> filteredContracts,
bool flatten =
true)
155 Symbol = canonicalOptionSymbol;
164 foreach (var trade
in trades)
166 var tick = trade as
Tick;
170 if (!
Ticks.TryGetValue(tick.Symbol, out ticks))
172 ticks =
new List<Tick>();
173 Ticks[tick.Symbol] = ticks;
185 foreach (var quote
in quotes)
187 var tick = quote as
Tick;
191 if (!
Ticks.TryGetValue(tick.Symbol, out ticks))
193 ticks =
new List<Tick>();
194 Ticks[tick.Symbol] = ticks;
206 foreach (var contract
in contracts)
222 : this(canonicalOptionSymbol, time, flatten)
225 Symbol = canonicalOptionSymbol;
233 foreach (var contractData
in contracts)
249 Dictionary<Symbol, List<BaseData>> dictionary;
250 if (!_auxiliaryData.TryGetValue(typeof(T), out dictionary) || !dictionary.TryGetValue(symbol, out list))
254 return list.OfType<T>().LastOrDefault();
264 Dictionary<Symbol, List<BaseData>> d;
265 if (!_auxiliaryData.TryGetValue(typeof(T), out d))
270 foreach (var kvp
in d)
272 var item = kvp.Value.OfType<T>().LastOrDefault();
275 dictionary.Add(kvp.Key, item);
288 Dictionary<Symbol, List<BaseData>> dictionary;
289 if (!_auxiliaryData.TryGetValue(typeof(T), out dictionary))
291 return new Dictionary<Symbol, List<BaseData>>();
305 Dictionary<Symbol, List<BaseData>> dictionary;
306 if (!_auxiliaryData.TryGetValue(typeof(T), out dictionary) || !dictionary.TryGetValue(symbol, out list))
308 return new List<T>();
310 return list.OfType<T>().ToList();
330 IEnumerator IEnumerable.GetEnumerator()
360 internal void AddAuxData(
BaseData baseData)
362 var type = baseData.GetType();
363 Dictionary<Symbol, List<BaseData>> dictionary;
364 if (!_auxiliaryData.TryGetValue(type, out dictionary))
366 dictionary =
new Dictionary<Symbol, List<BaseData>>();
367 _auxiliaryData[type] = dictionary;
371 if (!dictionary.TryGetValue(baseData.
Symbol, out list))
373 list =
new List<BaseData>();
374 dictionary[baseData.
Symbol] = list;