-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPiecewiseCurveBuilder.cpp
More file actions
85 lines (85 loc) · 3.08 KB
/
PiecewiseCurveBuilder.cpp
File metadata and controls
85 lines (85 loc) · 3.08 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
// PiecewiseCurveBuilder.cpp
#pragma once
#include "PiecewiseCurveBuilder.h"
//
template <class T>
PiecewiseCurveBuilder<T>::PiecewiseCurveBuilder(Date settlementDate,
Calendar calendar, Frequency fixedLegFrequency, DayCounter fixedLegDayCounter)
{
this->settlementDate = settlementDate;
this->calendar = calendar;
this->fixedLegFrequency = fixedLegFrequency;
this->fixedLegDayCounter = fixedLegDayCounter;
boost::shared_ptr<IborIndex> index(new T(3 * Months));
dayCounter = index->dayCounter();
businessDayConvention = index->businessDayConvention();
}
template <class T>
void PiecewiseCurveBuilder<T>::AddDeposit(boost::shared_ptr<Quote>& quote, Period periodLength)
{
// using third DepositRateHelper constructor
boost::shared_ptr<RateHelper> rateHelper(new DepositRateHelper(
Handle<Quote>(quote), boost::shared_ptr<IborIndex>(new T(periodLength))));
rateHelpers.push_back(rateHelper);
}
template <class T>
void PiecewiseCurveBuilder<T>::AddDeposit(Rate quote, Period periodLength)
{
// using second DepositRateHelper constructor
boost::shared_ptr<RateHelper> rateHelper(new DepositRateHelper(
quote, boost::shared_ptr<IborIndex>(new T(periodLength))));
rateHelpers.push_back(rateHelper);
}
template <class T>
void PiecewiseCurveBuilder<T>::AddFRA(boost::shared_ptr<Quote>& quote,
Period periodLengthToStart, Period periodLength)
{
// using seventh FraRateHelper constructor
boost::shared_ptr<RateHelper> rateHelper(new FraRateHelper(
Handle<Quote>(quote), periodLengthToStart,
boost::shared_ptr<IborIndex>(new T(periodLength))));
rateHelpers.push_back(rateHelper);
}
template <class T>
void PiecewiseCurveBuilder<T>::AddFRA(Rate quote,
Period periodLengthToStart, Period periodLength)
{
// using third FraRateHelper constructor
boost::shared_ptr<RateHelper> rateHelper(new FraRateHelper(
quote, periodLengthToStart,
boost::shared_ptr<IborIndex>(new T(periodLength))));
rateHelpers.push_back(rateHelper);
}
template <class T>
void PiecewiseCurveBuilder<T>::AddSwap(boost::shared_ptr<Quote>& quote,
Period periodLength)
{
// using fifth SwapRateHelper constructor
boost::shared_ptr<IborIndex> index(new T(periodLength));
boost::shared_ptr<RateHelper> rateHelper(new SwapRateHelper(
Handle<Quote>(quote), periodLength, calendar, fixedLegFrequency,
businessDayConvention, fixedLegDayCounter, index));
rateHelpers.push_back(rateHelper);
}
template <class T>
void PiecewiseCurveBuilder<T>::AddSwap(Rate quote,
Period periodLength)
{
// using fourth SwapRateHelper constructor
boost::shared_ptr<IborIndex> index(new T(periodLength));
boost::shared_ptr<RateHelper> rateHelper(new SwapRateHelper(
quote, periodLength, calendar, fixedLegFrequency,
businessDayConvention, fixedLegDayCounter, index));
rateHelpers.push_back(rateHelper);
}
template <class T>
RelinkableHandle<YieldTermStructure> PiecewiseCurveBuilder<T>::GetCurveHandle()
{
if(yieldTermStructure == NULL)
{
yieldTermStructure = boost::shared_ptr<YieldTermStructure>(
new PiecewiseYieldCurve<Discount, LogLinear>(
settlementDate, rateHelpers, dayCounter));
}
return RelinkableHandle<YieldTermStructure>(yieldTermStructure);
}