forked from lballabio/QuantLib-SWIG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfittedbondcurve.i
150 lines (129 loc) · 5.21 KB
/
fittedbondcurve.i
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
Copyright (C) 2014 StatPro Italia srl
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<[email protected]>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#ifndef quantlib_fitted_bond_i
#define quantlib_fitted_bond_i
%include termstructures.i
%include interpolation.i
%include ratehelpers.i
%{
using QuantLib::FittedBondDiscountCurve;
typedef boost::shared_ptr<YieldTermStructure> FittedBondDiscountCurvePtr;
typedef QuantLib::FittedBondDiscountCurve::FittingMethod FittingMethod;
std::vector<boost::shared_ptr<BondHelper> > convert_bond_helpers(
const std::vector<boost::shared_ptr<RateHelper> >& helpers) {
std::vector<boost::shared_ptr<BondHelper> > result(helpers.size());
for (Size i=0; i<helpers.size(); ++i)
result[i] = boost::dynamic_pointer_cast<BondHelper>(helpers[i]);
return result;
}
%}
class FittingMethod {
public:
virtual ~FittingMethod() = 0;
Size size() const;
Array solution() const;
Integer numberOfIterations() const;
Real minimumCostValue() const;
bool constrainAtZero() const;
Array weights() const;
};
%rename(FittedBondDiscountCurve) FittedBondDiscountCurvePtr;
class FittedBondDiscountCurvePtr
: public boost::shared_ptr<YieldTermStructure> {
public:
%extend {
FittedBondDiscountCurvePtr(
Natural settlementDays,
const Calendar& calendar,
const std::vector<boost::shared_ptr<RateHelper> >& helpers,
const DayCounter& dayCounter,
const FittingMethod& fittingMethod,
Real accuracy = 1.0e-10,
Size maxEvaluations = 10000,
const Array& guess = Array(),
Real simplexLambda = 1.0) {
return new FittedBondDiscountCurvePtr(
new FittedBondDiscountCurve(settlementDays,
calendar,
convert_bond_helpers(helpers),
dayCounter,
fittingMethod,
accuracy,
maxEvaluations,
guess,
simplexLambda));
}
FittedBondDiscountCurvePtr(
const Date &referenceDate,
const std::vector<boost::shared_ptr<RateHelper> >& helpers,
const DayCounter& dayCounter,
const FittingMethod& fittingMethod,
Real accuracy = 1.0e-10,
Size maxEvaluations = 10000,
const Array &guess = Array(),
Real simplexLambda = 1.0) {
return new FittedBondDiscountCurvePtr(
new FittedBondDiscountCurve(referenceDate,
convert_bond_helpers(helpers),
dayCounter,
fittingMethod,
accuracy,
maxEvaluations,
guess,
simplexLambda));
}
const FittingMethod& fitResults() const {
return boost::dynamic_pointer_cast<FittedBondDiscountCurve>(*self)
->fitResults();
}
}
};
%{
using QuantLib::ExponentialSplinesFitting;
using QuantLib::NelsonSiegelFitting;
using QuantLib::SvenssonFitting;
using QuantLib::CubicBSplinesFitting;
using QuantLib::SimplePolynomialFitting;
%}
class ExponentialSplinesFitting : public FittingMethod {
public:
ExponentialSplinesFitting(bool constrainAtZero = true,
const Array& weights = Array());
};
class NelsonSiegelFitting : public FittingMethod {
public:
NelsonSiegelFitting(const Array& weights = Array());
};
class SvenssonFitting : public FittingMethod {
public:
SvenssonFitting(const Array& weights = Array());
};
class CubicBSplinesFitting : public FittingMethod {
public:
CubicBSplinesFitting(const std::vector<Time>& knotVector,
bool constrainAtZero = true,
const Array& weights = Array());
Real basisFunction(Integer i, Time t);
};
class SimplePolynomialFitting : public FittingMethod {
public:
#if defined(SWIGJAVA)
SimplePolynomialFitting(Natural degree);
#else
SimplePolynomialFitting(Natural degree,
bool constrainAtZero = true,
const Array& weights = Array());
#endif
};
#endif