Skip to content

Commit

Permalink
- Dima dates
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Manese committed Apr 5, 2014
1 parent aa2050a commit 6ca7f80
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dima/02-ql/02-vartypes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>
#include <ql/quantlib.hpp>

using namespace std;
using namespace QuantLib;

// exercise
Real myReciproke(Real x) {
QL_REQUIRE(x != 0, "Zero number!");
return 1/x;
}

int main(int argc, char *argv) {
Real x = 3.1416;

std::cout << "myReciproke: " << myReciproke(x) << std::endl;
}
52 changes: 52 additions & 0 deletions dima/02-ql/03-dates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <iostream>
#include <ql/quantlib.hpp>

using namespace std;
using namespace QuantLib;

void DateTesting1() {

Date myDate(12, Aug, 2009);
std::cout << myDate << std::endl;

myDate++;
std::cout << myDate << std::endl;

myDate += 12*Days;
std::cout << myDate << std::endl;

myDate -= 2*Months;
std::cout << myDate << std::endl;

myDate--;
std::cout << myDate << std::endl;

Period p(10, Weeks);
myDate += p;
std::cout << myDate << std::endl;
}

void DateTesting2() {
Date myDate(12, Aug, 2009);

cout << "Original date: " << myDate << endl;
cout << "Weekday: " << myDate.weekday() << endl;
cout << "Day of month: " << myDate.dayOfMonth() << endl;
cout << "Day of year: " << myDate.dayOfYear() << endl;
cout << "Month: " << myDate.month() << endl;

int month = myDate.month();
cout << "Month via int: " << month << endl;
cout << "Year: " << myDate.year() << endl;

int serialNum = myDate.serialNumber();
cout << "Serial number: " << serialNum << endl;
}

int main(int argc, char *argv[]) {
//DateTesting1();
DateTesting2();

return 0;
}

8 changes: 8 additions & 0 deletions dima/02-ql/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@ macros.exe: 01-macros.cpp
g++ -c -Wall -I${BOOST} -I${QUANTLIB_H} $< -o $(patsubst %.exe,%.o,$@)
g++ -L${QUANTLIB_LIB} $(patsubst %.exe,%.o,$@) -o $@ -lQuantLib

vartypes.exe: 02-vartypes.cpp
g++ -c -Wall -I${BOOST} -I${QUANTLIB_H} $< -o $(patsubst %.exe,%.o,$@)
g++ -L${QUANTLIB_LIB} $(patsubst %.exe,%.o,$@) -o $@ -lQuantLib

dates.exe: 03-dates.cpp
g++ -c -Wall -I${BOOST} -I${QUANTLIB_H} $< -o $(patsubst %.exe,%.o,$@)
g++ -L${QUANTLIB_LIB} $(patsubst %.exe,%.o,$@) -o $@ -lQuantLib

clean:
rm -f *.exe

0 comments on commit 6ca7f80

Please sign in to comment.