Sunday, October 7, 2007

Note 10: Detailes for the usage of QuantLib Calendar Class

When we deal with real business time, it is no more simple time interval calculation between two different time. And one need to use the business day calculation. In principle, it is extremely simple and just needs basic level of programming. However, it is tedious for a quant working in this convention. So Let us borrow others.


Date todayDate(15, May, 1998);
Date settlementDate(17, May, 1998);
Date startDate(18,May,1998);
Date maturity(17, May, 1999);
// We use the Holidays setting for the stock exchange in NYSE
// Market { Settlement, NYSE, GovernmentBond, NERC }@USA
Calendar calendar = UnitedStates();

// Calculate the business day between
int btimeinterval=calendar.businessDaysBetween(startDate,maturity);
// Calculate the day between
DayCounter daycount = Actual365Fixed();
int timeinterval=daycount.dayCount(startDate,maturity);

std::cout << "SettlementDate = " << settlementDate << std::endl;
std::cout << "StartDate = " << startDate << std::endl;
std::cout << "Maturity = " << maturity << std::endl;
std::cout << "Total business days= "<< btimeinterval << std::endl;
std::cout << "Totaldays= "<< timeinterval << std::endl;


Date startDate01 = calendar.advance(settlementDate,Period(1,Days));

Date maturity01 = calendar.advance(settlementDate,Period(1,Years));

std::cout << "SettlementDate = " << settlementDate << std::endl;
std::cout << "StartDate = " << startDate01 << std::endl;
std::cout << "Maturity = " << maturity01 << std::endl;

No comments: