//-------------------------------------------------------------------------
 // rate calculation
 private static RateCalculation parseRateCalculation(CsvRow row, string leg, FloatingRateIndex index, DayCount defaultFixedLegDayCount, BusinessDayAdjustment bda, Currency currency)
 {
     if (index is IborIndex)
     {
         return(parseIborRateCalculation(row, leg, (IborIndex)index, bda, currency));
     }
     else if (index is OvernightIndex)
     {
         Optional <FloatingRateName> frnOpt = FloatingRateName.extendedEnum().find(getValue(row, leg, INDEX_FIELD));
         if (frnOpt.Present)
         {
             FloatingRateName frn = frnOpt.get();
             if (frn.Type == FloatingRateType.OVERNIGHT_AVERAGED)
             {
                 return(parseOvernightRateCalculation(row, leg, (OvernightIndex)index, OvernightAccrualMethod.AVERAGED));
             }
         }
         return(parseOvernightRateCalculation(row, leg, (OvernightIndex)index, OvernightAccrualMethod.COMPOUNDED));
     }
     else if (index is PriceIndex)
     {
         return(parseInflationRateCalculation(row, leg, (PriceIndex)index, currency));
     }
     else
     {
         return(parseFixedRateCalculation(row, leg, currency, defaultFixedLegDayCount));
     }
 }
        //-------------------------------------------------------------------------
        // parse the index and default fixed leg day count
        private static FloatingRateIndex parseIndex(CsvRow row, string leg)
        {
            Optional <string> fixedRateOpt = findValue(row, leg, FIXED_RATE_FIELD);
            Optional <string> indexOpt     = findValue(row, leg, INDEX_FIELD);

            if (fixedRateOpt.Present)
            {
                if (indexOpt.Present)
                {
                    throw new System.ArgumentException("Swap leg must not define both '" + leg + FIXED_RATE_FIELD + "' and  '" + leg + INDEX_FIELD + "'");
                }
                return(null);
            }
            if (!indexOpt.Present)
            {
                throw new System.ArgumentException("Swap leg must define either '" + leg + FIXED_RATE_FIELD + "' or  '" + leg + INDEX_FIELD + "'");
            }
            // use FloatingRateName to identify Ibor vs other
            string           indexStr = indexOpt.get();
            FloatingRateName frn      = FloatingRateName.parse(indexStr);

            if (frn.Type == FloatingRateType.IBOR)
            {
                // re-parse Ibor using tenor, which ensures tenor picked up from indexStr if present
                Frequency freq      = Frequency.parse(getValue(row, leg, FREQUENCY_FIELD));
                Tenor     iborTenor = freq.Term ? frn.DefaultTenor : Tenor.of(freq.Period);
                return(FloatingRateIndex.parse(indexStr, iborTenor));
            }
            return(frn.toFloatingRateIndex());
        }
Exemplo n.º 3
0
        public static FloatingRateIndex Parse(string s)
        {
            var result = new FloatingRateIndex {
                Value = s
            };

            return(result);
        }
        public static FloatingRateIndex Parse(string s)
        {
            FloatingRateIndex result = new FloatingRateIndex();

            result.Value = s;

            return(result);
        }
