Skip to content

Commit 0cf09a5

Browse files
author
jenkins
committed
git subrepo pull (merge) ore
subrepo: subdir: "ore" merged: "b66cf7d996" upstream: origin: "git@gitlab.acadiasoft.net:qs/ore.git" branch: "master" commit: "f90bfc655d" git-subrepo: version: "0.4.6" origin: "https://github.com/ingydotnet/git-subrepo" commit: "73a0129"
2 parents bbedf78 + f90bfc6 commit 0cf09a5

8 files changed

Lines changed: 62 additions & 47 deletions

File tree

OREAnalytics/orea/engine/marketriskbacktest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ const QuantLib::ext::shared_ptr<ore::data::Report>& MarketRiskBacktest::Backtest
4646
}
4747

4848
MarketRiskBacktest::MarketRiskBacktest(
49-
const std::string& baseCurrency,
49+
const std::string& calculationCurrency,
5050
std::unique_ptr<BacktestArgs> btArgs,
5151
std::unique_ptr<SensiRunArgs> sensiArgs,
5252
std::unique_ptr<FullRevalArgs> revalArgs,
5353
std::unique_ptr<MultiThreadArgs> mtArgs,
5454
const ext::shared_ptr<HistoricalScenarioGenerator>& hisScenGen,
5555
const bool breakdown,
5656
const bool requireTradePnl)
57-
: MarketRiskReport(baseCurrency, btArgs->backtestPeriod_, hisScenGen, std::move(sensiArgs), std::move(revalArgs),
57+
: MarketRiskReport(calculationCurrency, btArgs->backtestPeriod_, hisScenGen, std::move(sensiArgs), std::move(revalArgs),
5858
std::move(mtArgs), breakdown, requireTradePnl),
5959
btArgs_(std::move(btArgs)) {
6060
init();
@@ -370,7 +370,7 @@ void MarketRiskBacktest::reset(const QuantLib::ext::shared_ptr<MarketRiskGroup>&
370370

371371
void MarketRiskBacktest::addPnlRow(const QuantLib::ext::shared_ptr<BacktestReports>& reports, Size scenarioIdx,
372372
bool isCall, const RiskFactorKey& key_1, Real shift_1, Real delta, Real gamma, Real deltaPnl, Real gammaPnl,
373-
const RiskFactorKey& key_2, Real shift_2, const string& tradeId) {
373+
const RiskFactorKey& key_2, Real shift_2, const string& tradeId, const string& currency, Real fxSpot) {
374374

375375
// Do we have a report to write to?
376376
// Is this too slow to do on every call to addPnlRow? Need to find the report each time in any case.
@@ -401,9 +401,9 @@ void MarketRiskBacktest::addPnlRow(const QuantLib::ext::shared_ptr<BacktestRepor
401401
.add(gamma)
402402
.add(shift_1)
403403
.add(shift_2)
404-
.add(deltaPnl)
405-
.add(gammaPnl)
406-
.add(baseCurrency_);
404+
.add(currency.empty() || currency == calculationCurrency_ ? deltaPnl : deltaPnl / fxSpot)
405+
.add(currency.empty() || currency == calculationCurrency_ ? gammaPnl : gammaPnl / fxSpot)
406+
.add(currency.empty() ? calculationCurrency_ : currency);
407407
}
408408

409409
void BacktestPNLCalculator::writePNL(Size scenarioIdx, bool isCall, const RiskFactorKey& key_1, Real shift_1,

OREAnalytics/orea/engine/marketriskbacktest.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class MarketRiskBacktest : public ore::analytics::MarketRiskReport {
122122
void reset() { var = 0.0; }
123123
};
124124

125-
MarketRiskBacktest(const std::string& baseCurrency,
125+
MarketRiskBacktest(const std::string& calculationCurrency,
126126
std::unique_ptr<BacktestArgs> btArgs,
127127
std::unique_ptr<SensiRunArgs> sensiArgs = nullptr,
128128
std::unique_ptr<FullRevalArgs> revalArgs = nullptr,
@@ -142,10 +142,11 @@ class MarketRiskBacktest : public ore::analytics::MarketRiskReport {
142142

143143
//! Add a row to the P&L contribution report
144144
virtual void addPnlRow(const QuantLib::ext::shared_ptr<BacktestReports>& reports, QuantLib::Size scenarioIdx,
145-
bool isCall,
146-
const ore::analytics::RiskFactorKey& key_1, QuantLib::Real shift_1, QuantLib::Real delta, QuantLib::Real gamma,
147-
QuantLib::Real deltaPnl, QuantLib::Real gammaPnl, const ore::analytics::RiskFactorKey& key_2 = ore::analytics::RiskFactorKey(),
148-
QuantLib::Real shift_2 = 0.0, const std::string& tradeId = "");
145+
bool isCall, const ore::analytics::RiskFactorKey& key_1, QuantLib::Real shift_1,
146+
QuantLib::Real delta, QuantLib::Real gamma, QuantLib::Real deltaPnl, QuantLib::Real gammaPnl,
147+
const ore::analytics::RiskFactorKey& key_2 = ore::analytics::RiskFactorKey(),
148+
QuantLib::Real shift_2 = 0.0, const std::string& tradeId = "",
149+
const std::string& currency = "", QuantLib::Real fxSpot = 1.0);
149150

150151
protected:
151152
std::unique_ptr<BacktestArgs> btArgs_;

OREAnalytics/orea/engine/marketriskreport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ void MarketRiskReport::init() {
8383
vector<Date>(1, fullRevalArgs_->simMarket_->asofDate()), hisScenGen_->numScenarios());
8484

8585
histPnlGen_ = QuantLib::ext::make_shared<HistoricalPnlGenerator>(
86-
baseCurrency_, fullRevalArgs_->portfolio_, fullRevalArgs_->simMarket_,
86+
calculationCurrency_, fullRevalArgs_->portfolio_, fullRevalArgs_->simMarket_,
8787
hisScenGen_, cube, factory_->modelBuilders(), fullRevalArgs_->dryRun_);
8888
} else {
8989
histPnlGen_ = QuantLib::ext::make_shared<HistoricalPnlGenerator>(
90-
baseCurrency_, fullRevalArgs_->portfolio_, hisScenGen_,
90+
calculationCurrency_, fullRevalArgs_->portfolio_, hisScenGen_,
9191
fullRevalArgs_->engineData_,
9292
multiThreadArgs_->nThreads_, multiThreadArgs_->today_, multiThreadArgs_->loader_,
9393
multiThreadArgs_->curveConfigs_, multiThreadArgs_->todaysMarketParams_,

OREAnalytics/orea/engine/marketriskreport.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,15 @@ class MarketRiskReport : public ore::data::ProgressReporter {
154154
std::vector<QuantLib::ext::shared_ptr<ore::data::Report>> reports_;
155155
};
156156

157-
MarketRiskReport(const std::string& baseCurrency, boost::optional<ore::data::TimePeriod> period, const QuantLib::ext::shared_ptr<HistoricalScenarioGenerator>& hisScenGen = nullptr,
158-
std::unique_ptr<SensiRunArgs> sensiArgs = nullptr, std::unique_ptr<FullRevalArgs> fullRevalArgs = nullptr,
159-
std::unique_ptr<MultiThreadArgs> multiThreadArgs = nullptr, const bool breakdown = false,
160-
const bool requireTradePnl = false)
161-
: baseCurrency_(baseCurrency), period_(period), hisScenGen_(hisScenGen), sensiArgs_(std::move(sensiArgs)),
162-
fullRevalArgs_(std::move(fullRevalArgs)), multiThreadArgs_(std::move(multiThreadArgs)), breakdown_(breakdown),
163-
requireTradePnl_(requireTradePnl) {}
157+
MarketRiskReport(const std::string& calculationCurrency, boost::optional<ore::data::TimePeriod> period,
158+
const QuantLib::ext::shared_ptr<HistoricalScenarioGenerator>& hisScenGen = nullptr,
159+
std::unique_ptr<SensiRunArgs> sensiArgs = nullptr,
160+
std::unique_ptr<FullRevalArgs> fullRevalArgs = nullptr,
161+
std::unique_ptr<MultiThreadArgs> multiThreadArgs = nullptr, const bool breakdown = false,
162+
const bool requireTradePnl = false)
163+
: calculationCurrency_(calculationCurrency), period_(period), hisScenGen_(hisScenGen),
164+
sensiArgs_(std::move(sensiArgs)), fullRevalArgs_(std::move(fullRevalArgs)),
165+
multiThreadArgs_(std::move(multiThreadArgs)), breakdown_(breakdown), requireTradePnl_(requireTradePnl) {}
164166
virtual ~MarketRiskReport() {}
165167

166168
virtual void init();
@@ -183,7 +185,7 @@ class MarketRiskReport : public ore::data::ProgressReporter {
183185
bool sensiBased_ = false;
184186
bool fullReval_ = false;
185187

186-
std::string baseCurrency_;
188+
std::string calculationCurrency_;
187189
boost::optional<ore::data::TimePeriod> period_;
188190
QuantLib::ext::shared_ptr<HistoricalScenarioGenerator> hisScenGen_;
189191
std::unique_ptr<SensiRunArgs> sensiArgs_;

OREAnalytics/orea/simm/simmresults.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,41 @@ namespace analytics {
3535
void SimmResults::add(const CrifRecord::ProductClass& pc, const SimmConfiguration::RiskClass& rc,
3636
const SimmConfiguration::MarginType& mt, const string& b, Real im, const string& resultCurrency,
3737
const string& calculationCurrency, const bool overwrite) {
38+
if (!(mt == SimmConfiguration::MarginType::AdditionalIM || mt == SimmConfiguration::MarginType::All))
39+
QL_REQUIRE(im >= 0.0, "Cannot add negative IM " << im << " result to SimmResults for RiskClass=" << rc
40+
<< ", MarginType=" << mt << ", and Bucket=" << b);
3841

39-
// Add the value as long as the currencies are matching. If the SimmResults container does not yet have
40-
// a currency, we set it to be that of the incoming value
41-
if (resultCcy_.empty())
42-
resultCcy_ = resultCurrency;
43-
else
44-
QL_REQUIRE(resultCurrency == resultCcy_, "Cannot add value to SimmResults with a different result currency ("
45-
<< resultCurrency << "). Expected " << resultCcy_ << ".");
46-
47-
if (calcCcy_.empty())
48-
calcCcy_ = calculationCurrency;
49-
else
50-
QL_REQUIRE(calculationCurrency == calcCcy_, "Cannot add value to SimmResults in a different calculation currency ("
51-
<< calculationCurrency << "). Expected " << calcCcy_ << ".");
52-
53-
if (!(mt == SimmConfiguration::MarginType::AdditionalIM || mt == SimmConfiguration::MarginType::All))
54-
QL_REQUIRE(im >= 0.0, "Cannot add negative IM " << im << " result to SimmResults for RiskClass=" << rc
55-
<< ", MarginType=" << mt << ", and Bucket=" << b);
56-
57-
const auto key = make_tuple(pc, rc, mt, b);
58-
const bool hasResults = data_.find(key) != data_.end();
59-
if (hasResults && !overwrite)
60-
data_[key] += im;
61-
else
62-
data_[key] = im;
42+
const auto key = make_tuple(pc, rc, mt, b);
43+
add(key, im, resultCurrency, calculationCurrency, overwrite);
6344
}
6445

46+
47+
void SimmResults::add(const SimmResults::Key& key, QuantLib::Real im, const std::string& resultCurrency,
48+
const std::string& calculationCurrency, const bool overwrite) {
49+
// Add the value as long as the currencies are matching. If the SimmResults container does not yet have
50+
// a currency, we set it to be that of the incoming value
51+
if (resultCcy_.empty())
52+
resultCcy_ = resultCurrency;
53+
else
54+
QL_REQUIRE(resultCurrency == resultCcy_,
55+
"Cannot add value to SimmResults with a different result currency ("
56+
<< resultCurrency << "). Expected " << resultCcy_ << ".");
57+
58+
if (calcCcy_.empty())
59+
calcCcy_ = calculationCurrency;
60+
else
61+
QL_REQUIRE(calculationCurrency == calcCcy_,
62+
"Cannot add value to SimmResults in a different calculation currency ("
63+
<< calculationCurrency << "). Expected " << calcCcy_ << ".");
64+
65+
const bool hasResults = data_.find(key) != data_.end();
66+
if (hasResults && !overwrite)
67+
data_[key] += im;
68+
else
69+
data_[key] = im;
70+
}
71+
72+
6573
void SimmResults::convert(const QuantLib::ext::shared_ptr<ore::data::Market>& market, const string& currency) {
6674
// Get corresponding FX spot rate
6775
Real fxSpot = market->fxRate(resultCcy_ + currency)->value();

OREAnalytics/orea/simm/simmresults.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class SimmResults {
5656
const SimmConfiguration::MarginType& mt, const std::string& b, QuantLib::Real im,
5757
const std::string& resultCurrency, const std::string& calculationCurrency, const bool overwrite);
5858

59+
void add(const Key& key, QuantLib::Real im, const std::string& resultCurrency,
60+
const std::string& calculationCurrency, const bool overwrite);
61+
5962
//! Convert SIMM amounts to a different currency
6063
void convert(const QuantLib::ext::shared_ptr<ore::data::Market>& market, const std::string& currency);
6164
void convert(QuantLib::Real fxSpot, const std::string& currency);

OREData/ored/scripting/models/gaussiancam.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ RandomVariable GaussianCam::npv(const RandomVariable& amount, const Date& obsdat
658658
// store model if requried
659659

660660
if (memSlot) {
661-
storedRegressionModel_[*memSlot] = std::make_tuple(coeff, nModelStates, coordinateTransform);
661+
storedRegressionModel_[*memSlot] = std::make_tuple(coeff, nModelStates + nAddReg, coordinateTransform);
662662
}
663663

664664
} else {

Tools/PythonTools/comparison_config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@
636636
"GreenUpTo",
637637
"AmberUpTo",
638638
"Zone",
639-
"Currency",
639+
"DiscountingCurrency",
640+
"SIMMResultCurrency",
640641
"SIMMCalculationCurrency"
641642
],
642643
"abs_tol": null,

0 commit comments

Comments
 (0)