// Instrument interface public override void calculate() { if (discountCurve_.empty()) { throw new ArgumentException("no discounting term structure set"); } if (discountCurve_.Count != arguments_.legs.Count) { throw new ArgumentException("no discounting term structure set for all legs"); } results_.value = results_.cash = 0; results_.errorEstimate = null; results_.legNPV = new InitializedList <double?>(arguments_.legs.Count); results_.legBPS = new InitializedList <double?>(arguments_.legs.Count); List <double?> startDiscounts = new InitializedList <double?>(arguments_.legs.Count); for (int i = 0; i < arguments_.legs.Count; ++i) { results_.value += results_.legNPV[i]; results_.cash += arguments_.payer[i] * CashFlows.cash(arguments_.legs[i]); try { Date d = CashFlows.startDate(arguments_.legs[i]); startDiscounts[i] = discountCurve_[i].link.discount(d); } catch { startDiscounts[i] = null; } } results_.additionalResults.Add("startDiscounts", startDiscounts); }
public override void calculate() { List <CashFlow> cashflows = arguments_.cashflows; Date settlementDate = arguments_.settlementDate; Date valuationDate = discountCurve().link.referenceDate(); if (discountCurve().empty()) { throw new ApplicationException("no discounting term structure set"); } results_.value = CashFlows.npv(cashflows, discountCurve().link, valuationDate, valuationDate); results_.cash = CashFlows.cash(cashflows, settlementDate); results_.settlementValue = CashFlows.npv(cashflows, discountCurve().link, settlementDate, settlementDate); }
public override void calculate() { if (discountCurve_.empty()) { throw new ArgumentException("no discounting term structure set"); } results_.value = results_.cash = 0; results_.errorEstimate = null; results_.legNPV = new InitializedList <double?>(arguments_.legs.Count); for (int i = 0; i < arguments_.legs.Count; ++i) { results_.legNPV[i] = arguments_.payer[i] * CashFlows.npv(arguments_.legs[i], discountCurve_); results_.value += results_.legNPV[i]; results_.cash += arguments_.payer[i] * CashFlows.cash(arguments_.legs[i]); } }
public override void calculate() { if (_discountCurve.IsEmpty) { throw new ArgumentException("no discounting term structure set"); } results_.value = 0; results_.cash = 0; results_.errorEstimate = null; results_.legNPV.Clear(); for (int i = 0; i < arguments_.legs.Count; ++i) { results_.legNPV[i] = arguments_.payer[i] * CashFlows.npv(arguments_.legs[i], _discountCurve); results_.value += results_.legNPV[i]; results_.cash += arguments_.payer[i] * CashFlows.cash(arguments_.legs[i]); } }
public override void calculate() { Utils.QL_REQUIRE(!discountCurve_.empty(), "discounting term structure handle is empty"); results_.valuationDate = discountCurve_.link.referenceDate(); bool includeRefDateFlows = includeSettlementDateFlows_.HasValue ? includeSettlementDateFlows_.Value : Settings.includeReferenceDateEvents; results_.value = CashFlows.npv(arguments_.cashflows, discountCurve_, includeRefDateFlows, results_.valuationDate, results_.valuationDate); results_.cash = CashFlows.cash(arguments_.cashflows, arguments_.settlementDate); // a bond's cashflow on settlement date is never taken into // account, so we might have to play it safe and recalculate if (!includeRefDateFlows && results_.valuationDate == arguments_.settlementDate) { // same parameters as above, we can avoid another call results_.settlementValue = results_.value; } else { // no such luck results_.settlementValue = CashFlows.npv(arguments_.cashflows, discountCurve_, false, arguments_.settlementDate, arguments_.settlementDate); } }