Skip to content

Commit c7388b7

Browse files
author
jenkins
committed
git subrepo pull (merge) ore
subrepo: subdir: "ore" merged: "09a09e3d19" upstream: origin: "git@gitlab.acadiasoft.net:qs/ore.git" branch: "master" commit: "4506e15914" git-subrepo: version: "0.4.6" origin: "https://github.com/ingydotnet/git-subrepo" commit: "73a0129"
2 parents b90d30e + 4506e15 commit c7388b7

5 files changed

Lines changed: 58 additions & 22 deletions

File tree

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
#TradeId,Type,CashflowNo,LegNo,PayDate,FlowType,Amount,Currency,Coupon,Accrual,AccrualStartDate,AccrualEndDate,AccruedAmount,fixingDate,fixingValue,Notional,DiscountFactor,PresentValue,FXRate(Local-Base),PresentValue(Base),BaseCurrency,FloorStrike,CapStrike,FloorVolatility,CapVolatility
1+
#TradeId,Type,CashflowNo,LegNo,PayDate,FlowType,Amount,Currency,Coupon,Accrual,AccrualStartDate,AccrualEndDate,AccruedAmount,fixingDate,fixingValue,Notional,DiscountFactor,PresentValue,FXRate(Local-Base),PresentValue(Base),BaseCurrency,FloorStrike,CapStrike,FloorVolatility,CapVolatility,EffectiveFloorVolatility,EffectiveCapVolatility
2+
CommodityForward_Gold_1Y,CommodityForward,1,0,#N/A,Notional,-1160593.3333,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,0.9943418517,-1154026.5240929599,1.0000000000,-1154026.5240929599,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A
3+
CommodityForward_Gold_1Y,CommodityForward,1,1,#N/A,Notional,1162000.0000,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,0.9943418517,1155425.2316309642,1.0000000000,1155425.2316309642,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A
4+
CommodityForward_Gold_Apr_17,CommodityForward,1,0,#N/A,Notional,580900.0000,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,0.9928024234,576718.9277435583,1.0000000000,576718.9277435583,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A
5+
CommodityForward_Gold_Apr_17,CommodityForward,1,1,#N/A,Notional,-580900.0000,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,0.9928024234,-576718.9277435583,1.0000000000,-576718.9277435583,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A
6+
CommodityForward_WTI_2Y,CommodityForward,1,0,#N/A,Notional,44308571.4286,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,0.9871068084,43737292.5278331637,1.0000000000,43737292.5278331637,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A
7+
CommodityForward_WTI_2Y,CommodityForward,1,1,#N/A,Notional,-46000000.0000,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,0.9871068084,-45406913.1866207123,1.0000000000,-45406913.1866207123,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A
8+
CommodityForward_WTI_Oct_21,CommodityForward,1,0,#N/A,Notional,-24875000.0000,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,0.9432249101,-23462719.6376393437,1.0000000000,-23462719.6376393437,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A
9+
CommodityForward_WTI_Oct_21,CommodityForward,1,1,#N/A,Notional,24875000.0000,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,0.9432249101,23462719.6376393437,1.0000000000,23462719.6376393437,USD,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A

