Skip to content

Commit 4506e15

Browse files
nathaniel.volfangojenkins
authored andcommitted
QPR-12521, QPR-12538 -- Add CommodityForward cashflow to additional results, and clarify discount factor name, update tests
1 parent 2148087 commit 4506e15

2 files changed

Lines changed: 40 additions & 5 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

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)