Exemplo n.º 5
0
        public static FloatingRateCalculation CreateFloating(FloatingRateIndex floatingRateIndex, Period tenor)
        {
            FloatingRateCalculation floatingRateCalculation = new FloatingRateCalculation();

            floatingRateCalculation.floatingRateIndex = floatingRateIndex;
            floatingRateCalculation.indexTenor        = tenor;

            return(floatingRateCalculation);
        }
        public static FloatingRateCalculation CreateFloating(FloatingRateIndex floatingRateIndex, Period tenor)
        {
            var floatingRateCalculation = new FloatingRateCalculation
            {
                floatingRateIndex = floatingRateIndex,
                indexTenor        = tenor
            };

            return(floatingRateCalculation);
        }
 public virtual void test_tryParse_withTenor()
 {
     assertEquals(FloatingRateIndex.tryParse("GBP-LIBOR", Tenor.TENOR_6M), IborIndices.GBP_LIBOR_6M);
     assertEquals(FloatingRateIndex.tryParse("GBP-LIBOR-1M", Tenor.TENOR_6M), IborIndices.GBP_LIBOR_1M);
     assertEquals(FloatingRateIndex.tryParse("GBP-LIBOR-3M", Tenor.TENOR_6M), IborIndices.GBP_LIBOR_3M);
     assertEquals(FloatingRateIndex.tryParse("GBP-SONIA", Tenor.TENOR_6M), OvernightIndices.GBP_SONIA);
     assertEquals(FloatingRateIndex.tryParse("GB-RPI", Tenor.TENOR_6M), PriceIndices.GB_RPI);
     assertEquals(FloatingRateIndex.tryParse(null, Tenor.TENOR_6M), null);
     assertEquals(FloatingRateIndex.tryParse("NotAnIndex", Tenor.TENOR_6M), null);
 }
        // parse a single leg
        private static RateCalculationSwapLeg parseLeg(CsvRow row, string leg, FloatingRateIndex index, DayCount defaultFixedLegDayCount)
        {
            PayReceive       payReceive  = LoaderUtils.parsePayReceive(getValue(row, leg, DIRECTION_FIELD));
            PeriodicSchedule accrualSch  = parseAccrualSchedule(row, leg);
            PaymentSchedule  paymentSch  = parsePaymentSchedule(row, leg, accrualSch.Frequency);
            NotionalSchedule notionalSch = parseNotionalSchedule(row, leg);
            RateCalculation  calc        = parseRateCalculation(row, leg, index, defaultFixedLegDayCount, accrualSch.BusinessDayAdjustment, notionalSch.Currency);

            return(RateCalculationSwapLeg.builder().payReceive(payReceive).accrualSchedule(accrualSch).paymentSchedule(paymentSch).notionalSchedule(notionalSch).calculation(calc).build());
        }
 public virtual void test_parse_noTenor()
 {
     assertEquals(FloatingRateIndex.parse("GBP-LIBOR"), IborIndices.GBP_LIBOR_3M);
     assertEquals(FloatingRateIndex.parse("GBP-LIBOR-1M"), IborIndices.GBP_LIBOR_1M);
     assertEquals(FloatingRateIndex.parse("GBP-LIBOR-3M"), IborIndices.GBP_LIBOR_3M);
     assertEquals(FloatingRateIndex.parse("GBP-SONIA"), OvernightIndices.GBP_SONIA);
     assertEquals(FloatingRateIndex.parse("GB-RPI"), PriceIndices.GB_RPI);
     assertThrowsIllegalArg(() => FloatingRateIndex.parse(null));
     assertThrowsIllegalArg(() => FloatingRateIndex.parse("NotAnIndex"));
 }
        public static FloatingRateDefinition CreateSimple(FloatingRateIndex floatingRateIndex, Period tenor,
                                                          decimal derivedRate, decimal spread)
        {
            FloatingRateDefinition floatingRateDefinition = new FloatingRateDefinition();

            floatingRateDefinition.calculatedRate          = derivedRate + spread;
            floatingRateDefinition.calculatedRateSpecified = true;
            floatingRateDefinition.spread          = spread;
            floatingRateDefinition.spreadSpecified = true;
            return(floatingRateDefinition);
        }
Exemplo n.º 11
0
        public static FloatingRateDefinition CreateSimple(FloatingRateIndex floatingRateIndex, Period tenor,
                                                          decimal derivedRate, decimal spread)
        {
            var floatingRateDefinition = new FloatingRateDefinition
            {
                calculatedRate          = derivedRate + spread,
                calculatedRateSpecified = true,
                spread          = spread,
                spreadSpecified = true
            };

            return(floatingRateDefinition);
        }