OREData/ored/portfolio/collateralbalance.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ using ore::data::parseReal;
3030
namespace ore {
3131
namespace data {
3232

33-
void CollateralBalances::add(const QuantLib::ext::shared_ptr<CollateralBalance>& cb) {
34-
std::pair<NettingSetDetails, QuantLib::ext::shared_ptr<CollateralBalance>> newCollateralBalance(cb->nettingSetDetails(),
35-
cb);
36-
collateralBalances_.insert(newCollateralBalance);
33+
void CollateralBalances::add(const QuantLib::ext::shared_ptr<CollateralBalance>& cb, const bool overwrite) {
34+
if (collateralBalances_.find(cb->nettingSetDetails()) != collateralBalances_.end() && !overwrite)
35+
QL_FAIL("Cannot add collateral balances since it already exists and overwrite=false: " << cb->nettingSetDetails());
36+
37+
collateralBalances_[cb->nettingSetDetails()] = cb;
3738
}
3839

3940
bool CollateralBalances::has(const NettingSetDetails& nettingSetDetails) const {
@@ -84,8 +85,8 @@ void CollateralBalance::fromXML(XMLNode* node) {
8485
if (nettingSetDetailsNode) {
8586
nettingSetDetails_.fromXML(nettingSetDetailsNode);
8687
} else {
87-
nettingSetId_ = XMLUtils::getChildValue(node, "NettingSetId", false);
88-
nettingSetDetails_ = NettingSetDetails(nettingSetId_);
88+
const string nettingSetId = XMLUtils::getChildValue(node, "NettingSetId", false);
89+
nettingSetDetails_ = NettingSetDetails(nettingSetId);
8990
}
9091

9192
currency_ = XMLUtils::getChildValue(node, "Currency", true);
@@ -111,8 +112,8 @@ void CollateralBalance::fromXML(XMLNode* node) {
111112
XMLNode* CollateralBalance::toXML(XMLDocument& doc) const {
112113
XMLNode* node = doc.allocNode("CollateralBalance");
113114
XMLUtils::addChild(doc, node, "Currency", currency_);
114-
if (nettingSetDetails_.empty()) {
115-
XMLUtils::addChild(doc, node, "NettingSetId", nettingSetId_);
115+
if (nettingSetDetails_.emptyOptionalFields()) {
116+
XMLUtils::addChild(doc, node, "NettingSetId", nettingSetDetails_.nettingSetId());
116117
} else {
117118
XMLUtils::appendNode(node, nettingSetDetails_.toXML(doc));
118119
}

OREData/ored/portfolio/collateralbalance.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,25 @@ class CollateralBalance : public ore::data::XMLSerializable {
3939
default constructor
4040
*/
4141
CollateralBalance()
42-
: nettingSetId_(""), nettingSetDetails_(NettingSetDetails()), currency_(""),
42+
: nettingSetDetails_(NettingSetDetails()), currency_(""),
4343
im_(QuantLib::Null<QuantLib::Real>()), vm_(QuantLib::Null<QuantLib::Real>()) {}
4444

4545
CollateralBalance(ore::data::XMLNode* node);
4646

47-
CollateralBalance(const std::string& nettingSetId, const std::string& currency,
47+
CollateralBalance(const NettingSetDetails& nettingSetDetails, const std::string& currency,
4848
const QuantLib::Real& im, const QuantLib::Real& vm = QuantLib::Null<QuantLib::Real>())
49-
: nettingSetId_(nettingSetId), nettingSetDetails_(NettingSetDetails()), currency_(currency),
50-
im_(im), vm_(vm) {}
49+
: nettingSetDetails_(nettingSetDetails), currency_(currency), im_(im), vm_(vm) {}
5150

52-
CollateralBalance(const NettingSetDetails& nettingSetDetails, const std::string& currency,
51+
CollateralBalance(const std::string& nettingSetId, const std::string& currency,
5352
const QuantLib::Real& im, const QuantLib::Real& vm = QuantLib::Null<QuantLib::Real>())
54-
: nettingSetId_(""), nettingSetDetails_(nettingSetDetails), currency_(currency), im_(im), vm_(vm) {}
53+
: CollateralBalance(NettingSetDetails(nettingSetId), currency, im, vm) {}
5554

5655
void fromXML(ore::data::XMLNode* node) override;
5756
ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
5857

5958
// Getters
6059
const std::string& nettingSetId() const {
61-
return (nettingSetDetails_.empty() ? nettingSetId_ : nettingSetDetails_.nettingSetId());
60+
return nettingSetDetails_.nettingSetId();
6261
}
6362
const NettingSetDetails nettingSetDetails() const { return nettingSetDetails_; }
6463
const std::string& currency() const { return currency_; }
@@ -70,7 +69,6 @@ class CollateralBalance : public ore::data::XMLSerializable {
7069
QuantLib::Real& variationMargin() { return vm_; }
7170

7271
private:
73-
std::string nettingSetId_;
7472
NettingSetDetails nettingSetDetails_;
7573
std::string currency_;
7674
QuantLib::Real im_, vm_;
@@ -112,7 +110,7 @@ class CollateralBalances : public ore::data::XMLSerializable {
112110
/*!
113111
adds a new collateral balance to manager
114112
*/
115-
void add(const QuantLib::ext::shared_ptr<CollateralBalance>& cb);
113+
void add(const QuantLib::ext::shared_ptr<CollateralBalance>& cb, const bool overwrite = false);
116114

117115
/*!
118116
extracts a collateral balance from manager

OREData/ored/portfolio/commodityswap.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ const std::map<std::string,boost::any>& CommoditySwap::additionalData() const {
197197
additionalData_["quantity[" + label + "]"] = indexedFlow->quantity();
198198
additionalData_["periodQuantity[" + label + "]"] = indexedFlow->periodQuantity();
199199
additionalData_["gearing[" + label + "]"] = indexedFlow->gearing();
200+
additionalData_["spread[" + label + "]"] = indexedFlow->spread();
200201
if (indexedFlow->isAveragingFrontMonthCashflow(asof)) {
201202
std::vector<Real> priceVec;
202203
std::vector<std::string> indexVec;
@@ -242,6 +243,7 @@ const std::map<std::string,boost::any>& CommoditySwap::additionalData() const {
242243
additionalData_["quantity[" + label + "]"] = indexedAvgFlow->quantity();
243244
additionalData_["periodQuantity[" + label + "]"] = indexedAvgFlow->periodQuantity();
244245
additionalData_["gearing[" + label + "]"] = indexedAvgFlow->gearing();
246+
additionalData_["spread[" + label + "]"] = indexedAvgFlow->spread();
245247
std::vector<Real> priceVec;
246248
std::vector<std::string> indexVec;
247249
std::vector<Date> indexExpiryVec, pricingDateVec;

QuantExt/qle/pricingengines/discountingcommodityforwardengine.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <ql/event.hpp>
2020

2121
#include <qle/pricingengines/discountingcommodityforwardengine.hpp>
22+
#include <qle/instruments/cashflowresults.hpp>
2223

2324
using namespace std;
2425
using namespace QuantLib;
@@ -55,11 +56,13 @@ void DiscountingCommodityForwardEngine::calculate() const {
5556

5657
Real buySell = arguments_.position == Position::Long ? 1.0 : -1.0;
5758
Real forwardPrice = index->fixing(maturity);
58-
Real discountPaymentDate = discountCurve_->discount(paymentDate);
59-
auto value = arguments_.quantity * buySell * (forwardPrice - arguments_.strike) * discountPaymentDate /
59+
Real paymentDateDiscountFactor = discountCurve_->discount(paymentDate);
60+
61+
auto value = arguments_.quantity * buySell * (forwardPrice - arguments_.strike) * paymentDateDiscountFactor /
6062
discountCurve_->discount(npvDate);
63+
Real fxRate = 1.0;
6164
if(arguments_.fxIndex && (arguments_.fixingDate!=Date()) && (arguments_.payCcy!=arguments_.currency)){ // NDF
62-
auto fxRate = arguments_.fxIndex->fixing(arguments_.fixingDate);
65+
fxRate = arguments_.fxIndex->fixing(arguments_.fixingDate);
6366
value*=fxRate;
6467
results_.additionalResults["productCurrency"] = arguments_.currency;
6568
results_.additionalResults["settlementCurrency"] = arguments_.payCcy;
@@ -68,7 +71,31 @@ void DiscountingCommodityForwardEngine::calculate() const {
6871
results_.value = value;
6972
results_.additionalResults["forwardPrice"] = forwardPrice;
7073
results_.additionalResults["currentNotional"] = forwardPrice * arguments_.quantity;
71-
results_.additionalResults["discountPaymentDate"] = discountPaymentDate;
74+
results_.additionalResults["paymentDateDiscountFactor"] = paymentDateDiscountFactor;
75+
76+
// populate cashflow results
77+
std::vector<CashFlowResults> cashFlowResults;
78+
CashFlowResults cf1, cf2;
79+
cf1.payDate = cf2.payDate = arguments_.paymentDate;
80+
cf1.type = cf2.type = "Notional";
81+
cf1.discountFactor = cf2.discountFactor = paymentDateDiscountFactor / discountCurve_->discount(npvDate);
82+
cf1.legNumber = 0;
83+
cf2.legNumber = 1;
84+
if (!arguments_.physicallySettled) {
85+
cf1.fixingDate = maturity;
86+
cf1.fixingValue = forwardPrice;
87+
cf1.amount = arguments_.quantity * buySell * forwardPrice * fxRate;
88+
cf2.amount = arguments_.quantity * buySell * -arguments_.strike * fxRate;
89+
cf1.currency = cf2.currency =
90+
arguments_.payCcy.empty() ? arguments_.currency.code() : arguments_.payCcy.code();
91+
} else {
92+
cf1.amount = arguments_.quantity * buySell * forwardPrice;
93+
cf2.amount = arguments_.quantity * buySell * -arguments_.strike;
94+
cf1.currency = cf2.currency = arguments_.currency.code();
95+
}
96+
cashFlowResults.push_back(cf1);
97+
cashFlowResults.push_back(cf2);
98+
results_.additionalResults["cashFlowResults"] = cashFlowResults;
7299
}
73100
}
74101

0 commit comments

Comments
 (0)