forked from jjonphl/qlcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Miguel Manese
committed
Apr 14, 2014
1 parent
6ca7f80
commit 822539d
Showing
5 changed files
with
222 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <iostream> | ||
#include <ql/quantlib.hpp> | ||
#include <boost/foreach.hpp> | ||
|
||
using namespace std; | ||
using namespace QuantLib; | ||
|
||
// calendar functions: | ||
// isBusinessDay(const Date& d) | ||
// isHoliday(const Date& d) | ||
// isWeekend(Weekday w) | ||
// isEndOfMonth(const Date& d) | ||
// Date endOfMonth(const Date& d) | ||
|
||
void CalendarTesting1() { | ||
Calendar frankfCal = Germany(Germany::FrankfurtStockExchange); | ||
Calendar saudiCal = SaudiArabia(); | ||
Date nyEve(31, Dec, 2009); | ||
|
||
cout << "Is business day? (Frankfurt): " << frankfCal.isBusinessDay(nyEve) << endl; | ||
cout << "Is holiday? (Frankfurt): " << frankfCal.isHoliday(nyEve) << endl; | ||
cout << "Is weekend? (Saudi Arabia): " << saudiCal.isWeekend(Saturday) << endl; | ||
cout << "Is last business day? (Frankfurt): " << frankfCal.isEndOfMonth(Date(30,Dec,2009)) << endl; | ||
cout << "Last business day? (Frankfurt): " << frankfCal.endOfMonth(nyEve) << endl; | ||
} | ||
|
||
// customizing calendars | ||
// addHoiday(const Date& d) | ||
// removeHoliday(const Date &d) | ||
// std::vector<Date> holidayList(const Calendar& calendar, const Date& from, const Date& to, bool includeWeekends) | ||
|
||
void CalendarTesting2() { | ||
Calendar frankfCal = Germany(Germany::FrankfurtStockExchange); | ||
Date d1(24, Dec, 2009), d2(30, Dec, 2009), d3(31, Dec, 2009); | ||
|
||
frankfCal.addHoliday(d2); | ||
frankfCal.removeHoliday(d3); | ||
|
||
cout << "Is business day?: " << frankfCal.isBusinessDay(d2) << endl; | ||
cout << "Is business day?: " << frankfCal.isBusinessDay(d3) << endl; | ||
|
||
std::vector<Date> holidays = frankfCal.holidayList(frankfCal, d1, d2, false); | ||
cout << "------------------------------" << endl; | ||
BOOST_FOREACH(Date d, holidays) cout << d << endl; | ||
} | ||
|
||
// BusinessDayConvention enum(?) | ||
// * Following | ||
// * ModifiedFollowing | ||
// * Preceding | ||
// * ModifiedPreceding | ||
// * Unadjusted | ||
// | ||
// Calendar functions | ||
// Date adjust(const Date&, BusinessDayConvention convention) | ||
// Date advance(const Date&, const Periond&, DayConvention, bool endOfMonth) | ||
// BigInteger businessDaysBetween(const Date& from, const Date& to, | ||
// bool includeFirst, bool includeLast) - # of business days | ||
|
||
void CalendarTesting3() { | ||
Calendar frankfCal = Germany(Germany::FrankfurtStockExchange); | ||
|
||
Date d1(31,Oct,2009), d2(1,Jan,2010); | ||
|
||
cout << "Date 2 adjust (Preceding): " << frankfCal.adjust(d2, BusinessDayConvention(Preceding)) << endl; | ||
cout << "Date 2 adjust (ModifiedPreceding): " << frankfCal.adjust(d2, BusinessDayConvention(ModifiedPreceding)) << endl; | ||
|
||
Period mat(2, Months); | ||
cout << "Date 1 month adv: " << frankfCal.advance(d1, mat, BusinessDayConvention(Following), false) << endl; | ||
cout << "Date 1 month adv: " << frankfCal.advance(d1, mat, BusinessDayConvention(ModifiedFollowing), false) << endl; | ||
|
||
cout << "Business days b/w: " << frankfCal.businessDaysBetween(d1, d2, false, false) << endl; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
//CalendarTesting1(); | ||
//CalendarTesting2(); | ||
CalendarTesting3(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <iostream> | ||
#include <ql/quantlib.hpp> | ||
|
||
using namespace std; | ||
using namespace QuantLib; | ||
|
||
void dayCounterTesting1() { | ||
DayCounter dc = Thirty360(); | ||
Date d1(1, Oct, 2009); | ||
Date d2 = d1 + 2*Months; | ||
|
||
cout << "Days between d1/d2: " << dc.dayCount(d1, d2) << std::endl; | ||
cout << "Year fraction d1/d2: " << dc.yearFraction(d1, d2) << std::endl; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
dayCounterTesting1(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include <iostream> | ||
#include <ql/quantlib.hpp> | ||
#include <vector> | ||
#include <boost/foreach.hpp> | ||
|
||
using namespace std; | ||
using namespace QuantLib; | ||
|
||
// DateGeneration::Rule | ||
// Backward - backward from termination date to effective date | ||
// Forward - forward from effective date to termination date | ||
// Zero - no intermediate dates b/w effective & termination dates | ||
// ThirdWednesday - all dates in b/w eff & term dates are on 3rd Wed of | ||
// the month (forward calc) | ||
// Twentieth - used for CDS schedules in emerging markets, all dates b/w eff | ||
// & term dates are 20th of the month | ||
// TwentiethIMM - used for CDS schedules, all dates b/w eff & term dates are | ||
// 20th of an IMM month | ||
|
||
// Schedule(...) constructor arguments: | ||
// const Date& effectiveDate - | ||
// const Date& terminationDate - | ||
// const Period& tenor - freq of the schedule (e.g. 3*Months) | ||
// const Calendar& calendar - | ||
// BusinessDayConvention convention - for in b/w dates | ||
// BusinessDayConvention terminationDateConversion - for term date only | ||
// DateGeneration::Rule rule - | ||
// bool endOfMonth - if eff date is end of month, enforce sched dates | ||
// to be end of month too (e.g. April 30th, May 31st, ...) | ||
// const Date& firstDate = Date() - odd first | ||
// const Date& nextToLastDate = Date() - odd last | ||
|
||
// Schedule functions | ||
// Size size() - # of dates | ||
// const Date& operator[](Size i) - indexer | ||
// Date previousDate(const Date& refDate) - | ||
// Date nextDate(const Date& refDate) - | ||
// const std::vector<Date>& dates() - | ||
|
||
void scheduleTesting1(DateGeneration::Rule rule) { | ||
Date begin(30, Sep, 2009), end(15, Jun, 2012); | ||
Calendar cal = Japan(); | ||
|
||
BusinessDayConvention bdc = BusinessDayConvention(Following); | ||
|
||
Period tenor(6, Months); | ||
|
||
Schedule sched(begin, end, tenor, cal, bdc, bdc, rule, true); | ||
|
||
std::vector<Date> dates = sched.dates(); | ||
|
||
BOOST_FOREACH(Date d, dates) cout << d << endl; | ||
} | ||
|
||
void scheduleTesting3() { | ||
Date begin(30, Sep, 2009), end(15, Jun, 2012); | ||
Calendar cal = Japan(); | ||
|
||
BusinessDayConvention bdc = BusinessDayConvention(Following); | ||
|
||
Period tenor(6, Months); | ||
|
||
DateGeneration::Rule rule = DateGeneration::Forward; | ||
|
||
Schedule sched(begin, end, tenor, cal, bdc, bdc, rule, true); | ||
|
||
Date refDate(3, Aug, 2010); | ||
cout << "Date: " << refDate << endl; | ||
cout << "Next date: " << sched.nextDate(refDate) << endl; | ||
cout << "Prev date: " << sched.previousDate(refDate) << endl; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
// last date should be 2012-06-15, but I'm producing 2012-06-29!! wtf! | ||
//cout << "Forward: \n"; | ||
//scheduleTesting1(DateGeneration::Forward); | ||
|
||
//cout << "\n\nBackward: \n"; | ||
//scheduleTesting1(DateGeneration::Backward); | ||
|
||
scheduleTesting3(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters