Package org.jquantlib.daycounters

Examples of org.jquantlib.daycounters.DayCounter


        final Date paymentDate = iteratorLeg.get(iteratorIndex).date();
        boolean firstCouponFound = false;
        /* @Real */double nominal = Constants.NULL_REAL;
        /* @Time */double accrualPeriod = Constants.NULL_TIME;
        DayCounter dc = null;
        /* @Rate */double result = 0.0;

        for (int i = iteratorIndex; i < leg.size(); i++) {
            final CashFlow cf = iteratorLeg.get(i);
            if (cf.date().eq(paymentDate)) {
View Full Code Here


            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;
View Full Code Here

        final Quote zc3mRate = new SimpleQuote(zc3mQuote);
        final Quote zc6mRate = new SimpleQuote(zc6mQuote);
        final Quote zc1yRate = new SimpleQuote(zc1yQuote);

        final DayCounter zcBondsDayCounter = new Actual365Fixed();

        final RateHelper zc3m = new DepositRateHelper(
                new Handle<Quote>(zc3mRate), new Period(3, TimeUnit.Months),
                fixingDays, calendar,
                BusinessDayConvention.ModifiedFollowing, true, zcBondsDayCounter);
        final RateHelper zc6m = new DepositRateHelper(
                new Handle<Quote>(zc6mRate), new Period(6, TimeUnit.Months),
                fixingDays, calendar,
                BusinessDayConvention.ModifiedFollowing, true, zcBondsDayCounter);
        final RateHelper zc1y = new DepositRateHelper(
                new Handle<Quote>(zc1yRate), new Period(1, TimeUnit.Years),
                fixingDays, calendar,
                BusinessDayConvention.ModifiedFollowing, true, zcBondsDayCounter);

        // setup bonds
        final double redemption = 100.0;
        final int numberOfBonds = 5;

        final Date issueDates[] = {
                new Date(15, Month.March,    2005),
                new Date(15, Month.June,     2005),
                new Date(30, Month.June,     2006),
                new Date(15, Month.November, 2002),
                new Date(15, Month.May,      1987) };

        final Date maturities[] = {
                new Date(31, Month.August, 2010),
                new Date(31, Month.August, 2011),
                new Date(31, Month.August, 2013),
                new Date(15, Month.August, 2018),
                new Date(15, Month.May,    2038) };

        final double couponRates[] = 0.02375,
                        0.04625,
                        0.03125,
                        0.04000,
                        0.04500
                        };

        final double marketQuotes[] = { 100.390625,
                        106.21875,
                        100.59375,
                        101.6875,
                        102.140625
                        };

        final List<SimpleQuote> quote = new ArrayList<SimpleQuote>(numberOfBonds);
        final List<RelinkableHandle<Quote>> quoteHandle = new ArrayList<RelinkableHandle<Quote>>(numberOfBonds);
        for (int i = 0; i < numberOfBonds; i++) {
          final SimpleQuote sq = new SimpleQuote(marketQuotes[i]);
          final RelinkableHandle<Quote> handle = new RelinkableHandle<Quote>(sq);
            quote.add(sq);
            quoteHandle.add(handle);  
        }

        // Definition of the rate helpers
//        final List<FixedRateBondHelper<YieldTermStructure>> bondsHelpers = new ArrayList<FixedRateBondHelper<YieldTermStructure>>();
        final List<FixedRateBondHelper> bondsHelpers = new ArrayList<FixedRateBondHelper>();

        for (int i = 0; i < numberOfBonds; i++) {
            final Schedule schedule = new Schedule(
                    issueDates[i], maturities[i],
                    new Period(Frequency.Semiannual),
                    new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                    BusinessDayConvention.Unadjusted,
                    BusinessDayConvention.Unadjusted,
                    DateGeneration.Rule.Backward,
                    false);
            final FixedRateBondHelper bondHelper = new FixedRateBondHelper(
                            quoteHandle.get(i),
                            settlementDays,
                            100.0,
                            schedule,
                            new double[]{ couponRates[i] },
                            new ActualActual(ActualActual.Convention.Bond),
                            BusinessDayConvention.Unadjusted,
                            redemption,
                            issueDates[i]);

            bondsHelpers.add(bondHelper);
        }

        /*********************
         ** CURVE BUILDING **
         *********************/

        // Any DayCounter would be fine.
        // ActualActual::ISDA ensures that 30 years is 30.0
        final DayCounter termStructureDayCounter = new ActualActual(ActualActual.Convention.ISDA);

        final double tolerance = 1.0e-15;

        // A depo-bond curve
        final List<RateHelper> bondInstruments = new ArrayList<RateHelper>();

        // Adding the ZC bonds to the curve for the short end
        bondInstruments.add(zc3m);
        bondInstruments.add(zc6m);
        bondInstruments.add(zc1y);

        // Adding the Fixed rate bonds to the curve for the long end
        for (int i = 0; i < numberOfBonds; i++) {
            bondInstruments.add(bondsHelpers.get(i));
        }
        final RateHelper[] instruments1 = new RateHelper[bondInstruments.size()];
        bondInstruments.toArray(instruments1);
        final Handle[] jumps1 = new Handle[0];
        final Date[] jumpDates1 = new Date[0];
        final double tolerance1 = 1.0e-15;
        final LogLinear interpolator = null;
        final IterativeBootstrap bootstrap = null;
       
        final YieldTermStructure  bondDiscountingTermStructur =
                 new PiecewiseYieldCurve<Discount,LogLinear,IterativeBootstrap>(
                     Discount.class, LogLinear.class, IterativeBootstrap.class,
                     settlementDate,
                     instruments1,
                     termStructureDayCounter,
                     jumps1,
                     jumpDates1,
                     tolerance1,
                     interpolator,
                     bootstrap){/* anonymous */};

        // Building of the Libor forecasting curve
        // deposits
        final double d1wQuote = 0.043375;
        final double d1mQuote = 0.031875;
        final double d3mQuote = 0.0320375;
        final double d6mQuote = 0.03385;
        final double d9mQuote = 0.0338125;
        final double d1yQuote = 0.0335125;
        // swaps
        final double s2yQuote = 0.0295;
        final double s3yQuote = 0.0323;
        final double s5yQuote = 0.0359;
        final double s10yQuote = 0.0412;
        final double s15yQuote = 0.0433;

        /********************
         *** QUOTES ***
         ********************/

        // SimpleQuote stores a value which can be manually changed;
        // other Quote subclasses could read the value from a database
        // or some kind of data feed.

        // deposits
        final Quote d1wRate = (new SimpleQuote(d1wQuote));
        final Quote d1mRate = (new SimpleQuote(d1mQuote));
        final Quote d3mRate = (new SimpleQuote(d3mQuote));
        final Quote d6mRate = (new SimpleQuote(d6mQuote));
        final Quote d9mRate = (new SimpleQuote(d9mQuote));
        final Quote d1yRate = (new SimpleQuote(d1yQuote));
        // swaps
        final Quote s2yRate = (new SimpleQuote(s2yQuote));
        final Quote s3yRate = (new SimpleQuote(s3yQuote));
        final Quote s5yRate = (new SimpleQuote(s5yQuote));
        final Quote s10yRate = (new SimpleQuote(s10yQuote));
        final Quote s15yRate = (new SimpleQuote(s15yQuote));

        /*********************
         *** RATE HELPERS ***
         *********************/

        // RateHelpers are built from the above quotes together with
        // other instrument dependant infos. Quotes are passed in
        // relinkable handles which could be relinked to some other
        // data source later.

        // deposits
        final DayCounter depositDayCounter = new Actual360();

        final RateHelper d1w = new DepositRateHelper(
                  new Handle<Quote>(d1wRate),
                  new Period(1, TimeUnit.Weeks),
                  fixingDays, calendar,
                  BusinessDayConvention.ModifiedFollowing,
                  true, depositDayCounter);
        final RateHelper d1m = new DepositRateHelper(
                  new Handle<Quote>(d1mRate),
                  new Period(1, TimeUnit.Months),
                  fixingDays, calendar,
                  BusinessDayConvention.ModifiedFollowing,
                  true, depositDayCounter);
        final RateHelper d3m = new DepositRateHelper(
                  new Handle<Quote>(d3mRate),
                  new Period(3, TimeUnit.Months),
                  fixingDays, calendar,
                  BusinessDayConvention.ModifiedFollowing,
                  true, depositDayCounter);
        final RateHelper d6m = new DepositRateHelper(
                  new Handle<Quote>(d6mRate),
                  new Period(6, TimeUnit.Months),
                  fixingDays, calendar,
                  BusinessDayConvention.ModifiedFollowing,
                  true, depositDayCounter);
        final RateHelper d9m = new DepositRateHelper(
                new Handle<Quote>(d9mRate),
                new Period(9, TimeUnit.Months),
                fixingDays, calendar,
                BusinessDayConvention.ModifiedFollowing,
                true, depositDayCounter);
        final RateHelper d1y = new DepositRateHelper(
                new Handle<Quote>(d1yRate),
                new Period(1, TimeUnit.Years),
                fixingDays, calendar,
                BusinessDayConvention.ModifiedFollowing,
                true, depositDayCounter);

        // setup swaps
        final Frequency swFixedLegFrequency = Frequency.Annual;
        final BusinessDayConvention swFixedLegConvention = BusinessDayConvention.Unadjusted;
        final DayCounter swFixedLegDayCounter = new Thirty360(Convention.European);
        final IborIndex  swFloatingLegIndex = new Euribor6M(new Handle<YieldTermStructure>());

        // TODO and FIXME: not sure whether the class stuff works properly
        // final IborIndex swFloatingLegIndex = Euribor.getEuribor6M(new Handle<YieldTermStructure>(YieldTermStructure.class)); //FIXME::RG::Handle
//        final YieldTermStructure nullYieldTermStructure = new AbstractYieldTermStructure() {
View Full Code Here

        final RelinkableHandle<Quote> h2x5 = null;        h2x5.linkTo(fra2x5Rate.currentLink());
        final RelinkableHandle<Quote> h3x6 = null;        h3x6.linkTo(fra3x6Rate.currentLink());
        final RelinkableHandle<Quote> h6x9 = null;        h6x9.linkTo(fra6x9Rate.currentLink());
        final RelinkableHandle<Quote> h9x12 = null;       h9x12.linkTo(fra9x12Rate.currentLink());

        /*********************
         ***  RATE HELPERS ***
         *********************/

        // RateHelpers are built from the above quotes together with
        // other instrument dependant infos.  Quotes are passed in
        // relinkable handles which could be relinked to some other
        // data source later.

        final DayCounter fraDayCounter = euribor3m.currentLink().dayCounter();
        final BusinessDayConvention convention = euribor3m.currentLink().businessDayConvention();
        final boolean endOfMonth = euribor3m.currentLink().endOfMonth();

        final RateHelper fra1x4  = new FraRateHelper(h1x4,  14, fixingDays, calendar, convention, endOfMonth, fraDayCounter);
        final RateHelper fra2x5  = new FraRateHelper(h2x5,  25, fixingDays, calendar, convention, endOfMonth, fraDayCounter);
        final RateHelper fra3x6  = new FraRateHelper(h3x6,  36, fixingDays, calendar, convention, endOfMonth, fraDayCounter);
        final RateHelper fra6x9  = new FraRateHelper(h6x9,  69, fixingDays, calendar, convention, endOfMonth, fraDayCounter);
        final RateHelper fra9x12 = new FraRateHelper(h9x12, 9, 12, fixingDays, calendar, convention, endOfMonth, fraDayCounter);

        /*********************
         **  CURVE BUILDING **
         *********************/

        // Any DayCounter would be fine.
        // ActualActual::ISDA ensures that 30 years is 30.0
View Full Code Here

    }

    @Override
    public void calculate() {

        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();

        Double s0 = process_.x0();
        QL.require(s0 > 0.0, "negative or null underlying");
        final double /*Volatility*/ v = process_.blackVolatility().currentLink().blackVol(
View Full Code Here

        final double volatility = 0.2;
        final double dividendYield = 0.00;


        final Date maturity = new Date(17, Month.May, 1999);
        final DayCounter dayCounter = new Actual365Fixed();

        // define line formatting
        //              "         1         2         3         4         5         6         7         8         9"
        //              "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
        //              "                            Method      European      Bermudan      American";
View Full Code Here

        this.accrualEndTimes_ = new ArrayList<Double>(size_);
        this.accrualPeriod_ = new ArrayList<Double>(size_);
        this.m1 = new Array(size_);
        this.m2 = new Array(size_);

        final DayCounter dayCounter = index_.dayCounter();
        final List<CashFlow> flows = null /* cashFlows() */; // FIXME: translate cashFlows();

        QL.require(this.size_ == flows.size() , wrong_number_of_cashflows); // TODO: message

        final Date settlement = index_.termStructure().currentLink().referenceDate();
        final Date startDate = ((IborCoupon) flows.get(0)).fixingDate();
        for (int i = 0; i < size_; ++i) {
            final IborCoupon coupon = (IborCoupon) flows.get(i);
            QL.require(coupon.date().eq(coupon.accrualEndDate()) , irregular_coupon_types); // TODO: message

            initialValues_.set(i, coupon.rate());
            accrualPeriod_.set(i, coupon.accrualPeriod());

            fixingDates_.set(i, coupon.fixingDate());
            fixingTimes_.set(i, dayCounter.yearFraction(startDate, coupon.fixingDate()));
            accrualStartTimes_.set(i, dayCounter.yearFraction(settlement, coupon.accrualStartDate()));
            accrualEndTimes_.set(i, dayCounter.yearFraction(settlement, coupon.accrualEndDate()));
        }
    }
View Full Code Here

        greeks.delta = black.delta(spot);
        moreGreeks.deltaForward = black.deltaForward();
        moreGreeks.elasticity = black.elasticity(spot);
        greeks.gamma = black.gamma(spot);

        final DayCounter rfdc = process.riskFreeRate().currentLink().dayCounter();
        final DayCounter divdc = process.dividendYield().currentLink().dayCounter();
        final DayCounter voldc = process.blackVolatility().currentLink().dayCounter();
        final Date refDate = process.riskFreeRate().currentLink().referenceDate();
        /* @Time */double t = rfdc.yearFraction(refDate, a.exercise.lastDate());
        greeks.rho = black.rho(t);

        t = divdc.yearFraction(process.dividendYield().currentLink().referenceDate(), a.exercise.lastDate());
        greeks.dividendRho = black.dividendRho(t);

        t = voldc.yearFraction(process.blackVolatility().currentLink().referenceDate(), a.exercise.lastDate());
        greeks.vega = black.vega(t);
        try {
            greeks.theta = black.theta(spot, t);
            moreGreeks.thetaPerDay = black.thetaPerDay(spot, t);
        } catch (final Exception e) {
View Full Code Here

            greeks.delta            = black.delta(spot);
            moreGreeks.deltaForward = black.deltaForward();
            moreGreeks.elasticity   = black.elasticity(spot);
            greeks.gamma            = black.gamma(spot);

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

            double /* @Time */t = rfdc.yearFraction(process.riskFreeRate().currentLink().referenceDate(), a.exercise.lastDate());
            greeks.rho = black.rho(t);

            t = divdc.yearFraction(process.dividendYield().currentLink().referenceDate(), a.exercise.lastDate());
            greeks.dividendRho = black.dividendRho(t);

            t = voldc.yearFraction(process.blackVolatility().currentLink().referenceDate(), a.exercise.lastDate());
            greeks.vega            = black.vega(t);
            greeks.theta           = black.theta(spot, t);
            moreGreeks.thetaPerDay = black.thetaPerDay(spot, t);

            moreGreeks.strikeSensitivity  = black.strikeSensitivity();
View Full Code Here

        final double /* @Real */lambda = (k + 1.0) * process.jumpIntensity().currentLink().value();

        // 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();

        final PoissonDistribution p = new PoissonDistribution(lambda * t);

 
View Full Code Here

TOP

Related Classes of org.jquantlib.daycounters.DayCounter

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.