?> QuantXpress – Deliver high performance automated trading and connectivity solutions



Strategy Instrument Variable assignment validation


All strategy must define at least one Instrument Variable for trading transaction. The strategy can define any number of Instrument Variable based on its requirement. For example an options strategy for buying and selling a straddle or strangle needs at least two options contracts. The Strategy must define two Instrument Variables and during the stragy instace creation process, trader can assign a real tradable contract to IV. The server can implement ValidateInstrumentAssignment function to validate if user has correctly mapped the options contract based on strategy requirement. The function ValidateInstrumentAssignment is called multiple time for each Instrument Variable define in your strategy.
 
private IVObject _ivObjectOptionFirstLeg = new IVObject(("OptionsFirstLeg", 
                                                         "Option First Leg",
                                                          true,
                                                          InstrumentType.Options,
                                                          MarketDataType.All,
                                                          OrderEventType.All);

private IVObject _ivObjectOptionSecondLeg = new IVObject(("OptionsSecondLeg", 
                                                          "Option Second Leg",
                                                           true,
                                                           InstrumentType.Options,
                                                           MarketDataType.All,
                                                           OrderEventType.All);

public override bool ValidateInstrumentAssignment(IVObject ivObject,
                                                  Instrument instrument,
                                                  out string errorString)
{
    if (_ivObjectOptionFirstLeg.Name == ivObject.Name)
    {
        if (instrument.InstrumentType != InstrumentType.Options)
        {
            errorString = "Instrument assignment not a valid for Option contract. It must be Option Contract.";
            return false;
        }
     }
     else if (_ivObjectOptionFirstLeg.Name == ivObject.Name)
     {
       if (instrument.InstrumentType != InstrumentType.Options)
       {
           errorString = "Instrument assignment not a valid for Option contract. It must be Option Contract.";
           return false;
        }
      }

      errorString = string.Empty;
      return true;
}

There is one more function supported for Instrument Variable validation. It is called once and share a list of mapped Instrument to its corresponding IVs defined in a strategy. It is useful to compare some properties of both mapped instruments.
 
public override bool ValidateInstrumentAssignments(KeyValuePair[] ivObjetToInstrumentMap,
                                                   out string errorString)
{

    Options optionFirstLegInstrument = null;
    Options optionSecondLegInstrument = null;

    foreach (KeyValuePair iterator in ivObjetToInstrumentMap)
    {
        if (iterator.Key == _ivObjectOptionFirstLeg)
            optionFirstLegInstrument = (Options)iterator.Value;
        else if (iterator.Key == _ivObjectOptionSecondLeg)
            optionSecondLegInstrument = (Options)iterator.Value;
     }

    if (optionFirstLegInstrument.StrikePrice > optionSecondLegInstrument.StrikePrice)
     {
         errorString = "Instrument assignment is incorrect. First leg strike price must be less than second leg strike Price.";
         return false;
     }
     ...........
     ...........
     errorString = string.Empty;
      return true;
}