Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
FixingManager Class Reference

Pseudo Fixings Manager. More...

#include <orea/simulation/fixingmanager.hpp>

+ Collaboration diagram for FixingManager:

Public Types

using FixingMap = std::map< QuantLib::ext::shared_ptr< Index >, std::set< Date >, detail::IndexComparator >
 Cashflow handler type definitions. More...
 

Public Member Functions

 FixingManager (Date today)
 
virtual ~FixingManager ()
 
void initialise (const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< Market > &market, const std::string &configuration=Market::defaultConfiguration)
 Initialise the manager with these flows and indices from the given portfolio. More...
 
void update (Date d)
 Update fixings to date d. More...
 
void reset ()
 Reset fixings to t0 (today) More...
 

Private Types

using FixingCache = std::map< QuantLib::ext::shared_ptr< Index >, TimeSeries< Real >, detail::IndexComparator >
 

Private Member Functions

void applyFixings (Date start, Date end)
 

Private Attributes

Date today_
 
Date fixingsEnd_
 
bool modifiedFixingHistory_
 
FixingMap fixingMap_
 
FixingCache fixingCache_
 

Detailed Description

Pseudo Fixings Manager.

A Pseudo Fixing is a future historical fixing. When pricing on T0 but asof T and we require a fixing on t with T0 < t < T then the QuantLib pricing engines will look to the IndexManager for a fixing at t.

When moving between dates and simulation paths then the Fixings can change and should be populated in a path consistent manner

The FixingManager controls this updating and reset of the QuantLib::IndexManager for the required set of fixings

When stepping between simulation dated t_(n-1) and t_(n) and update a fixing t with t_(n-1) < t < t(n) than the fixing from t(n) will be backfilled. There is currently no interpolation of fixings.

Definition at line 57 of file fixingmanager.hpp.

Member Typedef Documentation

◆ FixingMap

using FixingMap = std::map<QuantLib::ext::shared_ptr<Index>, std::set<Date>, detail::IndexComparator>

Cashflow handler type definitions.

Definition at line 74 of file fixingmanager.hpp.

◆ FixingCache

using FixingCache = std::map<QuantLib::ext::shared_ptr<Index>, TimeSeries<Real>, detail::IndexComparator>
private

Definition at line 82 of file fixingmanager.hpp.

Constructor & Destructor Documentation

◆ FixingManager()

FixingManager ( Date  today)
explicit

◆ ~FixingManager()

virtual ~FixingManager ( )
virtual

Definition at line 60 of file fixingmanager.hpp.

60{}

Member Function Documentation

◆ initialise()

void initialise ( const QuantLib::ext::shared_ptr< Portfolio > &  portfolio,
const QuantLib::ext::shared_ptr< Market > &  market,
const std::string &  configuration = Market::defaultConfiguration 
)

Initialise the manager with these flows and indices from the given portfolio.

Initialise the manager-.

Definition at line 65 of file fixingmanager.cpp.

66 {
67
68 // populate the map "Index -> set of required fixing dates", where the index on the LHS is linked to curves
69 for (auto const& [tradeId,t] : portfolio->trades()) {
70 auto r = t->requiredFixings();
71 r.unsetPayDates();
72 for (auto const& [name, fixingDates] : r.fixingDatesIndices(QuantLib::Date::maxDate())) {
73 std::set<Date> dates;
74 for (const auto& [d, _] : fixingDates) {
75 dates.insert(d);
76 }
77 try {
78 auto rawIndex = parseIndex(name);
79 if (auto index = QuantLib::ext::dynamic_pointer_cast<EquityIndex2>(rawIndex)) {
80
81 fixingMap_[*market->equityCurve(index->familyName(), configuration)].insert(dates.begin(),
82 dates.end());
83 } else if (auto index = QuantLib::ext::dynamic_pointer_cast<BondIndex>(rawIndex)) {
84 QL_FAIL("BondIndex not handled");
85 } else if (auto index = QuantLib::ext::dynamic_pointer_cast<CommodityIndex>(rawIndex)) {
86 // for comm indices with non-daily expiries the expiry date's day of month is 1 always
87 Date safeExpiryDate = index->expiryDate();
88 if (safeExpiryDate != Date() && !index->keepDays()) {
89 safeExpiryDate = Date::endOfMonth(safeExpiryDate);
90 }
91 fixingMap_[index->clone(safeExpiryDate,
92 market->commodityPriceCurve(index->underlyingName(), configuration))]
93 .insert(dates.begin(), dates.end());
94 } else if (auto index = QuantLib::ext::dynamic_pointer_cast<FxIndex>(rawIndex)) {
95 fixingMap_[*market->fxIndex(index->oreName(), configuration)].insert(dates.begin(), dates.end());
96 } else if (auto index = QuantLib::ext::dynamic_pointer_cast<GenericIndex>(rawIndex)) {
97 QL_FAIL("GenericIndex not handled");
98 } else if (auto index = QuantLib::ext::dynamic_pointer_cast<ConstantMaturityBondIndex>(rawIndex)) {
99 QL_FAIL("ConstantMaturityBondIndex not handled");
100 } else if (auto index = QuantLib::ext::dynamic_pointer_cast<IborIndex>(rawIndex)) {
101 fixingMap_[*market->iborIndex(name, configuration)].insert(dates.begin(), dates.end());
102 } else if (auto index = QuantLib::ext::dynamic_pointer_cast<SwapIndex>(rawIndex)) {
103 fixingMap_[*market->swapIndex(name, configuration)].insert(dates.begin(), dates.end());
104 } else if (auto index = QuantLib::ext::dynamic_pointer_cast<ZeroInflationIndex>(rawIndex)) {
105 fixingMap_[*market->zeroInflationIndex(name, configuration)].insert(dates.begin(), dates.end());
106 }
107 } catch (const std::exception& e) {
108 ALOG("FixingManager: error " << e.what() << " - no fixings are added for '" << name << "'");
109 }
110 TLOG("Added " << dates.size() << " fixing dates for '" << name << "'");
111 }
112 }
113
114 // Now cache the original fixings so we can re-write on reset()
115 for (auto const& m : fixingMap_) {
116 fixingCache_[m.first] = IndexManager::instance().getHistory(m.first->name());
117 }
118}
QuantLib::ext::shared_ptr< Index > parseIndex(const string &s)
#define ALOG(text)
#define TLOG(text)
+ Here is the call graph for this function:

