Esempio n. 1
0
        public static Trade CreateFraTrade(string tradeId, DateTime adjustedEffectiveDate, DateTime adjustedTerminationDate,
                                           DateTime unadjustedPaymentDate, string paymentDateBusinessDayConvention, string paymentDateBusinessCenters,
                                           string fixingDayOffsetPeriod, string fixingDayOffsetDayType, string fixingDayOffsetBusinessDayConvention,
                                           string fixingDayOffsetBusinessCenters, string fixingDayOffsetDateRelativeTo,
                                           string dayCountFraction, decimal notionalAmount, string notionalCurrency, decimal fixedRate, string floatingRateIndex,
                                           string indexTenor, FraDiscountingEnum fraDiscounting)
        {
            var trade = new Trade();
            var fra   = new Fra
            {
                adjustedEffectiveDate =
                    DateTypesHelper.ToRequiredIdentifierDate(adjustedEffectiveDate),
                adjustedTerminationDate          = adjustedTerminationDate,
                adjustedTerminationDateSpecified = true,
                paymentDate =
                    DateTypesHelper.ToAdjustableDate(unadjustedPaymentDate,
                                                     paymentDateBusinessDayConvention,
                                                     paymentDateBusinessCenters),
                Items = new object[] { new ProductType {
                                           Value = ProductTypeSimpleEnum.FRA.ToString()
                                       } },
                ItemsElementName = new[] { ItemsChoiceType2.productType }
            };

            if ("resetDate" != fixingDayOffsetDateRelativeTo)
            {
                throw new ArgumentException("The fixing date must be specified as 'resetDate'-relative!", nameof(fixingDayOffsetDateRelativeTo));
            }
            var fixingDayType = EnumHelper.Parse <DayTypeEnum>(fixingDayOffsetDayType);

            fra.fixingDateOffset = RelativeDateOffsetHelper.Create(fixingDayOffsetPeriod, fixingDayType,
                                                                   fixingDayOffsetBusinessDayConvention,
                                                                   fixingDayOffsetBusinessCenters,
                                                                   fixingDayOffsetDateRelativeTo);
            fra.dayCountFraction = DayCountFractionHelper.Parse(dayCountFraction);
            IDayCounter dayCounter = DayCounterHelper.Parse(fra.dayCountFraction.Value);

            fra.calculationPeriodNumberOfDays = dayCounter.DayCount(fra.adjustedEffectiveDate.Value, fra.adjustedTerminationDate).ToString(CultureInfo.InvariantCulture);
            fra.notional                = MoneyHelper.GetAmount(notionalAmount, notionalCurrency);
            fra.fixedRate               = fixedRate;
            fra.fixedRateSpecified      = true;
            fra.floatingRateIndex       = FloatingRateIndexHelper.Parse(floatingRateIndex);
            fra.indexTenor              = new[] { PeriodHelper.Parse(indexTenor) };
            fra.fraDiscounting          = fraDiscounting;
            fra.fraDiscountingSpecified = true;
            PartyReference party1 = PartyReferenceFactory.Create("party1");
            PartyReference party2 = PartyReferenceFactory.Create("party2");

            fra.sellerPartyReference = party2;
            fra.buyerPartyReference  = party1;
            XsdClassesFieldResolver.TradeSetFra(trade, fra);
            trade.id = tradeId;
            return(trade);
        }
 public Fra(XmlNode xmlNode)
 : base(xmlNode)
 {
     XmlNodeList buyerPartyReferenceNodeList = xmlNode.SelectNodes("buyerPartyReference");
     if (buyerPartyReferenceNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in buyerPartyReferenceNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 buyerPartyReferenceIDRef = item.Attributes["id"].Name;
                 PartyReference ob = PartyReference();
                 IDManager.SetID(buyerPartyReferenceIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 buyerPartyReferenceIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 buyerPartyReference = new PartyReference(item);
             }
         }
     }
     
 
     XmlNodeList buyerAccountReferenceNodeList = xmlNode.SelectNodes("buyerAccountReference");
     if (buyerAccountReferenceNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in buyerAccountReferenceNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 buyerAccountReferenceIDRef = item.Attributes["id"].Name;
                 AccountReference ob = AccountReference();
                 IDManager.SetID(buyerAccountReferenceIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 buyerAccountReferenceIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 buyerAccountReference = new AccountReference(item);
             }
         }
     }
     
 
     XmlNodeList sellerPartyReferenceNodeList = xmlNode.SelectNodes("sellerPartyReference");
     if (sellerPartyReferenceNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in sellerPartyReferenceNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 sellerPartyReferenceIDRef = item.Attributes["id"].Name;
                 PartyReference ob = PartyReference();
                 IDManager.SetID(sellerPartyReferenceIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 sellerPartyReferenceIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 sellerPartyReference = new PartyReference(item);
             }
         }
     }
     
 
     XmlNodeList sellerAccountReferenceNodeList = xmlNode.SelectNodes("sellerAccountReference");
     if (sellerAccountReferenceNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in sellerAccountReferenceNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 sellerAccountReferenceIDRef = item.Attributes["id"].Name;
                 AccountReference ob = AccountReference();
                 IDManager.SetID(sellerAccountReferenceIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 sellerAccountReferenceIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 sellerAccountReference = new AccountReference(item);
             }
         }
     }
     
 
     XmlNodeList adjustedEffectiveDateNodeList = xmlNode.SelectNodes("adjustedEffectiveDate");
     if (adjustedEffectiveDateNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in adjustedEffectiveDateNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 adjustedEffectiveDateIDRef = item.Attributes["id"].Name;
                 RequiredIdentifierDate ob = RequiredIdentifierDate();
                 IDManager.SetID(adjustedEffectiveDateIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 adjustedEffectiveDateIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 adjustedEffectiveDate = new RequiredIdentifierDate(item);
             }
         }
     }
     
 
     XmlNodeList adjustedTerminationDateNodeList = xmlNode.SelectNodes("adjustedTerminationDate");
     if (adjustedTerminationDateNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in adjustedTerminationDateNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 adjustedTerminationDateIDRef = item.Attributes["id"].Name;
                 XsdTypeDate ob = XsdTypeDate();
                 IDManager.SetID(adjustedTerminationDateIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 adjustedTerminationDateIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 adjustedTerminationDate = new XsdTypeDate(item);
             }
         }
     }
     
 
     XmlNodeList paymentDateNodeList = xmlNode.SelectNodes("paymentDate");
     if (paymentDateNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in paymentDateNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 paymentDateIDRef = item.Attributes["id"].Name;
                 AdjustableDate ob = AdjustableDate();
                 IDManager.SetID(paymentDateIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 paymentDateIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 paymentDate = new AdjustableDate(item);
             }
         }
     }
     
 
     XmlNodeList fixingDateOffsetNodeList = xmlNode.SelectNodes("fixingDateOffset");
     if (fixingDateOffsetNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in fixingDateOffsetNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 fixingDateOffsetIDRef = item.Attributes["id"].Name;
                 RelativeDateOffset ob = RelativeDateOffset();
                 IDManager.SetID(fixingDateOffsetIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 fixingDateOffsetIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 fixingDateOffset = new RelativeDateOffset(item);
             }
         }
     }
     
 
     XmlNodeList dayCountFractionNodeList = xmlNode.SelectNodes("dayCountFraction");
     if (dayCountFractionNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in dayCountFractionNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 dayCountFractionIDRef = item.Attributes["id"].Name;
                 DayCountFraction ob = DayCountFraction();
                 IDManager.SetID(dayCountFractionIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 dayCountFractionIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 dayCountFraction = new DayCountFraction(item);
             }
         }
     }
     
 
     XmlNodeList calculationPeriodNumberOfDaysNodeList = xmlNode.SelectNodes("calculationPeriodNumberOfDays");
     if (calculationPeriodNumberOfDaysNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in calculationPeriodNumberOfDaysNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 calculationPeriodNumberOfDaysIDRef = item.Attributes["id"].Name;
                 XsdTypePositiveInteger ob = XsdTypePositiveInteger();
                 IDManager.SetID(calculationPeriodNumberOfDaysIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 calculationPeriodNumberOfDaysIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 calculationPeriodNumberOfDays = new XsdTypePositiveInteger(item);
             }
         }
     }
     
 
     XmlNodeList notionalNodeList = xmlNode.SelectNodes("notional");
     if (notionalNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in notionalNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 notionalIDRef = item.Attributes["id"].Name;
                 Money ob = Money();
                 IDManager.SetID(notionalIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 notionalIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 notional = new Money(item);
             }
         }
     }
     
 
     XmlNodeList fixedRateNodeList = xmlNode.SelectNodes("fixedRate");
     if (fixedRateNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in fixedRateNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 fixedRateIDRef = item.Attributes["id"].Name;
                 XsdTypeDecimal ob = XsdTypeDecimal();
                 IDManager.SetID(fixedRateIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 fixedRateIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 fixedRate = new XsdTypeDecimal(item);
             }
         }
     }
     
 
     XmlNodeList floatingRateIndexNodeList = xmlNode.SelectNodes("floatingRateIndex");
     if (floatingRateIndexNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in floatingRateIndexNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 floatingRateIndexIDRef = item.Attributes["id"].Name;
                 FloatingRateIndex ob = FloatingRateIndex();
                 IDManager.SetID(floatingRateIndexIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 floatingRateIndexIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 floatingRateIndex = new FloatingRateIndex(item);
             }
         }
     }
     
 
     XmlNodeList indexTenorNodeList = xmlNode.SelectNodes("indexTenor");
     
     foreach (XmlNode item in indexTenorNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 indexTenorIDRef = item.Attributes["id"].Name;
                 List<Period> ob = new List<Period>();
                 ob.Add(new Period(item));
                 IDManager.SetID(indexTenorIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 indexTenorIDRef = item.Attributes["href"].Name;
             }
             else
             {
             indexTenor.Add(new Period(item));
             }
         }
     }
     
 
     XmlNodeList fraDiscountingNodeList = xmlNode.SelectNodes("fraDiscounting");
     if (fraDiscountingNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in fraDiscountingNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 fraDiscountingIDRef = item.Attributes["id"].Name;
                 FraDiscountingEnum ob = FraDiscountingEnum();
                 IDManager.SetID(fraDiscountingIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 fraDiscountingIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 fraDiscounting = new FraDiscountingEnum(item);
             }
         }
     }
     
 
 }