From 8bd811738c0f429ef246bf6e18aa27b09cfb0774 Mon Sep 17 00:00:00 2001 From: Jhonathan Abreu Date: Wed, 25 Sep 2024 17:43:40 -0400 Subject: [PATCH] Format OptionContract for dataframe --- Common/Data/Market/OptionContract.cs | 25 +++++++++++++++++++++++++ Common/Python/PandasData.cs | 24 ++++++++++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/Common/Data/Market/OptionContract.cs b/Common/Data/Market/OptionContract.cs index ff13ab384937..9b268b5b828b 100644 --- a/Common/Data/Market/OptionContract.cs +++ b/Common/Data/Market/OptionContract.cs @@ -92,6 +92,31 @@ public decimal ScaledStrike /// public Greeks Greeks => _optionData.Greeks; + /// + /// Gets the delta. Pass-through for + /// + public decimal Delta => Greeks.Delta; + + /// + /// Gets the gamma. Pass-through for + /// + public decimal Gamma => Greeks.Gamma; + + /// + /// Gets the vega. Pass-through for + /// + public decimal Vega => Greeks.Vega; + + /// + /// Gets the theta. Pass-through for + /// + public decimal Theta => Greeks.Theta; + + /// + /// Gets the rho. Pass-through for + /// + public decimal Rho => Greeks.Rho; + /// /// Gets the local date time this contract's data was last updated /// diff --git a/Common/Python/PandasData.cs b/Common/Python/PandasData.cs index 8633f8e3d333..0a1bfd867376 100644 --- a/Common/Python/PandasData.cs +++ b/Common/Python/PandasData.cs @@ -64,12 +64,18 @@ public class PandasData private const string Strike = "strike"; private const string Right = "right"; - private static readonly string[] _optionUniverseExcludedProperties = new[] + private static readonly string[] _optionUniverseExcludedMembers = new[] { nameof(OptionUniverse.ID), nameof(OptionUniverse.Greeks) }; + private static readonly string[] _optionContractExcludedMembers = new[] + { + nameof(OptionContract.ID), + nameof(OptionContract.Greeks) + }; + // we keep these so we don't need to ask for them each time private static PyString _empty; private static PyObject _pandas; @@ -177,6 +183,7 @@ public PandasData(object data) if (keys == null) { var isOptionUniverse = type == typeof(OptionUniverse); + var isOptionContract = type == typeof(OptionContract); if (_membersByType.TryGetValue(type, out _members)) { @@ -186,9 +193,18 @@ public PandasData(object data) { var members = type .GetMembers(BindingFlags.Instance | BindingFlags.Public) - .Where(x => (x.MemberType == MemberTypes.Field || x.MemberType == MemberTypes.Property) && - (!isOptionUniverse || !_optionUniverseExcludedProperties.Contains(x.Name))) - .ToList(); + .Where(x => x.MemberType == MemberTypes.Field || x.MemberType == MemberTypes.Property); + + if (isOptionUniverse) + { + members = members.Where(x => !_optionUniverseExcludedMembers.Contains(x.Name)); + } + else if (isOptionContract) + { + members = members.Where(x => !_optionContractExcludedMembers.Contains(x.Name)); + } + + members = members.ToList(); var duplicateKeys = members.GroupBy(x => x.Name.ToLowerInvariant()).Where(x => x.Count() > 1).Select(x => x.Key); foreach (var duplicateKey in duplicateKeys)