◆ update()

void update ( Date  d)

Update fixings to date d.

Definition at line 121 of file fixingmanager.cpp.

121 {
122 if (!fixingMap_.empty()) {
123 QL_REQUIRE(d >= fixingsEnd_, "Can't go back in time, fixings must be reset."
124 " Update date "
125 << d << " but current fixings go to " << fixingsEnd_);
126 if (d > fixingsEnd_)
128 }
129 fixingsEnd_ = d;
130}
void applyFixings(Date start, Date end)
+ Here is the call graph for this function:

◆ reset()

void reset ( )

Reset fixings to t0 (today)

Definition at line 133 of file fixingmanager.cpp.

133 {
135 for (auto& kv : fixingCache_)
136 IndexManager::instance().setHistory(kv.first->name(), kv.second);
138 }
140}

◆ applyFixings()

void applyFixings ( Date  start,
Date  end 
)
private

Definition at line 142 of file fixingmanager.cpp.

142 {
143 // Loop over all indices
144 for (auto const& m : fixingMap_) {
145 Date fixStart = start;
146 Date fixEnd = end;
147 Date currentFixingDate;
148 if (auto zii = QuantLib::ext::dynamic_pointer_cast<ZeroInflationIndex>(m.first)) {
149 fixStart =
150 inflationPeriod(fixStart - zii->zeroInflationTermStructure()->observationLag(), zii->frequency()).first;
151 fixEnd =
152 inflationPeriod(fixEnd - zii->zeroInflationTermStructure()->observationLag(), zii->frequency()).first +
153 1;
154 currentFixingDate = fixEnd;
155 } else if (auto yii = QuantLib::ext::dynamic_pointer_cast<YoYInflationIndex>(m.first)) {
156 fixStart =
157 inflationPeriod(fixStart - yii->yoyInflationTermStructure()->observationLag(), yii->frequency()).first;
158 fixEnd =
159 inflationPeriod(fixEnd - yii->yoyInflationTermStructure()->observationLag(), yii->frequency()).first +
160 1;
161 currentFixingDate = fixEnd;
162 } else {
163 currentFixingDate = m.first->fixingCalendar().adjust(fixEnd, Following);
164 // This date is a business day but may not be a valid fixing date in case of BMA/SIFMA
165 if (!m.first->isValidFixingDate(currentFixingDate))
166 currentFixingDate = nextValidFixingDate(currentFixingDate, m.first);
167 }
168
169 // Add we have a coupon between start and asof.
170 bool needFixings = false;
171 for (auto const& d : m.second) {
172 if (d >= fixStart && d < fixEnd) {
173 needFixings = true;
174 break;
175 }
176 }
177
178 if (needFixings) {
179 Rate currentFixing;
180 if (auto comm = QuantLib::ext::dynamic_pointer_cast<QuantExt::CommodityIndex>(m.first);
181 comm != nullptr && comm->expiryDate() < currentFixingDate) {
182 currentFixing = comm->priceCurve()->price(currentFixingDate);
183 } else {
184 currentFixing = m.first->fixing(currentFixingDate);
185 }
186 // if we read the fixing from an inverted FxIndex we have to undo the inversion
187 TimeSeries<Real> history;
188 for (auto const& d : m.second) {
189 if (d >= fixStart && d < fixEnd) {
190 // Fixing dates include the valuation grid dates which might not be valid fixing dates (BMA/SIFMA)
191 bool valid = m.first->isValidFixingDate(d);
192 if (valid) {
193 history[d] = currentFixing;
195 }
196 }
197 if (d >= fixEnd)
198 break;
199 }
200 m.first->addFixings(history, true);
201 }
202 }
203}
Date nextValidFixingDate(Date d, const QuantLib::ext::shared_ptr< Index > &index, Size gap=7)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ today_

Date today_
private

Definition at line 79 of file fixingmanager.hpp.

◆ fixingsEnd_

Date fixingsEnd_
private

Definition at line 79 of file fixingmanager.hpp.

◆ modifiedFixingHistory_

bool modifiedFixingHistory_
private

Definition at line 80 of file fixingmanager.hpp.

◆ fixingMap_

FixingMap fixingMap_
private

Definition at line 84 of file fixingmanager.hpp.

◆ fixingCache_

FixingCache fixingCache_
private

Definition at line 85 of file fixingmanager.hpp.