//------------------------------------------------------------------------- public virtual void calibration_test() { RatesProvider result2 = CALIBRATOR.calibrate(CURVE_GROUP_DEFN, ALL_QUOTES, REF_DATA); // pv test CurveNode[] fwd3Nodes = CURVES_NODES[0][0]; IList <ResolvedTrade> fwd3Trades = new List <ResolvedTrade>(); for (int i = 0; i < fwd3Nodes.Length; i++) { fwd3Trades.Add(fwd3Nodes[i].resolvedTrade(1d, ALL_QUOTES, REF_DATA)); } for (int i = 0; i < FWD6_NB_NODES; i++) { MultiCurrencyAmount pvIrs2 = SWAP_PRICER.presentValue(((ResolvedSwapTrade)fwd3Trades[i]).Product, result2); assertEquals(pvIrs2.getAmount(GBP).Amount, 0.0, TOLERANCE_PV); } // regression test for curve DiscountFactors dsc = result2.discountFactors(GBP); double prevDsc = 0d; for (int i = 0; i < 121; ++i) { double time = ((double)i); double curDsc = dsc.discountFactor(time); if (i > 59) { double fwd = prevDsc / curDsc - 1d; assertEquals(fwd, 0.042, 2d * ONE_BP); } assertEquals(curDsc, DSC_EXP.get(i), ONE_PC); prevDsc = curDsc; } }
private RepoCurveDiscountFactors(DiscountFactors discountFactors, RepoGroup repoGroup) { JodaBeanUtils.notNull(discountFactors, "discountFactors"); JodaBeanUtils.notNull(repoGroup, "repoGroup"); this.discountFactors = discountFactors; this.repoGroup = repoGroup; }
//------------------------------------------------------------------------- public FxForwardRates fxForwardRates(CurrencyPair currencyPair) { DiscountFactors @base = discountFactors(currencyPair.Base); DiscountFactors counter = discountFactors(currencyPair.Counter); return(DiscountFxForwardRates.of(currencyPair, fxRateProvider, @base, counter)); };
static BondFuturesJpyEnd2EndTest() { for (int i = 0; i < NB_UND_BONDS; ++i) { PeriodicSchedule periodSchedule = PeriodicSchedule.of(START_DATE[i], MATURITY_DATE[i], Frequency.P6M, BUSINESS_ADJUST, StubConvention.SHORT_INITIAL, false); FixedCouponBond product = FixedCouponBond.builder().securityId(SecurityId.of(BOND_SECURITY_ID[i])).dayCount(DAY_COUNT).fixedRate(UND_RATES[i] * ONE_PERCENT).legalEntityId(ISSUER_ID).currency(JPY).notional(NOTIONAL).accrualSchedule(periodSchedule).settlementDateOffset(SETTLEMENT_DAYS).yieldConvention(YIELD_CONVENTION).build(); UND_BOND[i] = product; } UND_BOND_SEP = new FixedCouponBond[NB_UND_BONDS - 2]; Array.Copy(UND_BOND, 2, UND_BOND_SEP, 0, NB_UND_BONDS - 2); UND_BOND_JUN = new FixedCouponBond[NB_UND_BONDS - 1]; Array.Copy(UND_BOND, 1, UND_BOND_JUN, 0, NB_UND_BONDS - 1); double[] timeIssuer = new double[] { 0.25136612021857924, 0.4972677595628415, 1.0139980537465378, 2.013998053746538, 2.857833670184894, 3.857833670184894, 4.860655737704918, 5.857833670184894, 7.104409012650647, 7.857833670184894, 8.857923497267759, 9.863313122239688, 14.857833670184894, 19.857833670184895, 29.857833670184895, 39.11262819073284 }; double[] rateIssuer = new double[] { -0.0013117084834668065, -0.0010851901424876163, -0.0020906775838723216, -0.0022137102045172784, -0.0022695678374162888, -0.0023424568490920798, -0.0021603059162879916, -0.0021667343131861225, -0.0018285921969274823, -0.001355094018965514, -6.763044056712535E-4, 1.9555294306801752E-4, 0.003944125562941363, 0.008054233458390252, 0.012276105941434846, 0.013537766297065804 }; double[] timeRepo = new double[] { 0.00273224043715847, 0.01912568306010929, 0.040983606557377046, 0.05737704918032787, 0.07923497267759563, 0.2459016393442623, 0.4972677595628415, 1.0002994236095515 }; double[] rateRepo = new double[] { 2.599662058772748E-4, -8.403529976927196E-4, -0.0010105103936934236, -0.0011506617573950931, -0.0012708071334455143, -0.00146106683851595, -0.0014710815100096722, -0.001481096281798276 }; CurveMetadata metaIssuer = Curves.zeroRates(ISSUER_CURVE_NAME, ACT_ACT_ISDA); InterpolatedNodalCurve curveIssuer = InterpolatedNodalCurve.of(metaIssuer, DoubleArray.copyOf(timeIssuer), DoubleArray.copyOf(rateIssuer), INTERPOLATOR); DiscountFactors dscIssuer = ZeroRateDiscountFactors.of(JPY, VALUATION, curveIssuer); CurveMetadata metaRepo = Curves.zeroRates(REPO_CURVE_NAME, ACT_ACT_ISDA); InterpolatedNodalCurve curve = InterpolatedNodalCurve.of(metaRepo, DoubleArray.copyOf(timeRepo), DoubleArray.copyOf(rateRepo), INTERPOLATOR); DiscountFactors dscRepo = ZeroRateDiscountFactors.of(JPY, VALUATION, curve); LED_PROVIDER = ImmutableLegalEntityDiscountingProvider.builder().issuerCurves(ImmutableMap.of(Pair.of(GROUP_ISSUER, JPY), dscIssuer)).issuerCurveGroups(ImmutableMap.of(ISSUER_ID, GROUP_ISSUER)).repoCurves(ImmutableMap.of(Pair.of(GROUP_REPO, JPY), dscRepo)).repoCurveGroups(ImmutableMap.of(ISSUER_ID, GROUP_REPO)).build(); }
public virtual PointSensitivityBuilder pvbpSensitivity(RatePaymentPeriod paymentPeriod, RatesProvider provider) { ArgChecker.isTrue(!paymentPeriod.FxReset.Present, "FX reset is not supported"); int accPeriodCount = paymentPeriod.AccrualPeriods.size(); ArgChecker.isTrue(accPeriodCount == 1 || paymentPeriod.CompoundingMethod.Equals(CompoundingMethod.FLAT), "Only one accrued period or Flat compounding supported"); // no compounding if (accPeriodCount == 1) { RateAccrualPeriod accrualPeriod = paymentPeriod.AccrualPeriods.get(0); DiscountFactors discountFactors = provider.discountFactors(paymentPeriod.Currency); return(discountFactors.zeroRatePointSensitivity(paymentPeriod.PaymentDate).multipliedBy(accrualPeriod.YearFraction * paymentPeriod.Notional)); } else { // Flat compounding switch (paymentPeriod.CompoundingMethod) { case FLAT: return(pvbpSensitivtyCompoundedFlat(paymentPeriod, provider)); default: throw new System.NotSupportedException("PVBP not implemented yet for non FLAT compounding"); } } }
private CurrencyParameterSensitivities sensitivityCreidtCurve <T>(ImmutableCreditRatesProvider provider, System.Func <ImmutableCreditRatesProvider, CurrencyAmount> valueFn, MetaProperty <ImmutableMap <T, LegalEntitySurvivalProbabilities> > metaProperty, CurrencyAmount valueInit) { ImmutableMap <T, LegalEntitySurvivalProbabilities> baseCurves = metaProperty.get(provider); CurrencyParameterSensitivities result = CurrencyParameterSensitivities.empty(); foreach (T key in baseCurves.Keys) { LegalEntitySurvivalProbabilities credit = baseCurves.get(key); CreditDiscountFactors creditDiscountFactors = credit.SurvivalProbabilities; DiscountFactors discountFactors = creditDiscountFactors.toDiscountFactors(); Curve curve = checkDiscountFactors(discountFactors); int paramCount = curve.ParameterCount; double[] sensitivity = new double[paramCount]; for (int i = 0; i < paramCount; i++) { Curve dscBumped = curve.withParameter(i, curve.getParameter(i) + shift); IDictionary <T, LegalEntitySurvivalProbabilities> mapBumped = new Dictionary <T, LegalEntitySurvivalProbabilities>(baseCurves); mapBumped[key] = LegalEntitySurvivalProbabilities.of(credit.LegalEntityId, createCreditDiscountFactors(creditDiscountFactors, dscBumped)); ImmutableCreditRatesProvider providerDscBumped = provider.toBuilder().set(metaProperty, mapBumped).build(); sensitivity[i] = (valueFn(providerDscBumped).Amount - valueInit.Amount) / shift; } result = result.combinedWith(curve.createParameterSensitivity(valueInit.Currency, DoubleArray.copyOf(sensitivity))); } return(result); }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableConstructor private DiscountFxForwardRates(com.opengamma.strata.basics.currency.CurrencyPair currencyPair, com.opengamma.strata.basics.currency.FxRateProvider fxRateProvider, com.opengamma.strata.pricer.DiscountFactors baseCurrencyDiscountFactors, com.opengamma.strata.pricer.DiscountFactors counterCurrencyDiscountFactors) private DiscountFxForwardRates(CurrencyPair currencyPair, FxRateProvider fxRateProvider, DiscountFactors baseCurrencyDiscountFactors, DiscountFactors counterCurrencyDiscountFactors) { JodaBeanUtils.notNull(currencyPair, "currencyPair"); JodaBeanUtils.notNull(fxRateProvider, "fxRateProvider"); JodaBeanUtils.notNull(baseCurrencyDiscountFactors, "baseCurrencyDiscountFactors"); JodaBeanUtils.notNull(counterCurrencyDiscountFactors, "counterCurrencyDiscountFactors"); if (!baseCurrencyDiscountFactors.Currency.Equals(currencyPair.Base)) { throw new System.ArgumentException(Messages.format("Index base currency {} did not match discount factor base currency {}", currencyPair.Base, baseCurrencyDiscountFactors.Currency)); } if (!counterCurrencyDiscountFactors.Currency.Equals(currencyPair.Counter)) { throw new System.ArgumentException(Messages.format("Index counter currency {} did not match discount factor counter currency {}", currencyPair.Counter, counterCurrencyDiscountFactors.Currency)); } if (!baseCurrencyDiscountFactors.ValuationDate.Equals(counterCurrencyDiscountFactors.ValuationDate)) { throw new System.ArgumentException("Curves must have the same valuation date"); } this.currencyPair = currencyPair; this.fxRateProvider = fxRateProvider; this.baseCurrencyDiscountFactors = baseCurrencyDiscountFactors; this.counterCurrencyDiscountFactors = counterCurrencyDiscountFactors; this.valuationDate = baseCurrencyDiscountFactors.ValuationDate; this.paramCombiner = ParameterizedDataCombiner.of(baseCurrencyDiscountFactors, counterCurrencyDiscountFactors); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 1005147787: // currencyPair this.currencyPair = (CurrencyPair)newValue; break; case -1499624221: // fxRateProvider this.fxRateProvider = (FxRateProvider)newValue; break; case 1151357473: // baseCurrencyDiscountFactors this.baseCurrencyDiscountFactors = (DiscountFactors)newValue; break; case -453959018: // counterCurrencyDiscountFactors this.counterCurrencyDiscountFactors = (DiscountFactors)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
public ImmutableLegalEntityDiscountingProvider toImmutableLegalEntityDiscountingProvider() { // repo curves IDictionary <Pair <RepoGroup, Currency>, DiscountFactors> repoCurves = new Dictionary <Pair <RepoGroup, Currency>, DiscountFactors>(); foreach (Pair <RepoGroup, Currency> pair in lookup.RepoCurves.Keys) { CurveId curveId = lookup.RepoCurves.get(pair); if (marketData.containsValue(curveId)) { Curve curve = marketData.getValue(curveId); repoCurves[pair] = DiscountFactors.of(pair.Second, ValuationDate, curve); } } // issuer curves IDictionary <Pair <LegalEntityGroup, Currency>, DiscountFactors> issuerCurves = new Dictionary <Pair <LegalEntityGroup, Currency>, DiscountFactors>(); foreach (Pair <LegalEntityGroup, Currency> pair in lookup.IssuerCurves.Keys) { CurveId curveId = lookup.IssuerCurves.get(pair); if (marketData.containsValue(curveId)) { Curve curve = marketData.getValue(curveId); issuerCurves[pair] = DiscountFactors.of(pair.Second, ValuationDate, curve); } } // build result return(ImmutableLegalEntityDiscountingProvider.builder().valuationDate(ValuationDate).repoCurveSecurityGroups(lookup.RepoCurveSecurityGroups).repoCurveGroups(lookup.RepoCurveGroups).repoCurves(repoCurves).issuerCurveGroups(lookup.IssuerCurveGroups).issuerCurves(issuerCurves).build()); }
private IssuerCurveDiscountFactors(DiscountFactors discountFactors, LegalEntityGroup legalEntityGroup) { JodaBeanUtils.notNull(discountFactors, "discountFactors"); JodaBeanUtils.notNull(legalEntityGroup, "legalEntityGroup"); this.discountFactors = discountFactors; this.legalEntityGroup = legalEntityGroup; }
/// <summary> /// Obtains legal entity discounting rates provider from valuation date. /// </summary> /// <param name="valuationDate"> the valuation date </param> /// <returns> the discounting rates provider </returns> public static LegalEntityDiscountingProvider getLegalEntityDiscountingProviderJp(LocalDate valuationDate) { DiscountFactors dscIssuer = ZeroRateDiscountFactors.of(JPY, valuationDate, ISSUER_CURVE); DiscountFactors dscRepo = ZeroRateDiscountFactors.of(JPY, valuationDate, REPO_CURVE); return(ImmutableLegalEntityDiscountingProvider.builder().issuerCurves(ImmutableMap.of(Pair.of(GROUP_ISSUER, JPY), dscIssuer)).issuerCurveGroups(ImmutableMap.of(ISSUER_ID, GROUP_ISSUER)).repoCurves(ImmutableMap.of(Pair.of(GROUP_REPO, JPY), dscRepo)).repoCurveGroups(ImmutableMap.of(ISSUER_ID, GROUP_REPO)).build()); }
/// <summary> /// Calibrate trinomial tree to Black volatilities. /// <para> /// {@code timeToExpiry} determines the coverage of the resulting trinomial tree. /// Thus this should match the time to expiry of the target instrument to price using the calibrated tree. /// /// </para> /// </summary> /// <param name="timeToExpiry"> the time to expiry </param> /// <param name="currencyPair"> the currency pair </param> /// <param name="ratesProvider"> the rates provider </param> /// <param name="volatilities"> the Black volatility provider </param> /// <returns> the trinomial tree data </returns> public virtual RecombiningTrinomialTreeData calibrateTrinomialTree(double timeToExpiry, CurrencyPair currencyPair, RatesProvider ratesProvider, BlackFxOptionVolatilities volatilities) { validate(ratesProvider, volatilities); if (timeToExpiry <= 0d) { throw new System.ArgumentException("option expired"); } Currency ccyBase = currencyPair.Base; Currency ccyCounter = currencyPair.Counter; double todayFx = ratesProvider.fxRate(currencyPair); DiscountFactors baseDiscountFactors = ratesProvider.discountFactors(ccyBase); DiscountFactors counterDiscountFactors = ratesProvider.discountFactors(ccyCounter); System.Func <double, double> interestRate = (double?t) => { return(counterDiscountFactors.zeroRate(t.Value)); }; System.Func <double, double> dividendRate = (double?t) => { return(baseDiscountFactors.zeroRate(t.Value)); }; System.Func <DoublesPair, double> impliedVolSurface = (DoublesPair tk) => { double dfBase = baseDiscountFactors.discountFactor(tk.First); double dfCounter = counterDiscountFactors.discountFactor(tk.First); double forward = todayFx * dfBase / dfCounter; return(volatilities.volatility(currencyPair, tk.First, tk.Second, forward)); }; ImpliedTrinomialTreeLocalVolatilityCalculator localVol = new ImpliedTrinomialTreeLocalVolatilityCalculator(nSteps, timeToExpiry); return(localVol.calibrateImpliedVolatility(impliedVolSurface, todayFx, interestRate, dividendRate)); }
/// <summary> /// Test present value sensitivity for AFMA FRA discounting method. /// </summary> public virtual void test_presentValueSensitivity_AFMA() { RateComputationFn<RateComputation> mockObs = mock(typeof(RateComputationFn)); DiscountFactors mockDf = mock(typeof(DiscountFactors)); SimpleRatesProvider simpleProv = new SimpleRatesProvider(VAL_DATE, mockDf); ResolvedFra fraExp = RFRA_AFMA; double forwardRate = 0.05; double discountRate = 0.025; double paymentTime = 0.3; double discountFactor = Math.Exp(-discountRate * paymentTime); LocalDate fixingDate = FRA_AFMA.StartDate; IborIndexObservation obs = IborIndexObservation.of(FRA.Index, fixingDate, REF_DATA); PointSensitivityBuilder sens = IborRateSensitivity.of(obs, 1d); when(mockDf.discountFactor(fraExp.PaymentDate)).thenReturn(discountFactor); when(mockDf.zeroRatePointSensitivity(fraExp.PaymentDate)).thenReturn(ZeroRateSensitivity.of(fraExp.Currency, paymentTime, -discountFactor * paymentTime)); when(mockObs.rateSensitivity(fraExp.FloatingRate, fraExp.StartDate, fraExp.EndDate, simpleProv)).thenReturn(sens); when(mockObs.rate(fraExp.FloatingRate, FRA_AFMA.StartDate, FRA_AFMA.EndDate, simpleProv)).thenReturn(forwardRate); DiscountingFraProductPricer test = new DiscountingFraProductPricer(mockObs); PointSensitivities sensitivity = test.presentValueSensitivity(fraExp, simpleProv); double eps = 1.e-7; double fdDscSense = dscSensitivity(RFRA_AFMA, forwardRate, discountFactor, paymentTime, eps); double fdSense = presentValueFwdSensitivity(RFRA_AFMA, forwardRate, discountFactor, eps); ImmutableList<PointSensitivity> sensitivities = sensitivity.Sensitivities; assertEquals(sensitivities.size(), 2); IborRateSensitivity sensitivity0 = (IborRateSensitivity) sensitivities.get(0); assertEquals(sensitivity0.Index, FRA_AFMA.Index); assertEquals(sensitivity0.Observation.FixingDate, fixingDate); assertEquals(sensitivity0.Sensitivity, fdSense, FRA_AFMA.Notional * eps); ZeroRateSensitivity sensitivity1 = (ZeroRateSensitivity) sensitivities.get(1); assertEquals(sensitivity1.Currency, FRA_AFMA.Currency); assertEquals(sensitivity1.YearFraction, paymentTime); assertEquals(sensitivity1.Sensitivity, fdDscSense, FRA_AFMA.Notional * eps); }
//------------------------------------------------------------------------- private ValueDerivatives priceDerivatives(ResolvedFxSingleBarrierOption option, RatesProvider ratesProvider, BlackFxOptionVolatilities volatilities, RecombiningTrinomialTreeData data) { validate(option, ratesProvider, volatilities); validateData(option, ratesProvider, volatilities, data); int nSteps = data.NumberOfSteps; ResolvedFxVanillaOption underlyingOption = option.UnderlyingOption; double timeToExpiry = data.getTime(nSteps); ResolvedFxSingle underlyingFx = underlyingOption.Underlying; Currency ccyBase = underlyingFx.CounterCurrencyPayment.Currency; Currency ccyCounter = underlyingFx.CounterCurrencyPayment.Currency; DiscountFactors baseDiscountFactors = ratesProvider.discountFactors(ccyBase); DiscountFactors counterDiscountFactors = ratesProvider.discountFactors(ccyCounter); double rebateAtExpiry = 0d; // used to price knock-in option double rebateAtExpiryDerivative = 0d; // used to price knock-in option double notional = Math.Abs(underlyingFx.BaseCurrencyPayment.Amount); double[] rebateArray = new double[nSteps + 1]; SimpleConstantContinuousBarrier barrier = (SimpleConstantContinuousBarrier)option.Barrier; if (option.Rebate.Present) { CurrencyAmount rebateCurrencyAmount = option.Rebate.get(); double rebatePerUnit = rebateCurrencyAmount.Amount / notional; bool isCounter = rebateCurrencyAmount.Currency.Equals(ccyCounter); double rebate = isCounter ? rebatePerUnit : rebatePerUnit * barrier.BarrierLevel; if (barrier.KnockType.KnockIn) { // use in-out parity double dfCounterAtExpiry = counterDiscountFactors.discountFactor(timeToExpiry); double dfBaseAtExpiry = baseDiscountFactors.discountFactor(timeToExpiry); for (int i = 0; i < nSteps + 1; ++i) { rebateArray[i] = isCounter ? rebate * dfCounterAtExpiry / counterDiscountFactors.discountFactor(data.getTime(i)) : rebate * dfBaseAtExpiry / baseDiscountFactors.discountFactor(data.getTime(i)); } if (isCounter) { rebateAtExpiry = rebatePerUnit * dfCounterAtExpiry; } else { rebateAtExpiry = rebatePerUnit * data.Spot * dfBaseAtExpiry; rebateAtExpiryDerivative = rebatePerUnit * dfBaseAtExpiry; } } else { Arrays.fill(rebateArray, rebate); } } ConstantContinuousSingleBarrierKnockoutFunction barrierFunction = ConstantContinuousSingleBarrierKnockoutFunction.of(underlyingOption.Strike, timeToExpiry, underlyingOption.PutCall, nSteps, barrier.BarrierType, barrier.BarrierLevel, DoubleArray.ofUnsafe(rebateArray)); ValueDerivatives barrierPrice = TREE.optionPriceAdjoint(barrierFunction, data); if (barrier.KnockType.KnockIn) { // use in-out parity EuropeanVanillaOptionFunction vanillaFunction = EuropeanVanillaOptionFunction.of(underlyingOption.Strike, timeToExpiry, underlyingOption.PutCall, nSteps); ValueDerivatives vanillaPrice = TREE.optionPriceAdjoint(vanillaFunction, data); return(ValueDerivatives.of(vanillaPrice.Value + rebateAtExpiry - barrierPrice.Value, DoubleArray.of(vanillaPrice.getDerivative(0) + rebateAtExpiryDerivative - barrierPrice.getDerivative(0)))); } return(barrierPrice); }
//------------------------------------------------------------------------- public virtual void test_of_discountFactors() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE_DF); assertEquals(test is SimpleDiscountFactors, true); assertEquals(test.Currency, GBP); assertEquals(test.ValuationDate, DATE_VAL); }
public virtual void test_of_zeroRatePeriodic() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE_ZERO_PERIODIC); assertEquals(test is ZeroRatePeriodicDiscountFactors, true); assertEquals(test.Currency, GBP); assertEquals(test.ValuationDate, DATE_VAL); }
/// <summary> /// Computes the present value of the payment by discounting. /// <para> /// The present value is zero if the payment date is before the valuation date. /// </para> /// <para> /// The specified discount factors should be for the payment currency, however this is not validated. /// /// </para> /// </summary> /// <param name="payment"> the payment </param> /// <param name="discountFactors"> the discount factors to price against </param> /// <returns> the present value </returns> public virtual CurrencyAmount presentValue(Payment payment, DiscountFactors discountFactors) { if (discountFactors.ValuationDate.isAfter(payment.Date)) { return(CurrencyAmount.zero(payment.Currency)); } return(payment.Value.multipliedBy(discountFactors.discountFactor(payment.Date))); }
private DiscountIborIndexRates(IborIndex index, DiscountFactors discountFactors, LocalDateDoubleTimeSeries fixings) { JodaBeanUtils.notNull(index, "index"); JodaBeanUtils.notNull(discountFactors, "discountFactors"); JodaBeanUtils.notNull(fixings, "fixings"); this.index = index; this.discountFactors = discountFactors; this.fixings = fixings; }
public virtual void test_discountFactorTimeDerivative() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double expectedP = test.discountFactor(relativeYearFraction + EPS); double expectedM = test.discountFactor(relativeYearFraction - EPS); assertEquals(test.discountFactorTimeDerivative(relativeYearFraction), (expectedP - expectedM) / (2 * EPS), TOL_FD); }
//------------------------------------------------------------------------- // creates a simple provider private SimpleRatesProvider createProvider(ResolvedFra fraExp) { DiscountFactors mockDf = SimpleDiscountFactors.of(GBP, VAL_DATE, ConstantCurve.of(Curves.discountFactors("DSC", DAY_COUNT), DISCOUNT_FACTOR)); LocalDateDoubleTimeSeries timeSeries = LocalDateDoubleTimeSeries.of(VAL_DATE, FORWARD_RATE); IborIndexRates mockIbor = SimpleIborIndexRates.of(GBP_LIBOR_3M, VAL_DATE, ConstantCurve.of(Curves.forwardRates("L3M", DAY_COUNT), FORWARD_RATE), timeSeries); SimpleRatesProvider prov = new SimpleRatesProvider(VAL_DATE, mockDf); prov.IborRates = mockIbor; return prov; }
// lookup the discount factors for the repo group private RepoCurveDiscountFactors repoCurveDiscountFactors(RepoGroup repoGroup, Currency currency) { DiscountFactors discountFactors = repoCurves.get(Pair.of(repoGroup, currency)); if (discountFactors == null) { throw new System.ArgumentException("Unable to find repo curve: " + repoGroup + ", " + currency); } return(RepoCurveDiscountFactors.of(discountFactors, repoGroup)); }
//------------------------------------------------------------------------- /// <summary> /// Calculates the deposit fair rate given the start and end time and the accrual factor. /// <para> /// When the deposit has already started the number may not be meaningful as the remaining period /// is not in line with the accrual factor. /// /// </para> /// </summary> /// <param name="deposit"> the product </param> /// <param name="provider"> the rates provider </param> /// <returns> the par rate </returns> public virtual double parRate(ResolvedTermDeposit deposit, RatesProvider provider) { Currency currency = deposit.Currency; DiscountFactors discountFactors = provider.discountFactors(currency); double dfStart = discountFactors.discountFactor(deposit.StartDate); double dfEnd = discountFactors.discountFactor(deposit.EndDate); double accrualFactor = deposit.YearFraction; return((dfStart / dfEnd - 1d) / accrualFactor); }
/// <summary> /// Computes the present value of the payment with z-spread by discounting. /// <para> /// The present value is zero if the payment date is before the valuation date. /// </para> /// <para> /// The specified discount factors should be for the payment currency, however this is not validated. /// </para> /// <para> /// The z-spread is a parallel shift applied to continuously compounded rates or periodic /// compounded rates of the discounting curve. /// /// </para> /// </summary> /// <param name="payment"> the payment </param> /// <param name="discountFactors"> the discount factors to price against </param> /// <param name="zSpread"> the z-spread </param> /// <param name="compoundedRateType"> the compounded rate type </param> /// <param name="periodsPerYear"> the number of periods per year </param> /// <returns> the present value </returns> public virtual CurrencyAmount presentValueWithSpread(Payment payment, DiscountFactors discountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { if (discountFactors.ValuationDate.isAfter(payment.Date)) { return(CurrencyAmount.zero(payment.Currency)); } double df = discountFactors.discountFactorWithSpread(payment.Date, zSpread, compoundedRateType, periodsPerYear); return(payment.Value.multipliedBy(df)); }
private SimpleRatesProvider provider(LocalDate valuationDate, double dfStart, double dfEnd) { DiscountFactors mockDf = mock(typeof(DiscountFactors)); when(mockDf.discountFactor(START_DATE)).thenReturn(dfStart); when(mockDf.discountFactor(END_DATE)).thenReturn(dfEnd); SimpleRatesProvider prov = new SimpleRatesProvider(valuationDate, mockDf); return(prov); }
// lookup the discount factors for the legal entity group private IssuerCurveDiscountFactors issuerCurveDiscountFactors(LegalEntityGroup legalEntityGroup, Currency currency) { DiscountFactors discountFactors = issuerCurves.get(Pair.of(legalEntityGroup, currency)); if (discountFactors == null) { throw new System.ArgumentException("Unable to find issuer curve: " + legalEntityGroup + ", " + currency); } return(IssuerCurveDiscountFactors.of(discountFactors, legalEntityGroup)); }
private ImmutableLegalEntityDiscountingProvider replaceRepoCurve(ImmutableLegalEntityDiscountingProvider ratesProvider, Pair <RepoGroup, Currency> rgCcy, DiscountFactors discountFactors) { IDictionary <Pair <RepoGroup, Currency>, DiscountFactors> curves = new Dictionary <Pair <RepoGroup, Currency>, DiscountFactors>(); //JAVA TO C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'putAll' method: curves.putAll(ratesProvider.RepoCurves); curves[rgCcy] = discountFactors; return(ratesProvider.toBuilder().repoCurves(curves).build()); }
//------------------------------------------------------------------------- // creates a simple provider private SimpleRatesProvider createProvider(LocalDate valDate) { Curve curve = ConstantCurve.of(Curves.discountFactors("Test", DAY_COUNT), DISCOUNT_FACTOR); DiscountFactors df = SimpleDiscountFactors.of(GBP, valDate, curve); SimpleRatesProvider prov = new SimpleRatesProvider(valDate); prov.DayCount = DAY_COUNT; prov.DiscountFactors = df; return(prov); }
//------------------------------------------------------------------------- public DiscountFactors discountFactors(Currency currency) { Curve curve = discountCurves.get(currency); if (curve == null) { throw new System.ArgumentException("Unable to find discount curve: " + currency); } return(DiscountFactors.of(currency, valuationDate, curve)); }
/// <summary> /// Calculates the present value sensitivity of the Ibor fixing product. /// <para> /// The present value sensitivity of the product is the sensitivity of the present value to /// the underlying curves. /// /// </para> /// </summary> /// <param name="deposit"> the product </param> /// <param name="provider"> the rates provider </param> /// <returns> the point sensitivity of the present value </returns> public virtual PointSensitivities presentValueSensitivity(ResolvedIborFixingDeposit deposit, RatesProvider provider) { double forwardRate = this.forwardRate(deposit, provider); DiscountFactors discountFactors = provider.discountFactors(deposit.Currency); double discountFactor = discountFactors.discountFactor(deposit.EndDate); // sensitivity PointSensitivityBuilder sensiFwd = forwardRateSensitivity(deposit, provider).multipliedBy(-discountFactor * deposit.Notional * deposit.YearFraction); PointSensitivityBuilder sensiDsc = discountFactors.zeroRatePointSensitivity(deposit.EndDate).multipliedBy(deposit.Notional * deposit.YearFraction * (deposit.FixedRate - forwardRate)); return(sensiFwd.combinedWith(sensiDsc).build()); }
public virtual PointSensitivityBuilder presentValueSensitivity(FxResetNotionalExchange @event, RatesProvider provider) { DiscountFactors discountFactors = provider.discountFactors(@event.Currency); PointSensitivityBuilder sensiDsc = discountFactors.zeroRatePointSensitivity(@event.PaymentDate); sensiDsc = sensiDsc.multipliedBy(forecastValue(@event, provider)); PointSensitivityBuilder sensiFx = forecastValueSensitivity(@event, provider); sensiFx = sensiFx.multipliedBy(discountFactors.discountFactor(@event.PaymentDate)); return(sensiDsc.combinedWith(sensiFx)); }