Exemplo n.º 12
0
        public static Calculation CreateFloating(decimal fixedRate, Money notional, FloatingRateIndex floatingRateIndex, Period tenor,
                                                 DayCountFraction dayCountFraction, DiscountingTypeEnum discountingType)
        {
            var calculation = new Calculation
            {
                Item = NotionalFactory.Create(notional),
                compoundingMethod          = CompoundingMethodEnum.None,
                compoundingMethodSpecified = true,
                dayCountFraction           = dayCountFraction,
                discounting =
                    DiscountingHelper.Create(fixedRate, dayCountFraction, discountingType),
                Items = new object[] { FloatingRateCalculationHelper.CreateFloating(floatingRateIndex, tenor) }
            };

            return(calculation);
        }
        /// <summary>
        /// Parses from the CSV row.
        /// </summary>
        /// <param name="row">  the CSV row </param>
        /// <param name="info">  the trade info </param>
        /// <returns> the parsed trade </returns>
        internal static SwapTrade parse(CsvRow row, TradeInfo info)
        {
            // parse any number of legs by looking for 'Leg n Pay Receive'
            // this finds the index for each leg, using null for fixed legs
            IList <FloatingRateIndex> indices   = new List <FloatingRateIndex>();
            ISet <DayCount>           dayCounts = new LinkedHashSet <DayCount>();
            bool              missingDayCount   = false;
            string            legPrefix         = "Leg 1 ";
            Optional <string> payReceiveOpt     = getValue(row, legPrefix, DIRECTION_FIELD);
            int i = 1;

            while (payReceiveOpt.Present)
            {
                // parse this leg, capturing the day count for floating legs
                FloatingRateIndex index = parseIndex(row, legPrefix);
                indices.Add(index);
                if (index != null)
                {
                    dayCounts.Add(index.DefaultFixedLegDayCount);
                }
                // defaulting only triggered if a fixed leg actually has a missing day count
                if (index == null && !findValue(row, legPrefix, DAY_COUNT_FIELD).Present)
                {
                    missingDayCount = true;
                }
                // check if there is another leg
                i++;
                legPrefix     = "Leg " + i + " ";
                payReceiveOpt = findValue(row, legPrefix, DIRECTION_FIELD);
            }
            // determine the default day count for the fixed leg (only if there is a fixed leg)
            DayCount defaultFixedLegDayCount = null;

            if (missingDayCount)
            {
                if (dayCounts.Count != 1)
                {
                    throw new System.ArgumentException("Invalid swap definition, day count must be defined on each fixed leg");
                }
                defaultFixedLegDayCount = Iterables.getOnlyElement(dayCounts);
            }
            // parse fully now we know the number of legs and the default fixed leg day count
            IList <SwapLeg> legs = parseLegs(row, indices, defaultFixedLegDayCount);
            Swap            swap = Swap.of(legs);

            return(SwapTrade.of(info, swap));
        }
        public static FloatingLegCalculation Create(FloatingRateIndex floatingRateIndex, Period tenor, AveragingMethodEnum averagingMethod,
                                                    decimal conversionFactor, Rounding rounding, CommodityPricingDates pricingDates, CommodityFx fx, object[] commoditySpreadArray)
        {
            var floatingRateCalculation = new FloatingLegCalculation
            {
                averagingMethod           = averagingMethod,
                averagingMethodSpecified  = true,
                conversionFactor          = conversionFactor,
                conversionFactorSpecified = true,
                rounding     = rounding,
                pricingDates = pricingDates,
                fx           = fx,
                Items        = commoditySpreadArray
            };

            return(floatingRateCalculation);
        }
        public static FloatingRateDefinition CreateCapFloor(FloatingRateIndex floatingRateIndex, Period tenor, DateTime adjustedFixingDate,
                                                            decimal observedRate, decimal spread, decimal capfloorstrike, bool isCap)
        {
            FloatingRateDefinition floatingRateDefinition = CreateSimple(floatingRateIndex, tenor, adjustedFixingDate, observedRate, spread);
            var strike = new Strike();

            strike.strikeRate = capfloorstrike;
            if (isCap)
            {
                floatingRateDefinition.capRate = new[] { strike };
            }
            else
            {
                floatingRateDefinition.floorRate = new[] { strike };
            }
            return(floatingRateDefinition);
        }
Exemplo n.º 16
0
        public static Calculation CreateFloating(Money notional, FloatingRateIndex floatingRateIndex, Period tenor, DayCountFraction dayCountFraction, DiscountingTypeEnum?discountingType)
        {
            var discounting = discountingType != null
                                  ? DiscountingHelper.Create(null, dayCountFraction, (DiscountingTypeEnum)discountingType)
                                  : null;

            var calculation = new Calculation
            {
                Items                      = new object[] { NotionalFactory.Create(notional) },
                compoundingMethod          = CompoundingMethodEnum.None,
                compoundingMethodSpecified = true,
                dayCountFraction           = dayCountFraction,
                discounting                = discounting,
                Items1                     = new object[] { FloatingRateCalculationHelper.CreateFloating(floatingRateIndex, tenor) }
            };

            return(calculation);
        }
