Package org.jquantlib.time

Examples of org.jquantlib.time.Calendar$OrthodoxImpl


        final StopClock clock = new StopClock();
        clock.startClock();

        // <=========================Basic Calendar functions==============================>
        //Let's take UnitedStates New-York-Stock-Exchange calendar
        final Calendar unitedStatesCalendar = new UnitedStates(Market.NYSE);
        System.out.println("The name of this calendar is = "+ unitedStatesCalendar.name());
        // Let's get the list of holidays from todays date till the date obtained by advancing today's date by 90 days
        final Date dateToday = Date.todaysDate();
        final Date dateAdvanced = dateToday.add(90);
        final List<Date> holidayList = UnitedStates.holidayList(unitedStatesCalendar,dateToday, dateAdvanced, true);
        System. out.println("The holidays between dateToday = " + dateToday+ " till the date dateAdvanced = " + dateAdvanced+ " are as shown below");
        final StringBuffer bufferToHoldHolidays = new StringBuffer();
        for (final Date date : holidayList) {
            bufferToHoldHolidays.append(date +"::");
        }
        System. out.println("The holidays separated by :: are = "+ bufferToHoldHolidays);

        // Let's get the business days between dateToday and dateAdvanced as obtained above by advancing
        // today's date by 90 days as shown below and checking if the incremented date isBusinessDate
        final List<Date> businessDaysInBetweenUsingIsBusDay = new ArrayList<Date>();
        Date dateTodayTemp = dateToday.clone();
        for (; !dateTodayTemp.eq(dateAdvanced); dateTodayTemp.inc()) {
            if (unitedStatesCalendar.isBusinessDay(dateTodayTemp)) {
                businessDaysInBetweenUsingIsBusDay.add(dateTodayTemp);
            }
        }

        final Long sizeOfBusinessDays = Long.parseLong(Integer.toString((businessDaysInBetweenUsingIsBusDay.size())));
        // Let's get the business days between dateToday and dateAdvanced as obtained above by advancing
        // today's date by 90 days using calendar api businessDaysBetween
        final long sizeOfBusinessDaysUsingCalApi = unitedStatesCalendar.businessDaysBetween(dateToday, dateAdvanced, true, true);
        // Check if the sizes obtained are same as they both represent same set of business days
        if (sizeOfBusinessDays == sizeOfBusinessDaysUsingCalApi) {
            System.out.println("The sizes are same");
        }

        // Let's get the same business days using calendars isHoliday API
        final List<Date> businessDaysInBetweenUsingIsHolDay = new ArrayList<Date>();
        dateTodayTemp = dateToday.clone();
        for (; !dateTodayTemp.eq(dateAdvanced); dateTodayTemp.inc()) {
            if (!unitedStatesCalendar.isHoliday(dateTodayTemp)) {
                businessDaysInBetweenUsingIsHolDay.add(dateTodayTemp);
            }
        }

        //Essentially the lists businessDaysInBetweenUsingIsBusDay and businessDaysInBetweenUsingIsHolDay are same
        if (businessDaysInBetweenUsingIsBusDay.equals(businessDaysInBetweenUsingIsHolDay)) {
            System.out.println("The lists businessDaysInBetweenUsingIsBusDay and businessDaysInBetweenUsingIsHolDay are same");
        }

        // <========================Let's use some Calendar airthmetics==============================>
        // Get the first holiday from today
        final Date firstHolidayDate = dateToday.clone();
        while (!unitedStatesCalendar.isHoliday(firstHolidayDate)) {
            firstHolidayDate.inc();
        }

        // Check to see if firstHoliday is holiday
        if (unitedStatesCalendar.isHoliday(firstHolidayDate)) {
            System.out.println("FirstHolidayDate = " + firstHolidayDate+ " is a holiday date");
        }

        // Advance the first holiday date using calendars's advance(date) API and get the nexBusinessDay
        final Date nextBusinessDay = unitedStatesCalendar.advance(firstHolidayDate, new Period(1, TimeUnit.Days));
        if (unitedStatesCalendar.isBusinessDay(nextBusinessDay)) {
            System.out.println("NextBusinessDayFromFirstHolidayFromToday = "+ nextBusinessDay + " is a business date");
        }

        // Adjust todaysDate using different businessDayConventions

        // Using FOLLOWING as a business day convention
        final Date nextFollowingBusinessDay = unitedStatesCalendar.adjust(dateToday,BusinessDayConvention.Following);
        if (unitedStatesCalendar.isBusinessDay(nextFollowingBusinessDay)) {
            System. out.println("NextFollowingBusinessDate = "+ nextFollowingBusinessDay+ " from today is a business date");
        }

        // Using MODIFIED_FOLLOWING as a business day convention
        final Date nextModified_FollowingBusinessDay = unitedStatesCalendar.adjust(dateToday, BusinessDayConvention.ModifiedFollowing);
        if (unitedStatesCalendar.isBusinessDay(nextModified_FollowingBusinessDay)) {
            System.out.println("NextModified_FollowingBusinessDate = "+ nextModified_FollowingBusinessDay+ " from today is a business date");
        }

        // Using PRECEDING as a business day convention
        final Date nextPrecidingBusinessDay = unitedStatesCalendar.adjust(dateToday,BusinessDayConvention.Preceding);
        if (unitedStatesCalendar.isBusinessDay(nextPrecidingBusinessDay)) {
            System.out.println("NextPrecidingBusinessDay = "+ nextPrecidingBusinessDay+ " from today is a business date");
        }

        // Using MODIFIED_PRECEDING as a business day convention
        final Date nextModified_PrecidingBusinessDay = unitedStatesCalendar.adjust(dateToday, BusinessDayConvention.ModifiedPreceding);
        if (unitedStatesCalendar.isBusinessDay(nextModified_PrecidingBusinessDay)) {
            System.out.println("NextModified_PrecidingBusinessDay = "+ nextModified_PrecidingBusinessDay+ " from today is a business date");
        }

        // Using UNADJUSTED as a business day convention
        final Date nextUnadjustedBusinessDay = unitedStatesCalendar.adjust(dateToday,BusinessDayConvention.Unadjusted);
        if (unitedStatesCalendar.isBusinessDay(nextModified_PrecidingBusinessDay)) {
            System.out.println("NextUnadjustedBusinessDay = "+ nextUnadjustedBusinessDay+ " from today is a business date and is same as today");
        }

        // Advance the current date using calendars's advance(date,n,unit) where n = 10 and unit=DAYS
        Date advancedDate = unitedStatesCalendar.advance(dateToday, 10,TimeUnit.Days);
        System.out.println("Next business date when today's date is advanced by 10 days = "+ advancedDate);

        // Advance the current date using calendars's advance(date,n,unit) where n = 10 and unit=WEEKS
        advancedDate = unitedStatesCalendar.advance(dateToday, 10, TimeUnit.Weeks);
        System.out.println("Next business date when today's date is advanced by 10 weeks = "+ advancedDate);

        // Advance the current date using calendars's advance(date,n,unit) where n = 10 and unit=MONTHS
        advancedDate = unitedStatesCalendar.advance(dateToday, 10, TimeUnit.Months);
        System.out.println("Next business date when today's date is advanced by 10 months = "+ advancedDate);

        // Advance the current date using calendars's advance(date,n,unit) where n = 10 and unit=YEARS
        advancedDate = unitedStatesCalendar.advance(dateToday, 10, TimeUnit.Years);
        System.out.println("Next business date when today's date is advanced by 10 years = "+ advancedDate);

        // Advance the current date using calendars's advance(date,period-->lenth=1,Unit=Days,BusinessDayConvention=FOLLOWING)
        advancedDate = unitedStatesCalendar.advance(dateToday,new Period(1, TimeUnit.Days), BusinessDayConvention.Following);
        System.out.println("Next business date when today's date is advanced 1 day = "+ advancedDate);

        // Advance the current date using calendars's advance(date,period-->lenth=1,Unit=WEEKS,BusinessDayConvention=MODIFIED_FOLLOWING)
        advancedDate = unitedStatesCalendar.advance(dateToday,new Period(1, TimeUnit.Weeks),BusinessDayConvention.ModifiedFollowing);
        System.out.println("Next business date when today's date is advanced 1 week = "+ advancedDate);

        // Advance the current date using calendars's advance(date,period-->lenth=1,Unit=MONTHS,BusinessDayConvention=MODIFIED_PRECEDING)
        advancedDate = unitedStatesCalendar.advance(dateToday,new Period(1, TimeUnit.Months),BusinessDayConvention.ModifiedPreceding);
        System.out.println("Next business date when today's date is advanced 1 month = "+ advancedDate);

        // Advance the current date using calendars's advance(date,period-->lenth=1,Unit=YEARS,BusinessDayConvention=PRECEDING)
        advancedDate = unitedStatesCalendar.advance(dateToday,new Period(1, TimeUnit.Years), BusinessDayConvention.Preceding);
        System.out.println("Next business date when today's date is advanced 1 year = "+ advancedDate);

        //<==================Joining Calendars===============================>
        final Calendar unitedStatesCalendarGvtBondCalendar = new UnitedStates(Market.GOVERNMENTBOND);
        final Calendar jointCalendar = new JointCalendar(unitedStatesCalendar,unitedStatesCalendarGvtBondCalendar,JointCalendarRule.JoinBusinessDays);

        //The above joint calendar has been obtained by joining businessdays of newyork stock exchange and government bond calendar
        //which means a day will be a business day for the joint calendar if it is a business day for both of the calendars used
        //(NYSE,GovtBond) and will be a holiday if the day is a holiday in atleast one of the calendars.

        //Let's get the list of holidays for the joint calendar from the date today to date advanced(obtained by advancing date today by 90 days)
        final List<Date> listOfHoliDays = jointCalendar.holidayList(jointCalendar, dateToday, dateAdvanced, true);

        //Now let's get the same holiday list between dateToday and dateAdvanced using isBusinessDay API
        final List<Date> holidayListObtainedUsingCalAPI = new ArrayList<Date>();
        final Date start = dateToday.clone();
        for (; !start.eq(dateAdvanced); start.inc()) {
            if (jointCalendar.isHoliday(start)){
                holidayListObtainedUsingCalAPI.add(start.clone());
            }
        }

        //Essentially both the lists obtained above are same
