Repository navigation
Expand file tree
/
Copy pathyield_piecewise_support_code.cpp
More file actions
111 lines (103 loc) · 3.84 KB
/
Copy pathyield_piecewise_support_code.cpp
File metadata and controls
111 lines (103 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Cython does not support the full CPP syntax preventing to expose the
* Piecewise constructors (e.g. typemap).
*
* This code is inspired by the RQuantLib code and provides a factory function
* for PiecewiseYieldCurve.
*
*/
#include <vector>
#include <string>
#include <iostream>
#include <ql/termstructures/all.hpp>
#include <ql/time/date.hpp>
#include <ql/time/daycounter.hpp>
namespace QuantLib {
typedef boost::shared_ptr<YieldTermStructure> TS;
// Creates a YieldTermStructure based on a PiecewiseYieldCurve
TS term_structure_factory(
std::string& traits, std::string& interpolator,
const Date& settlement_date,
const std::vector<boost::shared_ptr<RateHelper> >& curve_input,
DayCounter&
day_counter, Real tolerance
) {
TS ts;
if (traits.compare("discount") == 0) {
if (interpolator.compare("linear") == 0) {
ts = TS(
new PiecewiseYieldCurve<Discount,Linear>(
settlement_date, curve_input, day_counter,
tolerance
)
);
} else if (interpolator.compare("loglinear") == 0) {
ts = TS(
new PiecewiseYieldCurve<Discount,LogLinear>(
settlement_date, curve_input, day_counter,
tolerance
)
);
} else if (interpolator.compare("spline") == 0) {
ts = TS(
new PiecewiseYieldCurve<Discount, Cubic>(
settlement_date, curve_input, day_counter,
tolerance
)
);
}
} else if (traits.compare("forward") == 0) {
if (interpolator.compare("linear") == 0) {
ts = TS(
new PiecewiseYieldCurve<ForwardRate,Linear>(
settlement_date, curve_input, day_counter,
tolerance
)
);
} else if (interpolator.compare("loglinear") == 0) {
ts = TS(
new PiecewiseYieldCurve<ForwardRate,LogLinear>(
settlement_date, curve_input, day_counter,
tolerance
)
);
} else if (interpolator.compare("spline") == 0) {
ts = TS(
new PiecewiseYieldCurve<ForwardRate,Cubic>(
settlement_date, curve_input, day_counter,
tolerance
)
);
}
} else if(traits.compare("zero") == 0) {
if (interpolator.compare("linear") == 0) {
ts = TS(
new PiecewiseYieldCurve<ZeroYield,Linear>(
settlement_date, curve_input, day_counter,
tolerance
)
);
} else if (interpolator.compare("loglinear") == 0) {
ts = TS(
new PiecewiseYieldCurve<ZeroYield,LogLinear>(
settlement_date,
curve_input, day_counter,
tolerance
)
);
} else if (interpolator.compare("spline") == 0) {
ts = TS(
new PiecewiseYieldCurve<ZeroYield,Cubic>(
settlement_date, curve_input, day_counter,
tolerance
)
);
}
} else {
std::cout << "traits = " << traits << std::endl;
std::cout << "interpolator = " << interpolator << std::endl;
QL_FAIL("What/How term structure options not recognized");
}
return ts;
}
}