Skip to content

Commit

Permalink
Format OptionContract for dataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonabreul committed Sep 25, 2024
1 parent 1467224 commit 8bd8117
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
25 changes: 25 additions & 0 deletions Common/Data/Market/OptionContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ public decimal ScaledStrike
/// </summary>
public Greeks Greeks => _optionData.Greeks;

/// <summary>
/// Gets the delta. Pass-through for <see cref="Greeks.Delta"/>
/// </summary>
public decimal Delta => Greeks.Delta;

/// <summary>
/// Gets the gamma. Pass-through for <see cref="Greeks.Gamma"/>
/// </summary>
public decimal Gamma => Greeks.Gamma;

/// <summary>
/// Gets the vega. Pass-through for <see cref="Greeks.Vega"/>
/// </summary>
public decimal Vega => Greeks.Vega;

/// <summary>
/// Gets the theta. Pass-through for <see cref="Greeks.Theta"/>
/// </summary>
public decimal Theta => Greeks.Theta;

/// <summary>
/// Gets the rho. Pass-through for <see cref="Greeks.Rho"/>
/// </summary>
public decimal Rho => Greeks.Rho;

/// <summary>
/// Gets the local date time this contract's data was last updated
/// </summary>
Expand Down
24 changes: 20 additions & 4 deletions Common/Python/PandasData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
{
Expand All @@ -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)
Expand Down

0 comments on commit 8bd8117

Please sign in to comment.