Package org.jquantlib.time

Examples of org.jquantlib.time.Calendar


    }


    @Test
    public void testSchedule() {
        final Calendar calendar = new Target();
        final Period maturity = new Period(30, TimeUnit.Years);
        final Date maturityDate = startDate.add(maturity);
        final Period accPeriodTenor = new Period(6, TimeUnit.Months);
        final BusinessDayConvention modFollow = BusinessDayConvention.ModifiedFollowing;
        final DateGeneration.Rule dateRule = DateGeneration.Rule.Backward;

        final Schedule firstConstrSchedule = new Schedule(
                startDate, maturityDate, accPeriodTenor,
                calendar, modFollow, modFollow,
                dateRule, false, null, null);

        final List<Date> dates = new ArrayList<Date>();
        dates.add(startDate);
        dates.add(calendar.advance(startDate, new Period(10, TimeUnit.Weeks),modFollow));

        final Schedule secondConstrSchedule = new Schedule(dates, calendar, modFollow);

        testDateAfter(firstConstrSchedule);
        testDateAfter(secondConstrSchedule);
View Full Code Here


        //           "neither European nor American option"); // TODO: message

        final DayCounter rfdc  = process.riskFreeRate().currentLink().dayCounter();
        final DayCounter divdc = process.dividendYield().currentLink().dayCounter();
        final DayCounter voldc = process.blackVolatility().currentLink().dayCounter();
        final Calendar volcal  = process.blackVolatility().currentLink().calendar();

        final double s0 = process.stateVariable().currentLink().value();
        QL.require(s0 > 0.0 , "negative or null underlying given"); // QA:[RG]::verified // TODO: message
        final double v = process.blackVolatility().currentLink().blackVol(a.exercise.lastDate(), s0);
        final Date maturityDate = a.exercise.lastDate();
View Full Code Here

            QL.require(floors.size() <= n   , "too many floors"); // TODO: message
        }
        QL.require(!isZero || !isInArrears , "features in-arrears and zero are not compatible"); // TODO: message

        // the following is not always correct (original C++ comment)
        final Calendar calendar = schedule.calendar();

        Date refStart, start, refEnd, end;
        final Date lastPaymentDate = calendar.adjust(schedule.date(n), paymentAdj);

        for (int i = 0; i < n; i++) {
            refStart = start = schedule.date(i);
            refEnd   =   end = schedule.date(i+1);
            final Date paymentDate = isZero ? lastPaymentDate : calendar.adjust(end, paymentAdj);

            if (i == 0 && !schedule.isRegular(i + 1)) {
                refStart = calendar.adjust(end.sub(schedule.tenor()), paymentAdj);
            }
            if (i == n - 1 && !schedule.isRegular(i + 1)) {
                refEnd = calendar.adjust(start.add(schedule.tenor()), paymentAdj);
            }
            if (Detail.get(gearings, i, 1.0) == 0.0) {
                add(new FixedRateCoupon(
                        Detail.get(nominals, i, 1.0),
                        paymentDate,
View Full Code Here

        // dummy strike
        final double /* @Real */variance = process.blackVolatility().currentLink().blackVariance(A.exercise.lastDate(), 1.0);

        final DayCounter voldc = process.blackVolatility().currentLink().dayCounter();
        final Calendar volcal = process.blackVolatility().currentLink().calendar();
        final Date volRefDate = process.blackVolatility().currentLink().referenceDate();
        final double /* @Time */t = voldc.yearFraction(volRefDate, A.exercise.lastDate());
        final double /* @Rate */riskFreeRate = -Math.log(process.riskFreeRate().currentLink().discount(A.exercise.lastDate())) / t;
        final Date rateRefDate = process.riskFreeRate().currentLink().referenceDate();

View Full Code Here

        QL.require(notionals_   != null && notionals_.length>0 , "nominals not specified"); // QA:[RG]::verified // TODO: message

        final Leg leg = new Leg();

        // the following is not always correct
        final Calendar calendar = schedule_.calendar();

        // first period might be short or long
        Date start = schedule_.date(0), end = schedule_.date(1);
        Date paymentDate = calendar.adjust(end, paymentAdjustment_);
        InterestRate rate = couponRates_[0];
        /*@Real*/ double nominal = notionals_[0];
        if (schedule_.isRegular(1)) {
            // TODO: code review :: please verify against QL/C++ code
            QL.require(firstPeriodDayCounter_==null || !firstPeriodDayCounter_.equals(paymentDayCounter_) , "regular first coupon does not allow a first-period day count"); // QA:[RG]::verified // TODO: message
            leg.add(new FixedRateCoupon(nominal, paymentDate, rate, paymentDayCounter_, start, end, start, end));
        } else {
            Date ref = end.sub(schedule_.tenor());
            ref = calendar.adjust(ref, schedule_.businessDayConvention());
            // FIXME: empty() method on dayCounter missing --> substituted by == null (probably incorrect)
            final DayCounter dc = (firstPeriodDayCounter_ == null) ? paymentDayCounter_ : firstPeriodDayCounter_;
            leg.add(new FixedRateCoupon(nominal, paymentDate, rate, dc, start, end, ref, end));
        }
        // regular periods
        for (int i = 2; i < schedule_.size() - 1; ++i) {
            start = end;
            end = schedule_.date(i);
            paymentDate = calendar.adjust(end, paymentAdjustment_);
            if ((i - 1) < couponRates_.length) {
                rate = couponRates_[i - 1];
            } else {
                rate = couponRates_[couponRates_.length - 1];
            }
            if ((i - 1) < notionals_.length) {
                nominal = notionals_[i - 1];
            } else {
                nominal = notionals_[notionals_.length - 1];
            }
            leg.add(new FixedRateCoupon(nominal, paymentDate, rate, paymentDayCounter_, start, end, start, end));
        }

        if (schedule_.size() > 2) {
            // last period might be short or long
            final int N = schedule_.size();
            start = end;
            end = schedule_.date(N - 1);
            paymentDate = calendar.adjust(end, paymentAdjustment_);
            if ((N - 2) < couponRates_.length) {
                rate = couponRates_[N - 2];
            } else {
                rate = couponRates_[couponRates_.length - 1];
            }
            if ((N - 2) < notionals_.length) {
                nominal = notionals_[N - 2];
            } else {
                nominal = notionals_[notionals_.length - 1];
            }
            if (schedule_.isRegular(N - 1)) {
                leg.add(new FixedRateCoupon(nominal, paymentDate, rate, paymentDayCounter_, start, end, start, end));
            } else {
                Date ref = start.add(schedule_.tenor());
                ref = calendar.adjust(ref, schedule_.businessDayConvention());
                leg.add(new FixedRateCoupon(nominal, paymentDate, rate, paymentDayCounter_, start, end, start, ref));
            }
        }
        return leg;
    }
View Full Code Here

        QL.require(!this.notionals.empty(), "no notional given");

        Leg cashflows = new Leg();

        // the following is not always correct
        Calendar calendar = schedule.calendar();

        Date refStart, start, refEnd, end;
        Date paymentDate;

        int n = schedule.size()-1;
         
        for (int i=0; i<n ; i++) {
          refStart = schedule.date(i);
          start = schedule.date(i);
         
          refEnd = schedule.date(i+1);
          end = schedule.date(i+1);
          paymentDate = calendar.adjust(end, paymentAdjustment);
         
          if (i == 0 && !schedule.isRegular(i+1)) {
            refStart = calendar.adjust(end.sub(schedule.tenor()),
                                   paymentAdjustment);
          }

          if (i == n-1 && !schedule.isRegular(i+1))
            refEnd = calendar.adjust(start.add(schedule.tenor()),
                                        paymentAdjustment);
         
          AverageBMACoupon coupon = new AverageBMACoupon(paymentDate,
                                  notionals.get(i) != 0.0 ? notionals.get(i):notionals.last(),
                                  start,
View Full Code Here

        // Thanksgiving Day, fourth Thursday in November
        expectedHol.add(new Date(25, November, year));
        // Christmas, December 25th (moved to Monday if Sunday or Friday if Saturday)

        // Call the Holiday Check
        final Calendar nerc = new UnitedStates(UnitedStates.Market.NERC);
        final CalendarUtil cbt = new CalendarUtil();
        cbt.checkHolidayList(expectedHol, nerc, year);
    }
View Full Code Here

        // Christmas, December 25th (moved to Monday if Sunday or Friday if Saturday)
        expectedHol.add(new Date(24, December, year));
        expectedHol.add(new Date(25, December, year));

        // Call the Holiday Check
        final Calendar settlement = new UnitedStates(UnitedStates.Market.SETTLEMENT);
        final CalendarUtil cbt = new CalendarUtil();
        cbt.checkHolidayList(expectedHol, settlement, year);
    }
View Full Code Here

        expectedHol.add(new Date(24, November, year));
        // Christmas, December 25th (moved to Monday if Sunday or Friday if Saturday)
        expectedHol.add(new Date(26, December, year));

        // Call the Holiday Check
        final Calendar settlement = new UnitedStates(UnitedStates.Market.SETTLEMENT);
        final CalendarUtil cbt = new CalendarUtil();
        cbt.checkHolidayList(expectedHol, settlement, year);
    }
View Full Code Here

        // Christmas, December 25th (moved to Monday if Sunday or Friday if Saturday)
        //expectedHol.add(new Date(24,DECEMBER,year));
        expectedHol.add(new Date(25, December, year));

        // Call the Holiday Check
        final Calendar settlement = new UnitedStates(UnitedStates.Market.SETTLEMENT);
        final CalendarUtil cbt = new CalendarUtil();
        cbt.checkHolidayList(expectedHol, settlement, year);
    }
View Full Code Here

TOP

Related Classes of org.jquantlib.time.Calendar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.