//-------------------------------------------------------------------------
 // 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));
     }
 }
Esempio n. 2
0
 // for historical compatibility, we determine known format by looking for these specific things
 // the new approach is to require either the 'Reference' or the 'Sensitivity Type' column
 private static bool knownReference(string refStr)
 {
     try
     {
         Optional <IborIndex> ibor = IborIndex.extendedEnum().find(refStr);
         if (ibor.Present)
         {
             return(true);
         }
         else
         {
             Optional <FloatingRateName> frName = FloatingRateName.extendedEnum().find(refStr);
             if (frName.Present)
             {
                 return(true);
             }
             else if (refStr.Length == 3)
             {
                 Currency.of(refStr);   // this may throw an exception validating the string
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 3
0
 //-------------------------------------------------------------------------
 public virtual void test_normalized()
 {
     assertEquals(FloatingRateName.of("GBP-LIBOR-BBA").normalized(), FloatingRateName.of("GBP-LIBOR"));
     assertEquals(FloatingRateName.of("GBP-WMBA-SONIA-COMPOUND").normalized(), FloatingRateName.of("GBP-SONIA"));
     foreach (FloatingRateName name in FloatingRateName.extendedEnum().lookupAll().values())
     {
         assertNotNull(name.normalized());
     }
 }
Esempio n. 4
0
        //-------------------------------------------------------------------------
        // parses the currency as a column or from the reference
        private static Currency parseCurrency(CsvRow row, CurveName reference)
        {
            Optional <string> currencyStr = row.findValue(CURRENCY_HEADER);

            if (currencyStr.Present)
            {
                return(LoaderUtils.parseCurrency(currencyStr.get()));
            }
            string referenceStr = reference.Name.ToUpper(Locale.ENGLISH);

            try
            {
                Optional <IborIndex> ibor = IborIndex.extendedEnum().find(referenceStr);
                if (ibor.Present)
                {
                    return(ibor.get().Currency);
                }
                else
                {
                    Optional <FloatingRateName> frName = FloatingRateName.extendedEnum().find(referenceStr);
                    if (frName.Present)
                    {
                        return(frName.get().Currency);
                    }
                    else if (referenceStr.Length == 3)
                    {
                        return(Currency.of(referenceStr));
                    }
                    else if (referenceStr.Length > 3 && referenceStr[3] == '-' || referenceStr[3] == '_')
                    {
                        return(LoaderUtils.parseCurrency(referenceStr.Substring(0, 3)));
                    }
                    else
                    {
                        // drop out to exception
                    }
                }
            }
            catch (Exception)
            {
                // drop out to exception
            }
            throw new System.ArgumentException("Unable to parse currency from reference, consider adding a 'Currency' column");
        }