Package org.jquantlib.util

Examples of org.jquantlib.util.Date


            throw new NullPointerException();

        if (c == BusinessDayConvention.UNADJUSTED)
            return d;

        Date d1 = d;
        if (c == BusinessDayConvention.FOLLOWING || c == BusinessDayConvention.MODIFIED_FOLLOWING) {
            while (isHoliday(d1))
                d1.increment();
            if (c == BusinessDayConvention.MODIFIED_FOLLOWING) {
                if (d1.getMonth() != d.getMonth()) {
                    return adjust(d, BusinessDayConvention.PRECEDING);
                }
            }
        } else if (c == BusinessDayConvention.PRECEDING || c == BusinessDayConvention.MODIFIED_PRECEDING) {
            while (isHoliday(d1))
                d1.decrement();
            if (c == BusinessDayConvention.MODIFIED_PRECEDING && d1.getMonth() != d.getMonth()) {
                return adjust(d, BusinessDayConvention.FOLLOWING);
            }
        } else {
            throw new IllegalArgumentException("unknown business-day convention");
        }
View Full Code Here


    }

    public final Date advance(final Date date, int n, final TimeUnit unit, final BusinessDayConvention c, boolean endOfMonth) {
        if (date == null)
            throw new NullPointerException();
        Date d1 = DateFactory.getFactory().getDate(date.getDayOfMonth(), date.getMonthEnum(), date.getYear());
        if (n == 0) {
            return adjust(d1, c);
        } else if (unit == TimeUnit.DAYS) {
            if (n > 0) {
                while (n > 0) {
                    d1.increment();
                    while (isHoliday(d1))
                        d1.increment();
                    n--;
                }
            } else {
                while (n < 0) {
                    d1.decrement();
                    while (isHoliday(d1))
                        d1.decrement();
                    n++;
                }
            }
            return d1;
        } else if (unit == TimeUnit.WEEKS) {
            d1 = d1.adjust(new Period(n, unit));
            return adjust(d1, c);
        } else {
            d1 = d1.adjust(new Period(n, unit));
            if (endOfMonth && (unit == TimeUnit.MONTHS || unit == TimeUnit.YEARS) && isEndOfMonth(d1)) {
                return getEndOfMonth(d1);
            }
            return adjust(d1, c);
        }
View Full Code Here

        if (from.equals(to)) {
            if (isBusinessDay(from) && (includeFirst || includeLast))
                wd = 1;
        } else {
            if (from.lt(to)) {
                Date d = from;
                while (d.le(to)) {
                    if (isBusinessDay(d))
                        wd++;
                    d = d.getDateAfter(1);
                }
            } else if (from.gt(to)) {
                Date d = to;
                while (d.le(from)) {
                    if (isBusinessDay(d))
                        wd++;
                    d = d.getDateAfter(1);
                }
            }

            if (isBusinessDay(from) && !includeFirst)
                wd--;
View Full Code Here

    public List<Date> getHolidayList(final Date from, final Date to, boolean includeWeekEnds) {
        List<Date> holidays = new ArrayList<Date>();
        if (from.ge(to))
            throw new IllegalStateException("To date  must be after from date ");
        Date startDate = from.getDateAfter(0);
        for (Date d = startDate; d.le(to); d = d.getDateAfter(1)) {
            if (isHoliday(d) && (includeWeekEnds || !isWeekend(d.getWeekday())))
                holidays.add(d);
        }
View Full Code Here

   */
    // FIXME: this method is potentially harmful in heavily multi-threaded environments
    public Date date(final String immCode, final Date refDate) {
        if (! (isIMMcode(immCode, false)) ) throw new IllegalArgumentException(immCode+" is not a valid IMM code");

        Date referenceDate;
        if (Date.NULL_DATE.equals(refDate)) {
          referenceDate = settings.getEvaluationDate();
        } else {
          referenceDate = refDate;
        }

        char code = immCode.charAt(0);
        Month m = Month.valueOf(code);
       
        int y = immCode.charAt(1) - '0';

        /* year<1900 are not valid QuantLib years: to avoid a run-time
           exception few lines below we need to add 10 years right away */
        if (y==0 && referenceDate.getYear()<=1909) y+=10;
        int yMod = (referenceDate.getYear() % 10);
        y += referenceDate.getYear() - yMod;
        Date result = nextDate(DateFactory.getFactory().getDate(1, m, y), false);
        if (result.lt(referenceDate))
            return nextDate(DateFactory.getFactory().getDate(1, m, y+10), false);

        return result;
    }
View Full Code Here

     * @return the 1st delivery date for next contract listed in the
     *   International Money Market section of the Chicago Mercantile
     *   Exchange.
     */
    public Date nextDate(final Date date, boolean mainCycle) {
        Date refDate;
        if (Date.NULL_DATE.equals(date)) {
          refDate = settings.getEvaluationDate();
        } else {
          refDate = date;       
        }
       
        int y = refDate.getYear();
        int m = refDate.getMonth();

        int offset = mainCycle ? 3 : 1;
        int skipMonths = offset-(m%offset);
        if (skipMonths != offset || refDate.getDayOfMonth() > 21) {
            skipMonths += m;
            if (skipMonths<=12) {
                m = skipMonths;
            } else {
                m = skipMonths-12;
                y += 1;
            }
        }

        Date result = DateFactory.getFactory().getNthWeekday(3, Weekday.WEDNESDAY, Month.valueOf(m), y);
        if (result.le(refDate))
            result = nextDate(DateFactory.getFactory().getDate(22, Month.valueOf(m), y), mainCycle);
        return result;
    }
View Full Code Here

     *  Exchange.
     */
    public Date nextDate(final String IMMcode,
                       boolean mainCycle,
                       final Date referenceDate)  {
        Date immDate = date(IMMcode, referenceDate);
        return nextDate(immDate.increment(), mainCycle);
    }
View Full Code Here

     * International Money Market section of the Chicago Mercantile
     * Exchange.
   */
    public String nextCode(final Date d,
                              boolean mainCycle) {
        Date date = nextDate(d, mainCycle);
        return code(date);
    }
View Full Code Here

     * Exchange.
   */
    public String nextCode(final String immCode,
                              boolean mainCycle,
                              final Date referenceDate) {
        Date date = nextDate(immCode, mainCycle, referenceDate);
        return code(date);
    }
View Full Code Here

    /* (non-Javadoc)
     * @see org.jquantlib.xmlrpc.services.CalendarWidget#getWeekday(int, int, int)
     */
    public final String getWeekday(final int year, final int month, final int day) {
        Date date = AbstractDateFactory.getFactory().getDate(day, month, year);
        return date.getWeekday().toString();
    }
View Full Code Here

TOP

Related Classes of org.jquantlib.util.Date

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.