Beispiel #1
0
        public static double DFFromRate(
            [QuantSAExcelArgument(Description = "The rate to use in finding the discount factor.")]
            double rate,
            [QuantSAExcelArgument(Description = "The compounding convention of the input rate.")]
            CompoundingConvention compounding,
            [QuantSAExcelArgument(Description = "The year fraction over which the rate applies.")]
            double yearFraction)

        {
            return(compounding.DF(rate, yearFraction));
        }
Beispiel #2
0
        public void SingleInstance()
        {
            CompoundingConvention annual1 = CompoundingStore.Annual;
            CompoundingConvention annual2 = CompoundingStore.Annual;

            Assert.IsTrue(annual1 == annual2);

            CompoundingConvention cont1 = CompoundingStore.Continuous;
            CompoundingConvention cont2 = CompoundingStore.Continuous;

            Assert.IsTrue(cont1 == cont2);
        }
Beispiel #3
0
        public static double RateConvert([QuantSAExcelArgument(Description = "The rate to convert.")]
                                         double rate,
                                         [QuantSAExcelArgument(Description = "The compounding convention of the input rate.")]
                                         CompoundingConvention compoundingFrom,
                                         [QuantSAExcelArgument(Description = "The compounding convention that the output rate should be in.")]
                                         CompoundingConvention compoundingTo,
                                         [QuantSAExcelArgument(
                                              Description =
                                                  "(Optional) The yearfraction over which the rate applies.  Only required if one of the conventions is 'Simple' or 'Discount'",
                                              Default = "double.NaN")]
                                         double yearFraction)

        {
            if (compoundingFrom == CompoundingStore.Simple && double.IsNaN(yearFraction))
            {
                throw new ArgumentException(
                          "Cannot convert from a 'Simple' convention without the year fraction being specified.");
            }
            if (compoundingFrom == CompoundingStore.Discount && double.IsNaN(yearFraction))
            {
                throw new ArgumentException(
                          "Cannot convert from a 'Discount' convention without the year fraction being specified.");
            }
            if (compoundingTo == CompoundingStore.Simple && double.IsNaN(yearFraction))
            {
                throw new ArgumentException(
                          "Cannot convert from a 'Simple' convention without the year fraction being specified.");
            }
            if (compoundingTo == CompoundingStore.Discount && double.IsNaN(yearFraction))
            {
                throw new ArgumentException(
                          "Cannot convert to a 'Discount' convention without the year fraction being specified.");
            }

            if (double.IsNaN(yearFraction))
            {
                yearFraction = 1.0;
            }
            var df         = compoundingFrom.DF(rate, yearFraction);
            var resultRate = compoundingTo.rateFromDF(df, yearFraction);

            return(resultRate);
        }