Exemplo n.º 17
0
        public static Calculation CreateFloating(Money notional, FloatingRateIndex floatingRateIndex, Period tenor, DayCountFraction dayCountFraction, DiscountingTypeEnum discountingType)
        {
            var calculation = new Calculation
            {
                Items                      = new object[] { NotionalFactory.Create(notional) },
                compoundingMethod          = CompoundingMethodEnum.None,
                compoundingMethodSpecified = true,
                dayCountFraction           = dayCountFraction
            };
            var discounting = new Discounting
            {
                discountingType = discountingType,
                discountRateDayCountFraction = dayCountFraction
            };

            calculation.discounting = discounting;
            calculation.Items       = new object[] { FloatingRateCalculationHelper.CreateFloating(floatingRateIndex, tenor) };
            return(calculation);
        }
Exemplo n.º 18
0
        public static RateIndex Create(string instrumentId,
                                       FloatingRateIndex floatingRateIndex,
                                       Currency currency,
                                       DayCountFraction dayCountFraction,
                                       Period paymentFrequency,
                                       Period term)
        {
            RateIndex rateIndex = new RateIndex();

            rateIndex.currency = new IdentifiedCurrency()
            {
                Value = currency.Value
            };
            rateIndex.dayCountFraction  = dayCountFraction;
            rateIndex.floatingRateIndex = floatingRateIndex;
            rateIndex.id               = instrumentId;
            rateIndex.instrumentId     = InstrumentIdArrayHelper.Parse(instrumentId);
            rateIndex.paymentFrequency = paymentFrequency;
            rateIndex.term             = term;

            return(rateIndex);
        }
Exemplo n.º 19
0
        public static RateIndex Create(string instrumentId,
                                       FloatingRateIndex floatingRateIndex,
                                       Currency currency,
                                       DayCountFraction dayCountFraction,
                                       Period paymentFrequency,
                                       Period term)
        {
            var rateIndex = new RateIndex
            {
                currency = new IdentifiedCurrency {
                    Value = currency.Value
                },
                dayCountFraction  = dayCountFraction,
                floatingRateIndex = floatingRateIndex,
                id               = instrumentId,
                instrumentId     = InstrumentIdArrayHelper.Parse(instrumentId),
                paymentFrequency = paymentFrequency,
                term             = term
            };

            return(rateIndex);
        }
Exemplo n.º 20
0
 ///<summary>
 /// Gets all the Discount curve name.
 ///</summary>
 ///<returns></returns>
 public static string GetForecastCurveName(FloatingRateIndex floatingRateIndex, Period[] periods)
 {
     return(GetForecastCurveName(PricingStructureTypeEnum.RateCurve, floatingRateIndex, periods));
 }
 public static FloatingRateDefinition CreateSimple(FloatingRateIndex floatingRateIndex, Period tenor, DateTime adjustedFixingDate,
                                                   decimal observedRate, decimal spread)
 {
     return(CreateSimple(adjustedFixingDate, observedRate, spread));
 }
Exemplo n.º 22
0
 ///<summary>
 /// Gets all the Forecast curve name.
 ///</summary>
 ///<returns></returns>
 private static string GetForecastCurveName(PricingStructureTypeEnum curveType, FloatingRateIndex floatingRateIndex, Period[] periods)
 {
     return(curveType + "." + floatingRateIndex.Value + "-" + periods[0].ToString());
 }
Exemplo n.º 23
0
 ///<summary>
 /// Gets all the Forecast curve name.
 ///</summary>
 ///<returns></returns>
 private static string GetForecastCurveName(PricingStructureTypeEnum curveType, FloatingRateIndex floatingRateIndex)
 {
     return(curveType + "." + floatingRateIndex.Value);
 }
Exemplo n.º 24
0
        ///<summary>
        /// Gets all the Forecast curve name.
        ///</summary>
        ///<returns></returns>
        public static string GetRateVolatilityMatrixName(FloatingRateIndex floatingRateIndex, Period indexTenor)
        {
            var result = GetRateVolatilityMatrixName(floatingRateIndex, new[] { indexTenor });

            return(result);
        }
Exemplo n.º 25
0
        ///<summary>
        /// Gets all the Forecast curve name.
        ///</summary>
        ///<returns></returns>
        public static string GetForecastCurveName(FloatingRateIndex floatingRateIndex, Period indexTenor)
        {
            string result = indexTenor != null?GetForecastCurveName(floatingRateIndex, new[] { indexTenor }) : GetForecastCurveName(PricingStructureTypeEnum.RateCurve, floatingRateIndex);

            return(result);
        }