View Full Code Here


    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(
                                         this.a.exercise.lastDate(), s0);
View Full Code Here

        clock.startClock();

        final Date todaysDate = new Date(15, February, 2002);

        // TODO: code review :: please verify against QL/C++ code
        final Calendar calendar = new Calendar() {
            public String getName() {
                return "";
            }

            @Override
View Full Code Here

  private final static Mexico SETTLEMENT_CALENDAR = new Mexico(
      Market.SETTLEMENT);
  private final static Mexico BVM_CALENDAR = new Mexico(Market.BVM);

  private Mexico(Market market) {
    Calendar delegate;
    switch (market) {
    case SETTLEMENT:
      delegate = new MexicoSettlementCalendar();
      break;
    case BVM:
View Full Code Here

      Market.SETTLEMENT);
  private final static Argentina EXCHANGE_CALENDAR = new Argentina(
      Market.BCBA);

  private Argentina(Market market) {
    Calendar delegate;
    switch (market) {
    case SETTLEMENT:
      delegate = new ArgentinaSettlementCalendar();
      break;
    case BCBA:
View Full Code Here

        final StopClock clock = new StopClock();
        clock.startClock();

        // set up dates
        final Calendar calendar = new Target();
        final Date todaysDate = new Date(15, Month.May, 1998);
        final Date settlementDate = new Date(17, Month.May, 1998);
        new Settings().setEvaluationDate(todaysDate);

        // our options
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

    public void compute(final int nTimeSteps, final int nSamples) {

        if (System.getProperty("EXPERIMENTAL") == null)
            throw new UnsupportedOperationException("Work in progress");

        final Calendar calendar = new Target();
        final Date today = Date.todaysDate();
        final DayCounter dayCount = new Actual365Fixed();
        final Handle<Quote> stateVariable = new Handle(new SimpleQuote(s0_.doubleValue()));
        final Handle<YieldTermStructure> riskFreeRate = new Handle(new FlatForward(today, r_.doubleValue(), dayCount));
View Full Code Here

        final int settlementDays = 3;
        final int length = 5;
        final double redemption = 100.0;
        final double conversionRatio = redemption/underlying;

        final Calendar calendar = new Target();
        //adjust today to the next business day...
        final Date today = calendar.adjust(Date.todaysDate());
        QL.info("Today's date is adjusted by the default business day convention is: " + today.shortDate());
        // set the evaluation date to the adjusted today's date
        new Settings().setEvaluationDate(today);
        QL.info("Set the global evaluation date to the adjusted today's date: " + today.shortDate());

        //Set up settlement, exercise and issue dates
        final Date settlementDate = calendar.advance(today, settlementDays, TimeUnit.Days);
        QL.info("SettlementDate is: " + settlementDate.shortDate());
        QL.info("Check that we haven't messed up with references --> today's date is still: " + today.shortDate());
        final Date exerciseDate = calendar.advance(settlementDate, length, TimeUnit.Years);
        QL.info("Excercise date is: " + exerciseDate.shortDate());
        final Date issueDate = calendar.advance(exerciseDate, -length, TimeUnit.Years);
        QL.info("Issue date is: " + issueDate.shortDate());

        //Fix business day convention and compounding?? frequency
        final BusinessDayConvention convention = BusinessDayConvention.ModifiedFollowing;
        final Frequency frequency = Frequency.Annual;
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"); // TODO: message
        final double v = process.blackVolatility().currentLink().blackVol(a.exercise.lastDate(), s0);
        final Date maturityDate = a.exercise.lastDate();
View Full Code Here

TOP

Related Classes of org.jquantlib.time.Calendar$OrthodoxImpl

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.