Esempio n. 1
0
 public static TestCase ExtraQuantity(OptionStrategyDefinition definition, params OptionPosition[] positions)
 {
     // add 1 to the first position
     var extra = positions[0].WithQuantity(1);
     var pos = positions.Select((p, i) => i == 0 ? p + extra : p).ToList();
     return new TestCase(nameof(ExtraQuantity), definition, pos, new[] {extra}, Array.Empty<OptionPosition>());
 }
Esempio n. 2
0
 public static TestCase ExtraPosition(OptionStrategyDefinition definition, params OptionPosition[] positions)
 {
     // add a random position w/ the same underlying
     var maxStrike = positions.Where(p => p.Symbol.HasUnderlying).Max(p => p.Strike);
     var extra = new OptionPosition(positions[0].Symbol.WithStrike(maxStrike + 5m), 1);
     var pos = positions.Concat(new[] {extra}).ToList();
     return new TestCase(nameof(ExtraPosition), definition, pos, new[] {extra}, Array.Empty<OptionPosition>());
 }
Esempio n. 3
0
        public void CreatesOptionRightPredicate()
        {
            var definition = OptionStrategyDefinition.Create("CallsOnly", OptionStrategyDefinition.CallLeg(1));
            var onlyLeg    = definition.Legs.Single();

            // put/call isn't phrased as a predicate since every one has it, also due to complexities w/ enums in expressions
            Assert.IsEmpty(onlyLeg);
            var filtered = onlyLeg.Filter(Array.Empty <OptionPosition>(), Positions, false);

            Assert.IsTrue(filtered.All(p => p.Right == OptionRight.Call));
        }
Esempio n. 4
0
            private TestCase(
                string methodName,
                OptionStrategyDefinition definition,
                IReadOnlyList <OptionPosition> positions,
                IReadOnlyList <OptionPosition> extra,
                IReadOnlyList <OptionPosition> missing
                )
            {
                _methodName = methodName;

                Extra      = extra;
                Missing    = missing;
                Definition = definition;
                Positions  = FromPositions(positions);
                var suffix = positions.Select(p =>
                {
                    var quantity = p.Quantity.ToString(CultureInfo.InvariantCulture);
                    if (p.Quantity > 0)
                    {
                        quantity = $"+{quantity}";
                    }

                    if (p.IsUnderlying)
                    {
                        return($"{quantity}{p.Symbol.Value}");
                    }

                    return($"{quantity}{p.Right.ToString()[0]}@{p.Strike}");
                });

                Name = $"{definition.Name}:{methodName}({string.Join(", ", suffix)})";

                //int count;
                //if (NameCounts.TryGetValue(Name, out count))
                //{
                //    // test runner doesn't like duplicate names -- ensure uniqueness by counting instances of names
                //    count++;
                //}

                //NameCounts[Name] = count;
                //Name = $"{Name} ({count})";
                ExpectedMatches = new Dictionary <string, int>
                {
                    { nameof(ExactPosition), 1 },
                    { nameof(ExtraQuantity), 1 },
                    { nameof(ExtraPosition), 1 },
                    { nameof(MissingPosition), 0 }
                };
            }
Esempio n. 5
0
 public static TestCase MissingPosition(OptionStrategyDefinition definition, OptionPosition missing, params OptionPosition[] positions)
 {
     return new TestCase(nameof(MissingPosition), definition, positions, Array.Empty<OptionPosition>(), new []{missing});
 }
Esempio n. 6
0
 public static TestCase ExactPosition(OptionStrategyDefinition definition, params OptionPosition[] positions)
 {
     return new TestCase(nameof(ExactPosition), definition, positions, Array.Empty<OptionPosition>(), Array.Empty<OptionPosition>());
 }