18 using System.Runtime.CompilerServices;
30 private const int StartingGreeksCsvIndex = 7;
33 private readonly
string _csvLine;
53 return _csvLine.GetDecimalFromCsv(0);
64 return _csvLine.GetDecimalFromCsv(1);
75 return _csvLine.GetDecimalFromCsv(2);
86 return _csvLine.GetDecimalFromCsv(3);
97 return _csvLine.GetDecimalFromCsv(4);
109 return _csvLine.GetDecimalFromCsv(5);
121 return _csvLine.GetDecimalFromCsv(6);
132 ThrowIfNotAnOption(nameof(
Greeks));
133 return new PreCalculatedGreeks(_csvLine);
140 public override DateTime
EndTime
157 : base(date, date, symbol, null, null)
168 _csvLine = other._csvLine;
181 path = Path.Combine(path, $
"{date:yyyyMMdd}.csv");
197 if (stream ==
null || stream.EndOfStream)
202 var sidStr = stream.GetString();
204 if (sidStr.StartsWith(
"#", StringComparison.InvariantCulture))
210 var symbolValue = stream.GetString();
211 var remainingLine = stream.ReadLine();
213 var key = $
"{sidStr}:{symbolValue}";
219 if (sid.HasUnderlying)
223 out var _, out var underlyingValue, out var _, out var _, out var _);
224 var underlyingKey = $
"{sid.Underlying}:{underlyingValue}";
225 var underlyingWasCached =
TryGetCachedSymbol(underlyingKey, out var underlyingSymbol);
229 if (!underlyingWasCached)
236 symbol =
new Symbol(sid, symbolValue);
254 if (optionUniverseDataPoint.Symbol.HasUnderlying)
256 optionUniverseDataPoint.Underlying =
Underlying;
257 base.Add(optionUniverseDataPoint);
292 public static string ToCsv(
Symbol symbol, decimal open, decimal high, decimal low, decimal close, decimal volume, decimal? openInterest,
293 decimal? impliedVolatility,
Greeks greeks)
295 return $
"{symbol.ID},{symbol.Value},{open},{high},{low},{close},{volume},"
296 + $
"{openInterest},{impliedVolatility},{greeks?.Delta},{greeks?.Gamma},{greeks?.Vega},{greeks?.Theta},{greeks?.Rho}";
319 public static string CsvHeader =>
"symbol_id,symbol_value,open,high,low,close,volume,open_interest,implied_volatility,delta,gamma,vega,theta,rho";
321 [MethodImpl(MethodImplOptions.AggressiveInlining)]
322 private void ThrowIfNotAnOption(
string propertyName)
326 throw new InvalidOperationException($
"{propertyName} is only available for options.");
334 private class PreCalculatedGreeks :
Greeks
336 private readonly
string _csvLine;
338 public override decimal Delta => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex);
340 public override decimal Gamma => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 1);
342 public override decimal Vega => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 2);
344 public override decimal Theta => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 3);
346 public override decimal Rho => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 4);
348 public override decimal Lambda => decimal.Zero;
353 public PreCalculatedGreeks(
string csvLine)
363 return $
"D: {Delta}, G: {Gamma}, V: {Vega}, T: {Theta}, R: {Rho}";