Package org.jquantlib.time

Examples of org.jquantlib.time.Calendar


  @Test
  //FIXME: http://bugs.jquantlib.org/view.php?id=472
  public void testYield() {
    QL.info("Testing consistency of bond price/yield calculation....");

        final Calendar calendar = new org.jquantlib.time.calendars.Target();
        final Date today = calendar.adjust(Date.todaysDate());
        final double faceAmount = 1000000.0;

    final double tolerance = 1.0e-7;
    final int maxEvaluations = 100;

    final int issueMonths[] = { -24, -18, -12, -6, 0, 6, 12, 18, 24 };
    final int lengths[] = { 3, 5, 10, 15, 20 };
    final int settlementDays = 3;
    final double coupons[] = { 0.02, 0.05, 0.08 };
    final Frequency frequencies[] = { Frequency.Semiannual, Frequency.Annual };
    final DayCounter bondDayCount = new Thirty360();
    final BusinessDayConvention accrualConvention = BusinessDayConvention.Unadjusted;
    final BusinessDayConvention paymentConvention = BusinessDayConvention.ModifiedFollowing;
    final double redemption = 100.0;

    final double yields[] = { 0.03, 0.04, 0.05, 0.06, 0.07 };
    final Compounding compounding[] = { Compounding.Compounded, Compounding.Continuous };

    for (int i = 0; i < (issueMonths).length; i++) {
      for (int j = 0; j < (lengths).length; j++) {
        for (int k = 0; k < (coupons).length; k++) {
          for (int l = 0; l < (frequencies).length; l++) {
            for (int n = 0; n < (compounding).length; n++) {
              final Date dated = calendar.advance(today, issueMonths[i], TimeUnit.Months);
              final Date issue = dated;
              final Date maturity = calendar.advance(issue, lengths[j], TimeUnit.Years);

              final Schedule sch = new Schedule(
                      dated,
                  maturity,
                  new Period(frequencies[l]),
View Full Code Here


  @Test
  public void testTheoretical() {
    QL.info("Testing theoretical bond price/yield calculation...");

        final Calendar calendar = new org.jquantlib.time.calendars.Target();
        final Date today = calendar.adjust(Date.todaysDate());
        final double faceAmount = 1000000.0;

    final double tolerance = 1.0e-7;
    final int maxEvaluations = 100;

    final int lengths[] = { 3, 5, 10, 15, 20 };
    final int settlementDays = 3;
    final double coupons[] = { 0.02, 0.05, 0.08 };
    final Frequency frequencies[] = { Frequency.Semiannual, Frequency.Annual };
    final DayCounter bondDayCount = new Actual360();
    final BusinessDayConvention accrualConvention = BusinessDayConvention.Unadjusted;
    final BusinessDayConvention paymentConvention = BusinessDayConvention.ModifiedFollowing;
    final double redemption = 100.0;

    final double yields[] = { 0.03, 0.04, 0.05, 0.06, 0.07 };

    for (final int length : lengths) {
      for (final double coupon : coupons) {
        for (final Frequency frequency : frequencies) {

          final Date dated = today;
          final Date issue = dated;
          final Date maturity = calendar.advance(issue, length, TimeUnit.Years);

          final SimpleQuote rate = new SimpleQuote(0.0);
          final Handle<YieldTermStructure> discountCurve = new Handle<YieldTermStructure>(Utilities.flatRate(today, rate, bondDayCount));

          final Schedule sch = new Schedule(
View Full Code Here

        final double faceAmount = 1000000.0;

        // with implicit settlement calculation:

      final Calendar bondCalendar = new NullCalendar();
      final DayCounter bondDayCount = new ActualActual(ActualActual.Convention.ISMA);
      final int settlementDays = 1;

    final Handle<YieldTermStructure> discountCurve = new Handle<YieldTermStructure>(Utilities.flatRate(today, 0.03, new Actual360()));
View Full Code Here

  @Test
  public void testCachedZero() {

      QL.info("Testing zero-coupon bond prices against cached values...");

        final Calendar calendar = new Target();
        final Date today = calendar.adjust(Date.todaysDate());
        // final Date today = calendar.adjust(new Date(6,Month.June,2007));
      // final Date today = new Date(22,Month.November,2004);
      final Settings settings = new Settings();
      settings.setEvaluationDate(today);
View Full Code Here

  @Test
  public void testCachedFixed() {

      QL.info("Testing fixed-coupon bond prices against cached values...");

        final Calendar calendar = new Target();
        final Date today = calendar.adjust(Date.todaysDate());
        // final Date today = calendar.adjust(new Date(6,Month.June,2007));
        // final Date today = new Date(22,Month.November,2004);
        final Settings settings = new Settings();
        settings.setEvaluationDate(today);
View Full Code Here

  @Test
  public void testBrazilianCached() {

      QL.info("Testing Brazilian public bond prices against cached values...");

        final Calendar calendar = new Target();
        // final Date today = calendar.adjust(Date.todaysDate());
      final Date today = calendar.adjust(new Date(6,Month.June,2007));
      final Settings settings = new Settings();
      settings.setEvaluationDate(today);

        //final double faceAmount = 1000000.0;
        final double faceAmount = 1000.0;
View Full Code Here

    }
    protected InterpolatedDiscountCurve(
            final Date referenceDate,
            final DayCounter dc,
            final Interpolator interpolator) {
        super(referenceDate, new Calendar(), dc);
        QL.validateExperimentalMode();

        this.classI = interpolator.getClass();
//XXX     this.classI = new TypeTokenTree(this.getClass()).getElement(0);
//        if (classI != interpolator.getClass()) {
View Full Code Here

        QL.validateExperimentalMode();

        QL.require(new IMM().isIMMdate(immDate, false) , "not a valid IMM date"); // QA:[RG]::verified // TODO: message
        convAdj = new Handle<Quote>(new SimpleQuote(conv));
        earliestDate = immDate;
        final Calendar cal = i.fixingCalendar();
        latestDate = cal.advance(immDate, i.tenor(), i.businessDayConvention());
        yearFraction = i.dayCounter().yearFraction(earliestDate, latestDate);
    }
View Full Code Here

    @Test
    public void testEndOfMonth() {
        QL.info("Testing end-of-month calculation...");

        final Calendar c = new Target(); // any calendar would be OK

        Date eom;
        final Date counter = Date.minDate();
        final Date last = Date.maxDate().sub(new Period(2, TimeUnit.Months));

        while (counter.le(last)) {
            eom = c.endOfMonth(counter);
            // check that eom is eom
            if (!c.isEndOfMonth(eom)) {
                Assert.fail(String.format("%s %s %s is not the last business day in %s according to %s",
                        eom.weekday(), eom.dayOfMonth(), eom.month(), eom.year(), c.name() ));
            }
            // check that eom is in the same month as counter
            if (eom.month()!=counter.month()) {
                Assert.fail(String.format("%s is not the same month as %s", eom, counter ));
            }
View Full Code Here

     * @warning term structures initialized by means of this
     *          constructor must manage their own reference date
     *          by overriding the referenceDate() method.
     */
    public BlackVolatilityTermStructure() {
        super(new Calendar(), BusinessDayConvention.Following, new DayCounter());
    }
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.