Package org.jquantlib.time

Examples of org.jquantlib.time.Period


    public MakeVanillaSwap (
            final Period swapTenor,
            final IborIndex index,
            final /*Rate*/ double fixedRate) {
        this(swapTenor, index, fixedRate, new Period(0,TimeUnit.Days));
    }
View Full Code Here


        //FIXME : JM port from quantlib :: code review :: effectiveDate_ = Date.maxDate();
        fixedCalendar_ = (index.fixingCalendar());
        floatCalendar_ = (index.fixingCalendar());
        type_ = (VanillaSwap.Type.Payer);
        nominal_ = (1.0);
        fixedTenor_ = (new Period(1, TimeUnit.Years));
        floatTenor_ = (index.tenor());
        fixedConvention_ = (BusinessDayConvention.ModifiedFollowing);
        fixedTerminationDateConvention_ = (BusinessDayConvention.ModifiedFollowing);
        floatConvention_ = (index.businessDayConvention());
        floatTerminationDateConvention_ = (index.businessDayConvention());
View Full Code Here

                    final CashFlow coupon = cashflows.get(i);
                    if (coupon instanceof Coupon && coupon != null) {
                        // if (coupon)
                        lastDate = ((Coupon) coupon).accrualStartDate();
                    } else {
                        lastDate = couponDate.sub(new Period(1, TimeUnit.Years));
                    }
                }
                discount *= y.discountFactor(settlement, couponDate, lastDate,
                        couponDate);
            } else {
View Full Code Here

          rule + " DateGeneration::Rule");
    default:
      QL.error("unknown DateGeneration::Rule (" + rule + ")");
    }

    final Schedule schedule = new Schedule(startDate, maturityDate_, new Period(couponFrequency),
        calendar_, accrualConvention, accrualConvention,
        rule, endOfMonth,
        firstDate, nextToLastDate);

    cashflows_ = new IborLeg(schedule, index.currentLink())
View Full Code Here

                    // d1 < refPeriodStart < refPeriodEnd
                    // AND d2 <= refPeriodEnd
                    // this case is long first coupon

                    // the last notional payment date
                    final Date previousRef = refPeriodStart.add(new Period(
                            -months, TimeUnit.Months));
                    if (d2.gt(refPeriodStart))
                        return yearFraction(d1, refPeriodStart, previousRef,
                                refPeriodStart)
                                + yearFraction(refPeriodStart, d2,
                                        refPeriodStart, refPeriodEnd);
                    else
                        return yearFraction(d1, d2, previousRef,
                                refPeriodStart);
                }
            } else {
                // TODO: code review :: please verify against QL/C++ code

                // here refPeriodEnd is the last notional payment date
                // d1 < refPeriodEnd < d2 AND refPeriodStart < refPeriodEnd
                QL.require(refPeriodStart.le(d1) , "invalid dates"); // TODO: message

                // now it is: refPeriodStart <= d1 < refPeriodEnd < d2

                // the part from d1 to refPeriodEnd
                double sum = yearFraction(d1, refPeriodEnd, refPeriodStart, refPeriodEnd);

                // the part from refPeriodEnd to d2
                // count how many regular periods are in [refPeriodEnd, d2],
                // then add the remaining time
                int i = 0;
                Date newRefStart, newRefEnd;
                do {
                    newRefStart = refPeriodEnd.add(new Period(months * i, TimeUnit.Months));
                    newRefEnd = refPeriodEnd.add(new Period(months * (i + 1), TimeUnit.Months));
                    if (d2.lt(newRefEnd))
                        break;
                    else {
                        sum += period;
                        i++;
View Full Code Here


    @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

                    // d1 < refPeriodStart < refPeriodEnd
                    // AND d2 <= refPeriodEnd
                    // this case is long first coupon

                    // the last notional payment date
                    final Date previousRef = refPeriodStart.add(new Period(
                            -months, TimeUnit.Months));
                    if (d2.gt(refPeriodStart))
                        return yearFraction(d1, refPeriodStart, previousRef,
                                refPeriodStart)
                                + yearFraction(refPeriodStart, d2,
                                        refPeriodStart, refPeriodEnd);
                    else
                        return yearFraction(d1, d2, previousRef,
                                refPeriodStart);
                }
            } else {
                // TODO: code review :: please verify against QL/C++ code

                // here refPeriodEnd is the last notional payment date
                // d1 < refPeriodEnd < d2 AND refPeriodStart < refPeriodEnd
                QL.require(refPeriodStart.le(d1) , "invalid dates"); // TODO: message

                // now it is: refPeriodStart <= d1 < refPeriodEnd < d2

                // the part from d1 to refPeriodEnd
                double sum = yearFraction(d1, refPeriodEnd, refPeriodStart, refPeriodEnd);

                // the part from refPeriodEnd to d2
                // count how many regular periods are in [refPeriodEnd, d2],
                // then add the remaining time
                int i = 0;
                Date newRefStart, newRefEnd;
                do {
                    newRefStart = refPeriodEnd.add(new Period(months * i, TimeUnit.Months));
                    newRefEnd = refPeriodEnd.add(new Period(months * (i + 1), TimeUnit.Months));
                    if (d2.lt(newRefEnd))
                        break;
                    else {
                        sum += period;
                        i++;
View Full Code Here

      units = TimeUnit.YEARS;
      enforceUnit(index,str,units);
    }
   
    String length = str.substring(0, index).trim();
    return new Period(Integer.parseInt(length), units);
  }
View Full Code Here

        final int dayOfEndOfMonth = dateEndOfMonth.dayOfMonth();
        final Date dateStartOfMonth = dateEndOfMonth.add(-dayOfEndOfMonth+1);
        System.out.println("The first date of the month to which todays date belong to is = "+dateStartOfMonth);

        //Let's try getting the first date of the month to which today's date belong to using Period
        final Period period = new Period(-today.dayOfMonth()+1,TimeUnit.Days);
        Date dateStartOfMonthUsingPeriod = today.add(period);
        System.out.println("The first date of the month to which today's date belong to using period is = "+dateStartOfMonthUsingPeriod);

        //Let's use adjust function to get the same result as obtained above
        dateStartOfMonthUsingPeriod = today.add(period);
View Full Code Here

    public Euribor365_10M() {
      this(new Handle<YieldTermStructure>());
    }
    public Euribor365_10M(final Handle<YieldTermStructure> h) {
        super(new Period(10, TimeUnit.Months), h);
    }
View Full Code Here

TOP

Related Classes of org.jquantlib.time.Period

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.