18 using System.Runtime.CompilerServices;
29 private const int StartingGreeksCsvIndex = 7;
39 return base.OpenInterest;
51 return CsvLine.GetDecimalFromCsv(6);
62 ThrowIfNotAnOption(nameof(
Greeks));
63 return new PreCalculatedGreeks(
CsvLine);
78 : base(date, symbol, csv)
101 if (
TryRead(config, stream, date, out var symbol, out var remainingLine))
118 if (optionUniverseDataPoint.Symbol.HasUnderlying)
120 optionUniverseDataPoint.Underlying =
Underlying;
121 base.Add(optionUniverseDataPoint);
146 public static string ToCsv(
Symbol symbol, decimal open, decimal high, decimal low, decimal close, decimal volume, decimal? openInterest,
147 decimal? impliedVolatility,
Greeks greeks)
151 return $
"{symbol.ID},{symbol.Value},{open},{high},{low},{close},{volume},{openInterest}";
154 return $
"{symbol.ID},{symbol.Value},{open},{high},{low},{close},{volume},"
155 + $
"{openInterest},{impliedVolatility},{greeks?.Delta},{greeks?.Gamma},{greeks?.Vega},{greeks?.Theta},{greeks?.Rho}";
162 #pragma warning disable CA2225 // Operator overloads have named alternates
164 #pragma warning restore CA2225 // Operator overloads have named alternates
177 return "symbol_id,symbol_value,open,high,low,close,volume,open_interest";
180 return "symbol_id,symbol_value,open,high,low,close,volume,open_interest,implied_volatility,delta,gamma,vega,theta,rho";
183 [MethodImpl(MethodImplOptions.AggressiveInlining)]
184 private void ThrowIfNotAnOption(
string propertyName)
188 throw new InvalidOperationException($
"{propertyName} is only available for options.");
196 private class PreCalculatedGreeks :
Greeks
198 private readonly
string _csvLine;
200 public override decimal Delta => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex);
202 public override decimal Gamma => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 1);
204 public override decimal Vega => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 2);
206 public override decimal Theta => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 3);
208 public override decimal Rho => _csvLine.GetDecimalFromCsv(StartingGreeksCsvIndex + 4);
211 public override decimal Lambda => decimal.Zero;
216 public PreCalculatedGreeks(
string csvLine)
226 return $
"D: {Delta}, G: {Gamma}, V: {Vega}, T: {Theta}, R: {Rho}";