public override void fetchResults(IPricingEngineResults r) { // copy from VanillaSwap // works because similarly simple instrument // that we always expect to be priced with a swap engine base.fetchResults(r); YearOnYearInflationSwap.Results results = r as YearOnYearInflationSwap.Results; if (results != null) { // might be a swap engine, so no error is thrown fairRate_ = results.fairRate; fairSpread_ = results.fairSpread; } else { fairRate_ = null; fairSpread_ = null; } if (fairRate_ == null) { // calculate it from other results if (legBPS_[0] != null) fairRate_ = fixedRate_ - NPV_ / (legBPS_[0] / Const.BASIS_POINT); } if (fairSpread_ == null) { // ditto if (legBPS_[1] != null) fairSpread_ = spread_ - NPV_ / (legBPS_[1] / Const.BASIS_POINT); } }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); LoanPricingEngineResults results = r as LoanPricingEngineResults; if (results == null) { throw new ArgumentException("wrong result type"); } if (results.legNPV.Count != 0) { if (results.legNPV.Count != legNPV_.Count) { throw new ArgumentException("wrong number of leg NPV returned"); } legNPV_ = results.legNPV; } else { legNPV_ = new InitializedList <double?>(legNPV_.Count); } }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); VanillaSwap.Results results = r as VanillaSwap.Results; if (results != null) { // might be a swap engine, so no error is thrown fairRate_ = results.fairRate; fairSpread_ = results.fairSpread; } else { fairRate_ = null; fairSpread_ = null; } if (fairRate_ == null) { // calculate it from other results if (legBPS_[0] != null) { fairRate_ = fixedRate_ - NPV_.GetValueOrDefault() / (legBPS_[0] / Const.BASIS_POINT); } } if (fairSpread_ == null) { // ditto if (legBPS_[1] != null) { fairSpread_ = spread_ - NPV_.GetValueOrDefault() / (legBPS_[1] / Const.BASIS_POINT); } } }
public override void fetchResults(IPricingEngineResults r) { const double basisPoint = 1.0e-4; base.fetchResults(r); BasisSwap.Results results = r as BasisSwap.Results; if (results != null) { fairLongSpread_ = results.fairLongSpread; fairShortSpread_ = results.fairShortSpread; } else { fairLongSpread_ = null; fairShortSpread_ = null; } // Long fair spread should be fine - no averaging or compounding if (fairLongSpread_ == null && legBPS_[longNo_] != null) { fairLongSpread_ = longSpread_ - NPV_ / (legBPS_[longNo_] / basisPoint); } /* Short fair spread calculation ok if no averaging/compounding OR * if there is averaging/compounding and the spread is added after */ if (fairShortSpread_ == null && legBPS_[shortNo_] != null) { fairShortSpread_ = shortSpread_ - NPV_ / (legBPS_[shortNo_] / basisPoint); } }
/*! When a derived result structure is defined for an instrument, * this method should be overridden to read from it. * This is mandatory in case a pricing engine is used. */ public virtual void fetchResults(IPricingEngineResults r) { var results = r as Results; if (results == null) throw new ArgumentException("no results returned from pricing engine"); NPV = results.value; errorEstimateValue = results.errorEstimate; additionalResultsMap = results.additionalResults; }
/*! When a derived result structure is defined for an instrument, * this method should be overridden to read from it. * This is mandatory in case a pricing engine is used. */ public virtual void fetchResults(IPricingEngineResults r) { Instrument.Results results = r as Instrument.Results; if (results == null) throw new ArgumentException("no results returned from pricing engine"); NPV_ = results.value; CASH_ = results.cash; errorEstimate_ = results.errorEstimate; additionalResults_ = results.additionalResults; }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); Bond.Results results = r as Bond.Results; Utils.QL_REQUIRE(results != null, () => "wrong result type"); settlementValue_ = results.settlementValue; }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); Swap.Results results = r as Swap.Results; Utils.QL_REQUIRE(results != null, () => "wrong result type"); if (!results.legNPV.empty()) { Utils.QL_REQUIRE(results.legNPV.Count == legNPV_.Count, () => "wrong number of leg NPV returned"); legNPV_ = new List <double?>(results.legNPV); } else { legNPV_ = new InitializedList <double?>(legNPV_.Count); } if (!results.legBPS.empty()) { Utils.QL_REQUIRE(results.legBPS.Count == legBPS_.Count, () => "wrong number of leg BPS returned"); legBPS_ = new List <double?>(results.legBPS); } else { legBPS_ = new InitializedList <double?>(legBPS_.Count); } if (!results.startDiscounts.empty()) { Utils.QL_REQUIRE(results.startDiscounts.Count == startDiscounts_.Count, () => "wrong number of leg start discounts returned"); startDiscounts_ = new List <double?>(results.startDiscounts); } else { startDiscounts_ = new InitializedList <double?>(startDiscounts_.Count); } if (!results.endDiscounts.empty()) { Utils.QL_REQUIRE(results.endDiscounts.Count == endDiscounts_.Count, () => "wrong number of leg end discounts returned"); endDiscounts_ = new List <double?>(results.endDiscounts); } else { endDiscounts_ = new InitializedList <double?>(endDiscounts_.Count); } if (results.npvDateDiscount != null) { npvDateDiscount_ = results.npvDateDiscount; } else { npvDateDiscount_ = null; } }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); CatBond.Results results = r as CatBond.Results; Utils.QL_REQUIRE(results != null, () => "wrong result type"); lossProbability_ = results.lossProbability; expectedLoss_ = results.expectedLoss; exhaustionProbability_ = results.exhaustionProbability; }
/*! When a derived result structure is defined for an instrument, * this method should be overridden to read from it. * This is mandatory in case a pricing engine is used. */ public virtual void fetchResults(IPricingEngineResults r) { Instrument.Results results = r as Instrument.Results; if (results == null) { throw new ArgumentException("no results returned from pricing engine"); } NPV_ = results.value; CASH_ = results.cash; errorEstimate_ = results.errorEstimate; additionalResults_ = results.additionalResults; }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); Bond.Results results = r as Bond.Results; if (results == null) { throw new ApplicationException("wrong result type"); } settlementValue_ = results.settlementValue; }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); ForwardVanillaOption.Results results = r as ForwardVanillaOption.Results; Utils.QL_REQUIRE(results != null, () => "no results returned from pricing engine"); delta_ = results.delta; gamma_ = results.gamma; theta_ = results.theta; vega_ = results.vega; rho_ = results.rho; dividendRho_ = results.dividendRho; }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); CreditDefaultSwap.Results results = r as CreditDefaultSwap.Results; Utils.QL_REQUIRE(results != null, () => "wrong result type"); fairSpread_ = results.fairSpread; fairUpfront_ = results.fairUpfront; couponLegBPS_ = results.couponLegBPS; couponLegNPV_ = results.couponLegNPV; defaultLegNPV_ = results.defaultLegNPV; upfrontNPV_ = results.upfrontNPV; upfrontBPS_ = results.upfrontBPS; }
/// <summary> /// Sets the pricing results locally. /// </summary> public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); Results results = r as Results; if (results == null) { throw new ApplicationException("No greeks returned from pricing engine"); } delta_ = results.delta; gamma_ = results.gamma; theta_ = results.theta; vega_ = results.vega; rho_ = results.rho; }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); AssetSwap.Results results = r as AssetSwap.Results; if (results != null) { fairSpread_ = results.fairSpread; fairCleanPrice_ = results.fairCleanPrice; fairNonParRepayment_ = results.fairNonParRepayment; } else { fairSpread_ = null; fairCleanPrice_ = null; fairNonParRepayment_ = null; } }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); Results results = r as Results; if (results == null) { throw new ApplicationException("no greeks returned from pricing engine"); } /* no check on null values - just copy. * this allows: * a) to decide in derived options what to do when null * results are returned (throw? numerical calculation?) * b) to implement slim engines which only calculate the * value---of course care must be taken not to call * the greeks methods when using these. */ delta_ = results.delta; gamma_ = results.gamma; theta_ = results.theta; vega_ = results.vega; rho_ = results.rho; dividendRho_ = results.dividendRho; // QL_ENSURE(moreResults != 0, "no more greeks returned from pricing engine"); /* no check on null values - just copy. * this allows: * a) to decide in derived options what to do when null * results are returned (throw? numerical calculation?) * b) to implement slim engines which only calculate the * value---of course care must be taken not to call * the greeks methods when using these. */ deltaForward_ = results.deltaForward; elasticity_ = results.elasticity; thetaPerDay_ = results.thetaPerDay; strikeSensitivity_ = results.strikeSensitivity; itmCashProbability_ = results.itmCashProbability; }
// other public override void fetchResults(IPricingEngineResults r) { const double basisPoint = 1.0e-4; // copy from VanillaSwap // works because similarly simple instrument // that we always expect to be priced with a swap engine base.fetchResults(r); CPISwap.Results results = r as CPISwap.Results; if (results != null) { // might be a swap engine, so no error is thrown fairRate_ = results.fairRate; fairSpread_ = results.fairSpread; } else { fairRate_ = null; fairSpread_ = null; } if (fairRate_ == null) { // calculate it from other results if (legBPS_[0] != null) { fairRate_ = fixedRate_ - NPV_ / (legBPS_[0] / basisPoint); } } if (fairSpread_ == null) { // ditto if (legBPS_[1] != null) { fairSpread_ = spread_ - NPV_ / (legBPS_[1] / basisPoint); } } }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); LoanPricingEngineResults results = r as LoanPricingEngineResults; if (results == null) throw new ArgumentException("wrong result type"); if (results.legNPV.Count != 0) { if (results.legNPV.Count != legNPV_.Count) { throw new ArgumentException("wrong number of leg NPV returned"); } legNPV_ = results.legNPV; } else { legNPV_ = new InitializedList<double?>(legNPV_.Count); } }
public override void fetchResults(IPricingEngineResults res) { base.fetchResults(res); }
public virtual void calculate(IPricingEngineResults r) { throw new NotSupportedException(); }
public override void fetchResults(IPricingEngineResults r) { // you don't actually need to do anything else because it is so simple base.fetchResults(r); }
public override void calculate(IPricingEngineResults r) { engine_.calculate(r); }
public override void calculate(IPricingEngineResults r) { OneAssetOption.Results results = r as OneAssetOption.Results; Utils.QL_REQUIRE(results != null, () => "incorrect results type"); double beginDate, endDate; int dateNumber = stoppingTimes_.Count; bool lastDateIsResTime = false; int firstIndex = -1; int lastIndex = dateNumber - 1; bool firstDateIsZero = false; double firstNonZeroDate = getResidualTime(); double dateTolerance = 1e-6; int j; if (dateNumber > 0) { Utils.QL_REQUIRE(getDividendTime(0) >= 0, () => "first date (" + getDividendTime(0) + ") cannot be negative"); if (getDividendTime(0) < getResidualTime() * dateTolerance) { firstDateIsZero = true; firstIndex = 0; if (dateNumber >= 2) { firstNonZeroDate = getDividendTime(1); } } if (Math.Abs(getDividendTime(lastIndex) - getResidualTime()) < dateTolerance) { lastDateIsResTime = true; lastIndex = dateNumber - 2; } if (!firstDateIsZero) { firstNonZeroDate = getDividendTime(0); } if (dateNumber >= 2) { for (j = 1; j < dateNumber; j++) { Utils.QL_REQUIRE(getDividendTime(j - 1) < getDividendTime(j), () => "dates must be in increasing order: " + getDividendTime(j - 1) + " is not strictly smaller than " + getDividendTime(j)); } } } double dt = getResidualTime() / (timeStepPerPeriod_ * (dateNumber + 1)); // Ensure that dt is always smaller than the first non-zero date if (firstNonZeroDate <= dt) { dt = firstNonZeroDate / 2.0; } setGridLimits(); initializeInitialCondition(); initializeOperator(); initializeBoundaryConditions(); initializeModel(); initializeStepCondition(); prices_ = (SampledCurve)intrinsicValues_.Clone(); if (lastDateIsResTime) { executeIntermediateStep(dateNumber - 1); } j = lastIndex; object temp; do { if (j == dateNumber - 1) { beginDate = getResidualTime(); } else { beginDate = getDividendTime(j + 1); } if (j >= 0) { endDate = getDividendTime(j); } else { endDate = dt; } temp = prices_.values(); model_.rollback(ref temp, beginDate, endDate, timeStepPerPeriod_, stepCondition_); prices_.setValues((Vector)temp); if (j >= 0) { executeIntermediateStep(j); } } while (--j >= firstIndex); temp = prices_.values(); model_.rollback(ref temp, dt, 0, 1, stepCondition_); prices_.setValues((Vector)temp); if (firstDateIsZero) { executeIntermediateStep(0); } results.value = prices_.valueAtCenter(); results.delta = prices_.firstDerivativeAtCenter(); results.gamma = prices_.secondDerivativeAtCenter(); results.additionalResults["priceCurve"] = prices_; }
public override void calculate(IPricingEngineResults r) { OneAssetOption.Results results = r as OneAssetOption.Results; setGridLimits(); initializeInitialCondition(); initializeOperator(); initializeBoundaryConditions(); initializeStepCondition(); List <IOperator> operatorSet = new List <IOperator>(); List <Vector> arraySet = new List <Vector>(); BoundaryConditionSet bcSet = new BoundaryConditionSet(); StepConditionSet <Vector> conditionSet = new StepConditionSet <Vector>(); prices_ = (SampledCurve)intrinsicValues_.Clone(); controlPrices_ = (SampledCurve)intrinsicValues_.Clone(); controlOperator_ = (TridiagonalOperator)finiteDifferenceOperator_.Clone(); controlBCs_[0] = BCs_[0]; controlBCs_[1] = BCs_[1]; operatorSet.Add(finiteDifferenceOperator_); operatorSet.Add(controlOperator_); arraySet.Add(prices_.values()); arraySet.Add(controlPrices_.values()); bcSet.Add(BCs_); bcSet.Add(controlBCs_); conditionSet.Add(stepCondition_); conditionSet.Add(new NullCondition <Vector>()); var model = new FiniteDifferenceModel <ParallelEvolver <CrankNicolson <TridiagonalOperator> > >(operatorSet, bcSet); object temp = arraySet; model.rollback(ref temp, getResidualTime(), 0.0, timeSteps_, conditionSet); arraySet = (List <Vector>)temp; prices_.setValues(arraySet[0]); controlPrices_.setValues(arraySet[1]); StrikedTypePayoff striked_payoff = payoff_ as StrikedTypePayoff; Utils.QL_REQUIRE(striked_payoff != null, () => "non-striked payoff given"); double variance = process_.blackVolatility().link.blackVariance(exerciseDate_, striked_payoff.strike()); double dividendDiscount = process_.dividendYield().link.discount(exerciseDate_); double riskFreeDiscount = process_.riskFreeRate().link.discount(exerciseDate_); double spot = process_.stateVariable().link.value(); double forwardPrice = spot * dividendDiscount / riskFreeDiscount; BlackCalculator black = new BlackCalculator(striked_payoff, forwardPrice, Math.Sqrt(variance), riskFreeDiscount); results.value = prices_.valueAtCenter() - controlPrices_.valueAtCenter() + black.value(); results.delta = prices_.firstDerivativeAtCenter() - controlPrices_.firstDerivativeAtCenter() + black.delta(spot); results.gamma = prices_.secondDerivativeAtCenter() - controlPrices_.secondDerivativeAtCenter() + black.gamma(spot); results.additionalResults["priceCurve"] = prices_; }
public override void fetchResults(IPricingEngineResults r) { const double basisPoint = 1.0e-4; base.fetchResults(r); VanillaSwap.Results results = r as VanillaSwap.Results; if (results != null) { // might be a swap engine, so no error is thrown fairRate_ = results.fairRate; fairSpread_ = results.fairSpread; } else { fairRate_ = null; fairSpread_ = null; } if (fairRate_ == null) { // calculate it from other results if (legBPS_[0] != null) fairRate_ = fixedRate_ - NPV_.GetValueOrDefault() / (legBPS_[0] / basisPoint); } if (fairSpread_ == null) { // ditto if (legBPS_[1] != null) fairSpread_ = spread_ - NPV_.GetValueOrDefault() / (legBPS_[1] / basisPoint); } }
public override void calculate(IPricingEngineResults r) { OneAssetOption.Results results = r as OneAssetOption.Results; if (results == null) throw new ApplicationException("incorrect results type"); double beginDate, endDate; int dateNumber = stoppingTimes_.Count; bool lastDateIsResTime = false; int firstIndex = -1; int lastIndex = dateNumber - 1; bool firstDateIsZero = false; double firstNonZeroDate = getResidualTime(); double dateTolerance = 1e-6; int j; if (dateNumber > 0) { if (!(getDividendTime(0) >= 0)) throw new ApplicationException("first date (" + getDividendTime(0) + ") cannot be negative"); if (getDividendTime(0) < getResidualTime() * dateTolerance) { firstDateIsZero = true; firstIndex = 0; if (dateNumber >= 2) firstNonZeroDate = getDividendTime(1); } if (Math.Abs(getDividendTime(lastIndex) - getResidualTime()) < dateTolerance) { lastDateIsResTime = true; lastIndex = dateNumber - 2; } if (!firstDateIsZero) firstNonZeroDate = getDividendTime(0); if (dateNumber >= 2) { for (j = 1; j < dateNumber; j++) if (!(getDividendTime(j - 1) < getDividendTime(j))) throw new ApplicationException("dates must be in increasing order: " + getDividendTime(j - 1) + " is not strictly smaller than " + getDividendTime(j)); } } double dt = getResidualTime() / (timeStepPerPeriod_ * (dateNumber + 1)); // Ensure that dt is always smaller than the first non-zero date if (firstNonZeroDate <= dt) dt = firstNonZeroDate / 2.0; setGridLimits(); initializeInitialCondition(); initializeOperator(); initializeBoundaryConditions(); initializeModel(); initializeStepCondition(); prices_ = (SampledCurve)intrinsicValues_.Clone(); if (lastDateIsResTime) executeIntermediateStep(dateNumber - 1); j = lastIndex; object temp; do { if (j == dateNumber - 1) beginDate = getResidualTime(); else beginDate = getDividendTime(j + 1); if (j >= 0) endDate = getDividendTime(j); else endDate = dt; temp = prices_.values(); model_.rollback(ref temp, beginDate, endDate, timeStepPerPeriod_, stepCondition_); prices_.setValues((Vector)temp); if (j >= 0) executeIntermediateStep(j); } while (--j >= firstIndex); temp = prices_.values(); model_.rollback(ref temp, dt, 0, 1, stepCondition_); prices_.setValues((Vector)temp); if (firstDateIsZero) executeIntermediateStep(0); results.value = prices_.valueAtCenter(); results.delta = prices_.firstDerivativeAtCenter(); results.gamma = prices_.secondDerivativeAtCenter(); results.additionalResults["priceCurve"] = prices_; }
public override void calculate(IPricingEngineResults r) { OneAssetOption.Results results = r as OneAssetOption.Results; setGridLimits(); initializeInitialCondition(); initializeOperator(); initializeBoundaryConditions(); initializeStepCondition(); // typedef StandardSystemFiniteDifferenceModel model_type; List<IOperator> operatorSet = new List<IOperator>(); List<Vector> arraySet = new List<Vector>(); BoundaryConditionSet bcSet = new BoundaryConditionSet(); StepConditionSet<Vector> conditionSet = new StepConditionSet<Vector>(); prices_ = (SampledCurve)intrinsicValues_.Clone(); controlPrices_ = (SampledCurve)intrinsicValues_.Clone(); controlOperator_ = (TridiagonalOperator)finiteDifferenceOperator_.Clone(); controlBCs_[0] = BCs_[0]; controlBCs_[1] = BCs_[1]; operatorSet.Add(finiteDifferenceOperator_); operatorSet.Add(controlOperator_); arraySet.Add(prices_.values()); arraySet.Add(controlPrices_.values()); bcSet.Add(BCs_); bcSet.Add(controlBCs_); conditionSet.Add(stepCondition_); conditionSet.Add(new NullCondition<Vector>()); var model = new FiniteDifferenceModel<ParallelEvolver<CrankNicolson<TridiagonalOperator>>>(operatorSet, bcSet); object temp = arraySet; model.rollback(ref temp, getResidualTime(), 0.0, timeSteps_, conditionSet); arraySet = (List<Vector>)temp; prices_.setValues(arraySet[0]); controlPrices_.setValues(arraySet[1]); StrikedTypePayoff striked_payoff = payoff_ as StrikedTypePayoff; if (striked_payoff == null) throw new ApplicationException("non-striked payoff given"); double variance = process_.blackVolatility().link.blackVariance(exerciseDate_, striked_payoff.strike()); double dividendDiscount = process_.dividendYield().link.discount(exerciseDate_); double riskFreeDiscount = process_.riskFreeRate().link.discount(exerciseDate_); double spot = process_.stateVariable().link.value(); double forwardPrice = spot * dividendDiscount / riskFreeDiscount; BlackCalculator black = new BlackCalculator(striked_payoff, forwardPrice, Math.Sqrt(variance), riskFreeDiscount); results.value = prices_.valueAtCenter() - controlPrices_.valueAtCenter() + black.value(); results.delta = prices_.firstDerivativeAtCenter() - controlPrices_.firstDerivativeAtCenter() + black.delta(spot); results.gamma = prices_.secondDerivativeAtCenter() - controlPrices_.secondDerivativeAtCenter() + black.gamma(spot); results.additionalResults.Add("priceCurve", prices_); }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); BasisSwap.Results results = r as BasisSwap.Results; }
public override void fetchResults(IPricingEngineResults r) { base.fetchResults(r); AssetSwap.Results results = r as AssetSwap.Results; if (results != null) { fairSpread_ = results.fairSpread; fairCleanPrice_= results.fairCleanPrice; fairNonParRepayment_= results.fairNonParRepayment; } else { fairSpread_ = null; fairCleanPrice_ = null; fairNonParRepayment_ = null; } }