Пример #1
0
            public override Builder set(string propertyName, object newValue)
            {
                switch (propertyName.GetHashCode())
                {
                case 1905311443:         // dayCount
                    this.dayCount_Renamed = (DayCount)newValue;
                    break;

                case 3493088:         // rate
                    this.rate_Renamed = (ValueSchedule)newValue;
                    break;

                case 1233359378:         // initialStub
                    this.initialStub_Renamed = (FixedRateStubCalculation)newValue;
                    break;

                case 355242820:         // finalStub
                    this.finalStub_Renamed = (FixedRateStubCalculation)newValue;
                    break;

                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
                }
                return(this);
            }
Пример #2
0
 /// <summary>
 /// Restricted copy constructor. </summary>
 /// <param name="beanToCopy">  the bean to copy from, not null </param>
 internal Builder(FixedRateCalculation beanToCopy)
 {
     this.dayCount_Renamed    = beanToCopy.DayCount;
     this.rate_Renamed        = beanToCopy.Rate;
     this.initialStub_Renamed = beanToCopy.initialStub;
     this.finalStub_Renamed   = beanToCopy.finalStub;
 }
Пример #3
0
        public ImmutableList <RateAccrualPeriod> createAccrualPeriods(Schedule accrualSchedule, Schedule paymentSchedule, ReferenceData refData)
        {
            // avoid null stub definitions if there are stubs
            FixedRateStubCalculation  initialStub         = firstNonNull(this.initialStub, FixedRateStubCalculation.NONE);
            FixedRateStubCalculation  finalStub           = firstNonNull(this.finalStub, FixedRateStubCalculation.NONE);
            Optional <SchedulePeriod> scheduleInitialStub = accrualSchedule.InitialStub;
            Optional <SchedulePeriod> scheduleFinalStub   = accrualSchedule.FinalStub;
            // resolve data by schedule
            DoubleArray resolvedRates = rate.resolveValues(accrualSchedule);

            // build accrual periods
            ImmutableList.Builder <RateAccrualPeriod> accrualPeriods = ImmutableList.builder();
            for (int i = 0; i < accrualSchedule.size(); i++)
            {
                SchedulePeriod period       = accrualSchedule.getPeriod(i);
                double         yearFraction = period.yearFraction(dayCount, accrualSchedule);
                // handle stubs
                RateComputation rateComputation;
                if (scheduleInitialStub.Present && scheduleInitialStub.get() == period)
                {
                    rateComputation = initialStub.createRateComputation(resolvedRates.get(i));
                }
                else if (scheduleFinalStub.Present && scheduleFinalStub.get() == period)
                {
                    rateComputation = finalStub.createRateComputation(resolvedRates.get(i));
                }
                else
                {
                    rateComputation = FixedRateComputation.of(resolvedRates.get(i));
                }
                accrualPeriods.add(new RateAccrualPeriod(period, yearFraction, rateComputation));
            }
            return(accrualPeriods.build());
        }
