Ejemplo n.º 1
0
 /// <summary>
 /// Determines whether or not the provided combination of preceding <paramref name="legs"/>
 /// and current <paramref name="position"/> adhere to this predicate's requirements.
 /// </summary>
 public bool Matches(IReadOnlyList <OptionPosition> legs, OptionPosition position)
 {
     try
     {
         return(_predicate(legs, position));
     }
     catch (InvalidOperationException)
     {
         // attempt to access option SecurityIdentifier values, such as strike, on the underlying
         // this simply means we don't match and can safely ignore this exception. now, this does
         // somewhat indicate a potential design flaw, but I content that this is better than having
         // to manage the underlying position separately throughout the entire matching process.
         return(false);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines whether or not this leg definition matches the specified <paramref name="position"/>,
        /// and if so, what the resulting quantity of the <see cref="OptionStrategy.OptionLegData"/> should be.
        /// </summary>
        public bool TryMatch(OptionPosition position, out OptionStrategy.LegData leg)
        {
            if (Right != position.Right ||
                Math.Sign(Quantity) != Math.Sign(position.Quantity))
            {
                leg = null;
                return(false);
            }

            var quantity = position.Quantity / Quantity;

            if (quantity == 0)
            {
                leg = null;
                return(false);
            }

            leg = position.Symbol.SecurityType == SecurityType.Option
                ? (OptionStrategy.LegData)OptionStrategy.OptionLegData.Create(quantity, position.Symbol)
                : OptionStrategy.UnderlyingLegData.Create(quantity);

            return(true);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OptionStrategyLegDefinitionMatch"/> struct
 /// </summary>
 /// <param name="multiplier">The number of times the positions matched the leg definition</param>
 /// <param name="position">The position that matched the leg definition</param>
 public OptionStrategyLegDefinitionMatch(int multiplier, OptionPosition position)
 {
     Position   = position;
     Multiplier = multiplier;
 }