public static void SetSpread(PaymentCalculationPeriod paymentCalculationPeriod, decimal value)
 {
     foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriodCalculationPeriodArray(paymentCalculationPeriod))
     {
         if (XsdClassesFieldResolver.CalculationPeriodHasFloatingRateDefinition(calculationPeriod))
         {
             FloatingRateDefinition floatingRateDefinition = XsdClassesFieldResolver.CalculationPeriodGetFloatingRateDefinition(calculationPeriod);
             floatingRateDefinition.spread          = value;
             floatingRateDefinition.spreadSpecified = true;
         }
         else
         {
             throw new NotImplementedException("PaymentCalculationPeriodHelper.SetSpread cannot be called on a fixed rate cashflow.");
         }
     }
 }
 public static void SetRate(PaymentCalculationPeriod paymentCalculationPeriod, decimal rate)
 {
     foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriodCalculationPeriodArray(paymentCalculationPeriod))
     {
         if (XsdClassesFieldResolver.CalculationPeriodHasFixedRate(calculationPeriod))
         {
             XsdClassesFieldResolver.SetCalculationPeriodFixedRate(calculationPeriod, rate);
         }
         else if (XsdClassesFieldResolver.CalculationPeriodHasFloatingRateDefinition(calculationPeriod))
         {
             throw new NotImplementedException("Cannot modify floating rate, PaymentCalculationPeriodHelper.SetRate");
             //XsdClassesFieldResolver.CalculationPeriod_GetFloatingRateDefinition(calculationPeriod).calculatedRate;
         }
         else
         {
             throw new NotImplementedException("PaymentCalculationPeriodHelper.SetRate");
         }
     }
 }
 public static void ReplaceFloatingRateWithFixedRate(PaymentCalculationPeriod paymentCalculationPeriod, decimal fixedRate)
 {
     foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriodCalculationPeriodArray(paymentCalculationPeriod))
     {
         if (XsdClassesFieldResolver.CalculationPeriodHasFixedRate(calculationPeriod))
         {
             throw new System.Exception("calculation period already uses a fixed rate.");
         }
         if (XsdClassesFieldResolver.CalculationPeriodHasFloatingRateDefinition(calculationPeriod))
         {
             // Replace FloatingRateDefinition with decimal (fixed rate)
             //
             XsdClassesFieldResolver.SetCalculationPeriodFixedRate(calculationPeriod, fixedRate);
         }
         else
         {
             throw new NotSupportedException("PaymentCalculationPeriodHelper.ReplaceFloatingRateWithFixedRate");
         }
     }
 }
        public static decimal GetSpread(PaymentCalculationPeriod paymentCalculationPeriod)
        {
            decimal result          = 0.0m;
            decimal numberOfPeriods = 0.0m;

            foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriodCalculationPeriodArray(paymentCalculationPeriod))
            {
                if (XsdClassesFieldResolver.CalculationPeriodHasFloatingRateDefinition(calculationPeriod))
                {
                    FloatingRateDefinition floatingRateDefinition = XsdClassesFieldResolver.CalculationPeriodGetFloatingRateDefinition(calculationPeriod);
                    result += floatingRateDefinition.spread;
                }
                else
                {
                    throw new NotImplementedException("PaymentCalculationPeriodHelper.GetSpread cannot be called on fixed rate cashflow.");
                }
                numberOfPeriods += 1;
            }
            return(result / numberOfPeriods);
        }
        public static decimal GetRate(PaymentCalculationPeriod paymentCalculationPeriod)
        {
            decimal result          = 0.0m;
            decimal numberOfPeriods = 0.0m;

            foreach (CalculationPeriod calculationPeriod in XsdClassesFieldResolver.GetPaymentCalculationPeriodCalculationPeriodArray(paymentCalculationPeriod))
            {
                if (XsdClassesFieldResolver.CalculationPeriodHasFixedRate(calculationPeriod))
                {
                    result += XsdClassesFieldResolver.CalculationPeriodGetFixedRate(calculationPeriod);
                }
                else if (XsdClassesFieldResolver.CalculationPeriodHasFloatingRateDefinition(calculationPeriod))
                {
                    result += XsdClassesFieldResolver.CalculationPeriodGetFloatingRateDefinition(calculationPeriod).calculatedRate;
                }
                else
                {
                    throw new NotImplementedException("PaymentCalculationPeriodHelper.GetRate");
                }
                numberOfPeriods += 1;
            }
            return(result / numberOfPeriods);
        }