@@ -45,14 +45,14 @@ CommodityIndexedAverageCashFlow::CommodityIndexedAverageCashFlow(
4545 const ext::shared_ptr<FutureExpiryCalculator>& calc, bool includeEndDate, bool excludeStartDate,
4646 bool useBusinessDays, CommodityQuantityFrequency quantityFrequency, Natural hoursPerDay, Natural dailyExpiryOffset,
4747 bool unrealisedQuantity, const boost::optional<pair<Calendar, Real>>& offPeakPowerData,
48- const ext::shared_ptr<FxIndex>& fxIndex)
48+ const ext::shared_ptr<FxIndex>& fxIndex, QuantLib::Natural avgPricePrecision )
4949 : CommodityCashFlow(quantity, spread, gearing, useFuturePrice, index, fxIndex), startDate_(startDate),
5050 endDate_ (endDate),
5151 paymentDate_(paymentDate), pricingCalendar_(pricingCalendar), deliveryDateRoll_(deliveryDateRoll),
5252 futureMonthOffset_(futureMonthOffset), includeEndDate_(includeEndDate), excludeStartDate_(excludeStartDate),
5353 useBusinessDays_(useBusinessDays), quantityFrequency_(quantityFrequency), hoursPerDay_(hoursPerDay),
5454 dailyExpiryOffset_(dailyExpiryOffset), unrealisedQuantity_(unrealisedQuantity),
55- offPeakPowerData_(offPeakPowerData) {
55+ offPeakPowerData_(offPeakPowerData), avgPricePrecision_(avgPricePrecision) {
5656 init (calc);
5757}
5858
@@ -64,13 +64,14 @@ CommodityIndexedAverageCashFlow::CommodityIndexedAverageCashFlow(
6464 const ext::shared_ptr<FutureExpiryCalculator>& calc, bool includeEndDate, bool excludeStartDate,
6565 const QuantLib::Date& paymentDateOverride, bool useBusinessDays, CommodityQuantityFrequency quantityFrequency,
6666 Natural hoursPerDay, Natural dailyExpiryOffset, bool unrealisedQuantity,
67- const boost::optional<pair<Calendar, Real>>& offPeakPowerData, const ext::shared_ptr<FxIndex>& fxIndex)
67+ const boost::optional<pair<Calendar, Real>>& offPeakPowerData, const ext::shared_ptr<FxIndex>& fxIndex,
68+ QuantLib::Natural avgPricePrecision)
6869 : CommodityCashFlow(quantity, spread, gearing, useFuturePrice, index, fxIndex), startDate_(startDate), endDate_(endDate),
6970 paymentDate_(paymentDateOverride), pricingCalendar_(pricingCalendar),
7071 deliveryDateRoll_(deliveryDateRoll), futureMonthOffset_(futureMonthOffset), includeEndDate_(includeEndDate),
7172 excludeStartDate_(excludeStartDate), useBusinessDays_(useBusinessDays), quantityFrequency_(quantityFrequency),
7273 hoursPerDay_(hoursPerDay), dailyExpiryOffset_(dailyExpiryOffset), unrealisedQuantity_(unrealisedQuantity),
73- offPeakPowerData_(offPeakPowerData) {
74+ offPeakPowerData_(offPeakPowerData), avgPricePrecision_(avgPricePrecision) {
7475
7576 // Derive the payment date
7677 if (paymentDate_ == Date ()) {
@@ -100,6 +101,11 @@ void CommodityIndexedAverageCashFlow::performCalculations() const {
100101 }
101102 }
102103
104+ if (avgPricePrecision_ != QuantLib::Null<QuantLib::Natural>()) {
105+ QuantLib::ClosestRounding round (avgPricePrecision_);
106+ averagePrice_ = round (averagePrice_);
107+ }
108+
103109 // Amount is just average price times quantity
104110 // In case of Foreign currency settlement, the spread must be expressed in Foreign currency units
105111 amount_ = periodQuantity_ * (gearing_ * averagePrice_ + spread_);
@@ -284,7 +290,7 @@ CommodityIndexedAverageLeg::CommodityIndexedAverageLeg(const Schedule& schedule,
284290 deliveryDateRoll_(0 ), futureMonthOffset_(0 ), payAtMaturity_(false ), includeEndDate_(true ),
285291 excludeStartDate_(true ), useBusinessDays_(true ),
286292 quantityFrequency_(CommodityQuantityFrequency::PerCalculationPeriod), hoursPerDay_(Null<Natural>()),
287- dailyExpiryOffset_(Null<Natural>()), unrealisedQuantity_(false ) {}
293+ dailyExpiryOffset_(Null<Natural>()), unrealisedQuantity_(false ), avgPricePrecision_(Null<Natural>()) {}
288294
289295CommodityIndexedAverageLeg& CommodityIndexedAverageLeg::withQuantities (Real quantity) {
290296 quantities_ = vector<Real>(1 , quantity);
@@ -419,6 +425,11 @@ CommodityIndexedAverageLeg& CommodityIndexedAverageLeg::withOffPeakPowerData(con
419425 return *this ;
420426}
421427
428+ CommodityIndexedAverageLeg& CommodityIndexedAverageLeg::withAvgPricePrecision (QuantLib::Natural precision){
429+ avgPricePrecision_ = precision;
430+ return *this ;
431+ }
432+
422433CommodityIndexedAverageLeg::operator Leg () const {
423434
424435 // Number of commodity indexed average cashflows
@@ -469,7 +480,7 @@ CommodityIndexedAverageLeg::operator Leg() const {
469480 quantity, start, end, paymentLag_, paymentCalendar_, paymentConvention_, index_, pricingCalendar_, spread,
470481 gearing, paymentTiming_, useFuturePrice_, deliveryDateRoll_, futureMonthOffset_, calc_, includeEnd,
471482 excludeStart, paymentDate, useBusinessDays_, quantityFrequency_, hoursPerDay_, dailyExpiryOffset_,
472- unrealisedQuantity_, offPeakPowerData_, fxIndex_));
483+ unrealisedQuantity_, offPeakPowerData_, fxIndex_, avgPricePrecision_ ));
473484 }
474485
475486 return leg;
0 commit comments