Пример #4
0
 private FixedRateCalculation(DayCount dayCount, ValueSchedule rate, FixedRateStubCalculation initialStub, FixedRateStubCalculation finalStub)
 {
     JodaBeanUtils.notNull(dayCount, "dayCount");
     JodaBeanUtils.notNull(rate, "rate");
     this.dayCount    = dayCount;
     this.rate        = rate;
     this.initialStub = initialStub;
     this.finalStub   = finalStub;
 }
        public virtual void test_ofKnownAmount()
        {
            FixedRateStubCalculation test = FixedRateStubCalculation.ofKnownAmount(GBP_P1000);

            assertEquals(test.FixedRate, double?.empty());
            assertEquals(test.KnownAmount, GBP_P1000);
            assertEquals(test.FixedRate, false);
            assertEquals(test.KnownAmount, true);
        }
        public virtual void test_builder()
        {
            FixedRateCalculation test = FixedRateCalculation.builder().dayCount(ACT_365F).rate(ValueSchedule.of(0.025d)).initialStub(FixedRateStubCalculation.ofFixedRate(0.1d)).finalStub(FixedRateStubCalculation.ofFixedRate(0.2d)).build();

            assertEquals(test.Rate, ValueSchedule.of(0.025d));
            assertEquals(test.DayCount, ACT_365F);
            assertEquals(test.InitialStub, FixedRateStubCalculation.ofFixedRate(0.1d));
            assertEquals(test.FinalStub, FixedRateStubCalculation.ofFixedRate(0.2d));
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            FixedRateStubCalculation test = FixedRateStubCalculation.ofFixedRate(0.025d);

            coverImmutableBean(test);
            FixedRateStubCalculation test2 = FixedRateStubCalculation.ofKnownAmount(GBP_P1000);

            coverBeanEquals(test, test2);
        }
        //-------------------------------------------------------------------------
        public virtual void test_ofFixedRate()
        {
            FixedRateStubCalculation test = FixedRateStubCalculation.ofFixedRate(0.025d);

            assertEquals(test.FixedRate, double?.of(0.025d));
            assertEquals(test.KnownAmount, null);
            assertEquals(test.FixedRate, true);
            assertEquals(test.KnownAmount, false);
        }
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         FixedRateStubCalculation other = (FixedRateStubCalculation)obj;
         return(JodaBeanUtils.equal(fixedRate, other.fixedRate) && JodaBeanUtils.equal(knownAmount, other.knownAmount));
     }
     return(false);
 }
        public virtual void test_resolve_knownAmountStub()
        {
            // test case
            CurrencyAmount         knownAmount = CurrencyAmount.of(GBP, 150d);
            RateCalculationSwapLeg test        = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_02_03).endDate(DATE_04_03).firstRegularStartDate(DATE_02_05).lastRegularEndDate(DATE_03_05).frequency(P1M).stubConvention(StubConvention.BOTH).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_TWO_DAYS).build()).notionalSchedule(NotionalSchedule.of(GBP, 1000d)).calculation(FixedRateCalculation.builder().dayCount(ACT_365F).rate(ValueSchedule.of(0.025d)).initialStub(FixedRateStubCalculation.ofKnownAmount(knownAmount)).finalStub(FixedRateStubCalculation.ofFixedRate(0.1d)).build()).build();
            // expected
            KnownAmountNotionalSwapPaymentPeriod pp1 = KnownAmountNotionalSwapPaymentPeriod.builder().payment(Payment.of(knownAmount, DATE_02_07)).startDate(DATE_02_03).endDate(DATE_02_05).unadjustedStartDate(DATE_02_03).notionalAmount(CurrencyAmount.of(GBP, -1000d)).build();
            RatePaymentPeriod rpp2 = RatePaymentPeriod.builder().paymentDate(DATE_03_07).accrualPeriods(RateAccrualPeriod.builder().startDate(DATE_02_05).endDate(DATE_03_05).yearFraction(ACT_365F.yearFraction(DATE_02_05, DATE_03_05)).rateComputation(FixedRateComputation.of(0.025d)).build()).dayCount(ACT_365F).currency(GBP).notional(-1000d).build();
            RatePaymentPeriod rpp3 = RatePaymentPeriod.builder().paymentDate(DATE_04_07).accrualPeriods(RateAccrualPeriod.builder().startDate(DATE_03_05).endDate(DATE_04_03).unadjustedEndDate(DATE_04_03).yearFraction(ACT_365F.yearFraction(DATE_03_05, DATE_04_03)).rateComputation(FixedRateComputation.of(0.1d)).build()).dayCount(ACT_365F).currency(GBP).notional(-1000d).build();

            // assertion
            assertEquals(test.resolve(REF_DATA), ResolvedSwapLeg.builder().type(FIXED).payReceive(PAY).paymentPeriods(pp1, rpp2, rpp3).build());
        }
        public virtual void test_serialization()
        {
            FixedRateStubCalculation test = FixedRateStubCalculation.ofFixedRate(0.025d);

            assertSerialization(test);
        }
        public virtual void test_createRateComputation_knownAmount()
        {
            FixedRateStubCalculation test = FixedRateStubCalculation.ofKnownAmount(GBP_P1000);

            assertEquals(test.createRateComputation(3d), KnownAmountRateComputation.of(GBP_P1000));
        }
        public virtual void test_createRateComputation_fixedRate()
        {
            FixedRateStubCalculation test = FixedRateStubCalculation.ofFixedRate(0.025d);

            assertEquals(test.createRateComputation(3d), FixedRateComputation.of(0.025d));
        }
        //-------------------------------------------------------------------------
        public virtual void test_createRateComputation_NONE()
        {
            FixedRateStubCalculation test = FixedRateStubCalculation.NONE;

            assertEquals(test.createRateComputation(3d), FixedRateComputation.of(3d));
        }
 //-------------------------------------------------------------------------
 public virtual void test_builder_invalid_fixedAndKnown()
 {
     assertThrowsIllegalArg(() => FixedRateStubCalculation.meta().builder().set(FixedRateStubCalculation.meta().fixedRate(), 0.025d).set(FixedRateStubCalculation.meta().knownAmount(), GBP_P1000).build());
 }
Пример #16
0
 /// <summary>
 /// Sets the initial stub, optional.
 /// <para>
 /// The initial stub of a swap may have a different rate from the regular accrual periods.
 /// This property allows the stub rate to be specified, either as a known amount or a rate.
 /// If this property is not present, then the rate derived from the {@code rate} property applies during the stub.
 /// If this property is present and there is no initial stub, it is ignored.
 /// </para>
 /// </summary>
 /// <param name="initialStub">  the new value </param>
 /// <returns> this, for chaining, not null </returns>
 public Builder initialStub(FixedRateStubCalculation initialStub)
 {
     this.initialStub_Renamed = initialStub;
     return(this);
 }
Пример #17
0
 /// <summary>
 /// Sets the final stub, optional.
 /// <para>
 /// The final stub of a swap may have a different rate from the regular accrual periods.
 /// This property allows the stub rate to be specified, either as a known amount or a rate.
 /// If this property is not present, then the rate derived from the {@code rate} property applies during the stub.
 /// If this property is present and there is no initial stub, it is ignored.
 /// </para>
 /// </summary>
 /// <param name="finalStub">  the new value </param>
 /// <returns> this, for chaining, not null </returns>
 public Builder finalStub(FixedRateStubCalculation finalStub)
 {
     this.finalStub_Renamed = finalStub;
     return(this);
 }