Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
scenariogeneratortransform.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20
21using namespace QuantLib;
22
23namespace ore {
24namespace analytics {
25
26QuantLib::ext::shared_ptr<Scenario> ScenarioGeneratorTransform::next(const Date& d) {
27 QuantLib::ext::shared_ptr<Scenario> scenario = scenarioGenerator_->next(d)->clone();
28 const vector<RiskFactorKey>& keys = simMarket_->baseScenario()->keys();
29 Date asof = simMarket_->baseScenario()->asof();
30 vector<Period> tenors;
31 Date endDate;
32 DayCounter dc;
33
34 for (Size k = 0; k < keys.size(); ++k) {
35 if ((keys[k].keytype == RiskFactorKey::KeyType::DiscountCurve) ||
36 (keys[k].keytype == RiskFactorKey::KeyType::IndexCurve) ||
37 (keys[k].keytype == RiskFactorKey::KeyType::YieldCurve)) {
38 Real df = scenario->get(keys[k]);
39 Real compound = 1 / df;
40 if ((keys[k].keytype == RiskFactorKey::KeyType::DiscountCurve)) {
41 dc = simMarket_->discountCurve(keys[k].name)->dayCounter();
42 tenors = simMarketConfig_->yieldCurveTenors(keys[k].name);
43 } else if (keys[k].keytype == RiskFactorKey::KeyType::IndexCurve ||
44 keys[k].keytype == RiskFactorKey::KeyType::YieldCurve) {
45 dc = simMarket_->iborIndex(keys[k].name)->dayCounter();
46 tenors = simMarketConfig_->yieldCurveTenors(keys[k].name);
47 }
48 endDate = asof + tenors[keys[k].index];
49 Real zero = InterestRate::impliedRate(compound, dc, QuantLib::Compounding::Continuous,
50 QuantLib::Frequency::Annual, asof, endDate)
51 .rate();
52 scenario->add(keys[k], zero);
53 }
54 }
55 return scenario;
56}
57
59
60} // namespace analytics
61} // namespace ore
QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > simMarketConfig_
QuantLib::ext::shared_ptr< ScenarioSimMarket > simMarket_
QuantLib::ext::shared_ptr< ScenarioGenerator > scenarioGenerator_
QuantLib::ext::shared_ptr< Scenario > next(const QuantLib::Date &d) override
void reset() override
Reset the generator so calls to next() return the first scenario.
Transformer class used for transform discount factors in the scenario into zero rates.
Date asof(14, Jun, 2018)
string name