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.")] ICompoundingConvention compounding, [QuantSAExcelArgument(Description = "The year fraction over which the rate applies.")] double yearFraction) { return(compounding.DfFromRate(rate, yearFraction)); }
public void SingleInstance() { ICompoundingConvention annual1 = CompoundingStore.Annual; ICompoundingConvention annual2 = CompoundingStore.Annual; Assert.IsTrue(annual1 == annual2); ICompoundingConvention cont1 = CompoundingStore.Continuous; ICompoundingConvention cont2 = CompoundingStore.Continuous; Assert.IsTrue(cont1 == cont2); }
public static double RateConvert([QuantSAExcelArgument(Description = "The rate to convert.")] double rate, [QuantSAExcelArgument(Description = "The compounding convention of the input rate.")] ICompoundingConvention compoundingFrom, [QuantSAExcelArgument(Description = "The compounding convention that the output rate should be in.")] ICompoundingConvention compoundingTo, [QuantSAExcelArgument( Description = "(Optional) The yearfraction over which the rate applies. Only required if one of the conventions is 'Simple' or 'Discount'", Default = null)] 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.DfFromRate(rate, yearFraction); var resultRate = compoundingTo.RateFromDf(df, yearFraction); return(resultRate); }