18 using System.Runtime.CompilerServices;
31 private const int StartingGreeksCsvIndex = 7;
34 private readonly
string _csvLine;
56 return _csvLine.GetDecimalFromCsv(0);
67 return _csvLine.GetDecimalFromCsv(1);
78 return _csvLine.GetDecimalFromCsv(2);
89 return _csvLine.GetDecimalFromCsv(3);
100 return _csvLine.GetDecimalFromCsv(4);
112 return _csvLine.GetDecimalFromCsv(5);
124 return _csvLine.GetDecimalFromCsv(6);
135 ThrowIfNotAnOption(nameof(
Greeks));
136 return new PreCalculatedGreeks(_csvLine);
143 public override DateTime
EndTime
160 : base(date, date, symbol, null, null)
171 _csvLine = other._csvLine;
184 path = Path.Combine(path, $
"{date:yyyyMMdd}.csv");
200 if (stream ==
null || stream.EndOfStream)
205 var sidStr = stream.GetString();
207 if (sidStr.StartsWith(
"#", StringComparison.InvariantCulture))
213 var symbolValue = stream.GetString();
214 var remainingLine = stream.ReadLine();
216 var key = $
"{sidStr}:{symbolValue}";
222 if (sid.HasUnderlying)
226 out var _, out var underlyingValue, out var _, out var _, out var _);
227 var underlyingKey = $
"{sid.Underlying}:{underlyingValue}";
228 var underlyingWasCached =
TryGetCachedSymbol(underlyingKey, out var underlyingSymbol);
232 if (!underlyingWasCached)
239 symbol =
new Symbol(sid, symbolValue);
257 if (optionUniverseDataPoint.Symbol.HasUnderlying)
259 optionUniverseDataPoint.Underlying =
Underlying;
260 base.Add(optionUniverseDataPoint);
295 public static string ToCsv(
Symbol symbol, decimal open, decimal high, decimal low, decimal close, decimal volume, decimal? openInterest,
296 decimal? impliedVolatility,
Greeks greeks)
298 return $
"{symbol.ID},{symbol.Value},{open},{high},{low},{close},{volume},"
299 + $
"{openInterest},{impliedVolatility},{greeks?.Delta},{greeks?.Gamma},{greeks?.Vega},{greeks?.Theta},{greeks?.Rho}";
322 public static string CsvHeader =>
"symbol_id,symbol_value,open,high,low,close,volume,open_interest,implied_volatility,delta,gamma,vega,theta,rho";
324 [MethodImpl(MethodImplOptions.AggressiveInlining)]
325 private void ThrowIfNotAnOption(
string propertyName)
329 throw new InvalidOperationException($
"{propertyName} is only available for options.");
337 private class PreCalculatedGreeks :
Greeks
339 private readonly
string _csvLine;
341 public override decimal Delta => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex);
343 public override decimal Gamma => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 1);
345 public override decimal Vega => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 2);
347 public override decimal Theta => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 3);
349 public override decimal Rho => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 4);
352 public override decimal Lambda => decimal.Zero;
357 public PreCalculatedGreeks(
string csvLine)
367 return $
"D: {Delta}, G: {Gamma}, V: {Vega}, T: {Theta}, R: {Rho}";