Beispiel #1
0
        public static Either <Error, Maturity> GetMaturity(this Tenor tenor)
        {
            var multiplier = (tenor.ToString()[0]) switch
            {
                'M' => 1D / 12,
                _ => 1,
            };
            var right = int.Parse(tenor.ToString().Substring(1));

            return(Maturity.TryCreate(right * multiplier));
        }
        // writes the rows for a single CurrencyParameterSensitivity
        private void write(string reference, CurveSensitivitiesType type, CurveSensitivities curveSens, CurrencyParameterSensitivity paramSens, IList <string> additionalHeaders, bool containsDates, CsvOutput csv)
        {
            IList <string> additionalCells = supplier.values(additionalHeaders, curveSens, paramSens);

            for (int i = 0; i < paramSens.ParameterCount; i++)
            {
                ParameterMetadata pmd   = paramSens.getParameterMetadata(i);
                Tenor             tenor = ((TenoredParameterMetadata)pmd).Tenor;
                double            value = paramSens.Sensitivity.get(i);
                csv.writeCell(reference);
                csv.writeCell(type.Name);
                csv.writeCell(tenor.ToString());
                if (containsDates)
                {
                    csv.writeCell(pmd is DatedParameterMetadata ? ((DatedParameterMetadata)pmd).Date.ToString() : "");
                }
                csv.writeCell(paramSens.Currency.Code);
                csv.writeCell(decimal.valueOf(value).toPlainString());
                csv.writeLine(additionalCells);
            }
        }
Beispiel #3
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains an instance using the tenor.
 /// </summary>
 /// <param name="date">  the date associated with the parameter </param>
 /// <param name="tenor">  the tenor associated with the parameter </param>
 /// <returns> the parameter metadata based on the tenor </returns>
 public static TenorDateParameterMetadata of(LocalDate date, Tenor tenor)
 {
     ArgChecker.notNull(date, "date");
     ArgChecker.notNull(tenor, "tenor");
     return(new TenorDateParameterMetadata(date, tenor, tenor.ToString()));
 }
Beispiel #4
0
        public virtual void test_swapIndicies()
        {
            ImmutableMap <string, SwapIndex> mapAll   = SwapIndices.ENUM_LOOKUP.lookupAll();
            ImmutableList <SwapIndex>        indexAll = mapAll.values().asList();
            ImmutableList <string>           nameAll  = mapAll.Keys.asList();
            int size = indexAll.size();

            for (int i = 0; i < size; ++i)
            {
                // check no duplication
                for (int j = i + 1; j < size; ++j)
                {
                    assertFalse(nameAll.get(i).Equals(nameAll.get(j)));
                    assertFalse(indexAll.get(i).Equals(indexAll.get(j)));
                }
            }
            foreach (string name in nameAll)
            {
                SwapIndex index = mapAll.get(name);
                assertEquals(SwapIndex.of(name), index);
                assertEquals(index.Active, true);
                FixedIborSwapTemplate   temp = index.Template;
                FixedIborSwapConvention conv = temp.Convention;
                Tenor     tenor = temp.Tenor;
                LocalTime time  = index.FixingTime;
                ZoneId    zone  = index.FixingZone;
                // test consistency between name and template
                assertTrue(name.Contains(tenor.ToString()));
                if (name.StartsWith("USD", StringComparison.Ordinal))
                {
                    assertTrue(name.Contains("1100") || name.Contains("1500"));
                    assertTrue(conv.Equals(FixedIborSwapConventions.USD_FIXED_6M_LIBOR_3M));
                    assertTrue(zone.Equals(NEY_YORK));
                }
                if (name.StartsWith("GBP", StringComparison.Ordinal))
                {
                    assertTrue(name.Contains("1100"));
                    if (tenor.Equals(Tenor.TENOR_1Y))
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.GBP_FIXED_1Y_LIBOR_3M));
                    }
                    else
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.GBP_FIXED_6M_LIBOR_6M));
                    }
                    assertTrue(zone.Equals(LONDON));
                }
                if (name.StartsWith("EUR", StringComparison.Ordinal))
                {
                    assertTrue(name.Contains("1100") || name.Contains("1200"));
                    if (tenor.Equals(Tenor.TENOR_1Y))
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.EUR_FIXED_1Y_EURIBOR_3M));
                    }
                    else
                    {
                        assertTrue(conv.Equals(FixedIborSwapConventions.EUR_FIXED_1Y_EURIBOR_6M));
                    }
                    assertTrue(zone.Equals(FRANKFURT));
                }
                if (name.Contains("1100"))
                {
                    assertTrue(time.Equals(LocalTime.of(11, 0)));
                }
                if (name.Contains("1200"))
                {
                    assertTrue(time.Equals(LocalTime.of(12, 0)));
                }
                if (name.Contains("1500"))
                {
                    assertTrue(time.Equals(LocalTime.of(15, 0)));
                }
                assertEquals(index.calculateFixingDateTime(date(2015, 6, 30)), date(2015, 6, 30).atTime(time).atZone(zone));
            }
        }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains an instance using the tenor.
 /// </summary>
 /// <param name="tenor">  the tenor associated with the parameter </param>
 /// <returns> the parameter metadata based on the tenor </returns>
 public static TenorParameterMetadata of(Tenor tenor)
 {
     ArgChecker.notNull(tenor, "tenor");
     return(new TenorParameterMetadata(tenor, tenor.ToString()));
 }