当前位置: 首页>>代码示例>>Java>>正文


Java MersenneTwister类代码示例

本文整理汇总了Java中cern.jet.random.engine.MersenneTwister的典型用法代码示例。如果您正苦于以下问题:Java MersenneTwister类的具体用法?Java MersenneTwister怎么用?Java MersenneTwister使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MersenneTwister类属于cern.jet.random.engine包,在下文中一共展示了MersenneTwister类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: GibbsIndependentJointNormalGammaOperator

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
public GibbsIndependentJointNormalGammaOperator(Variable mean, Variable precision, NormalDistributionModel model, GammaDistribution gamma, double weight, boolean updateAllIndependently) {
	
	this.mean = mean;
       this.precision = precision;
	this.model = model;
       this.gamma = gamma;
	this.updateAllIndependently = updateAllIndependently;
	setWeight(weight);
	
	if (TRY_COLT) {
           randomEngine = new MersenneTwister(MathUtils.nextInt());
           //create standard normal distribution, internal states will be bypassed anyway
           //takes mean and standard deviation
           coltNormal = new Normal(0.0, 1.0, randomEngine);
           //coltGamma = new Gamma(gamma.getShape(), 1.0/gamma.getScale(), randomEngine);
       } else {
       	//no random draw with specified mean and stdev implemented in the normal distribution in BEAST (as far as I know)
       	throw new RuntimeException("Normal distribution in BEAST still needs a random sampler.");
       }
	
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:22,代码来源:GibbsIndependentJointNormalGammaOperator.java

示例2: init

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
/**
 * Create n  permutations
 *
 */
private  void init() {



    if (a==null) {
    //    System.out.println("this.seed = "+this.seed);
        MersenneTwister random = new MersenneTwister((int) this.seed);
  a = new long[n];
  b = new long[n];
  for (int j=0; j<n; j++) {
      a[j] = random.nextLong();
      b[j] = random.nextLong();
 //     System.out.println("a["+j+"]="+a[j]);
  //    System.out.println("b["+j+"]="+b[j]);
      while (a[j]<0)  a[j] = random.nextLong();
      while (b[j]<0)  b[j] = random.nextLong();
  }  
    }
}
 
开发者ID:dice-group,项目名称:CostFed,代码行数:24,代码来源:IndependentPermutations.java

示例3: visitSwaptionPhysicalFixedIbor

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Override
/**
 * The calculator is for test purposes only! It calibrates a Hull-White on a swaption priced with SABR and then price the same swaption in the Hull-White model by Monte Carlo.
 * Do not use this calculator in production.
 */
public MultipleCurrencyAmount visitSwaptionPhysicalFixedIbor(final SwaptionPhysicalFixedIbor swaption, final SABRSwaptionProviderInterface sabrData) {
  ArgumentChecker.notNull(swaption, "Swaption");
  ArgumentChecker.notNull(sabrData, "SABR swaption provider");
  final Currency ccy = swaption.getCurrency();
  final HullWhiteOneFactorPiecewiseConstantParameters hwParameters = new HullWhiteOneFactorPiecewiseConstantParameters(DEFAULT_MEAN_REVERSION, new double[] {0.01}, new double[0]);
  final SuccessiveRootFinderHullWhiteCalibrationObjective objective = new SuccessiveRootFinderHullWhiteCalibrationObjective(hwParameters, ccy);
  final SuccessiveRootFinderHullWhiteCalibrationEngine<SABRSwaptionProviderInterface> calibrationEngine = new SuccessiveRootFinderHullWhiteCalibrationEngine<>(objective);
  // Calibration instruments
  calibrationEngine.addInstrument(swaption, PVSSC);
  // Calibration
  calibrationEngine.calibrate(sabrData);
  final HullWhiteOneFactorProvider hwMulticurves = new HullWhiteOneFactorProvider(sabrData.getMulticurveProvider(), hwParameters, ccy);
  // Pricing
  final HullWhiteMonteCarloMethod methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), DEFAULT_NB_PATH);
  return methodMC.presentValue(swaption, ccy, hwMulticurves);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:PresentValueSABRHullWhiteMonteCarloCalculator.java

示例4: testFlat

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test
//TODO if this interpolator cannot get the answer right then an exception should be thrown
public void testFlat() {
  final RandomEngine random = new MersenneTwister64(MersenneTwister.DEFAULT_SEED);
  final double x1 = 10 * random.nextDouble();
  final double x2 = 10 * random.nextDouble();
  final double x3 = 10 * random.nextDouble();
  // Fails utterly for flat surface since the variogram function will be zero for all r
  final InterpolatorND interpolator = new KrigingInterpolatorND(1.99);
  final InterpolatorNDDataBundle dataBundle = interpolator.getDataBundle(FLAT_DATA);
  assertEquals(INTERPOLATOR.interpolate(dataBundle, new double[] {x1, x2, x3}), 0, 0);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:13,代码来源:KrigingInterpolatorNDTest.java

示例5: monteCarlo

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test(enabled = true)
/**
 * Compare explicit formula with Monte-Carlo and long/short and payer/receiver parities.
 */
public void monteCarlo() {
  HullWhiteMonteCarloMethod methodMC;
  methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), 10 * NB_PATH);
  // Seed fixed to the DEFAULT_SEED for testing purposes.
  final MultipleCurrencyAmount pvExplicit = METHOD_HW.presentValue(CAP_LONG, HW_MULTICURVES);
  final MultipleCurrencyAmount pvMC = methodMC.presentValue(CAP_LONG, EUR, HW_MULTICURVES);
  assertEquals("Cap/floor - Hull-White - Monte Carlo", pvExplicit.getAmount(EUR), pvMC.getAmount(EUR), 5.0E+2);
  final double pvMCPreviousRun = 136707.032;
  assertEquals("Swaption physical - Hull-White - Monte Carlo", pvMCPreviousRun, pvMC.getAmount(EUR), TOLERANCE_PV);
  methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), 10 * NB_PATH);
  final MultipleCurrencyAmount pvShortMC = methodMC.presentValue(CAP_SHORT, EUR, HW_MULTICURVES);
  assertEquals("Swaption physical - Hull-White - Monte Carlo", -pvMC.getAmount(EUR), pvShortMC.getAmount(EUR), TOLERANCE_PV);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:18,代码来源:CapFloorIborHullWhiteMethodTest.java

示例6: performance

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test(enabled = false)
/**
 * Performance for a high number of paths.
 */
public void performance() {
  long startTime, endTime;
  final MultipleCurrencyAmount pvExplicit = METHOD_HW.presentValue(CAP_LONG, HW_MULTICURVES);
  HullWhiteMonteCarloMethod methodMC;
  final int nbPath = 1000000;
  methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), nbPath);
  final int nbTest = 10;
  final double[] pv = new double[nbTest];
  final double[] pvDiff = new double[nbTest];

  startTime = System.currentTimeMillis();
  for (int looptest = 0; looptest < nbTest; looptest++) {
    pv[looptest] = methodMC.presentValue(CAP_LONG, EUR, HW_MULTICURVES).getAmount(EUR);
    pvDiff[looptest] = pv[looptest] - pvExplicit.getAmount(EUR);
  }
  endTime = System.currentTimeMillis();
  System.out.println(nbTest + " pv cap/floor Hull-White MC method (" + nbPath + " paths): " + (endTime - startTime) + " ms. Error: " + pvDiff[0]);
  // Performance note: price: 12-Jun-12: On Mac Pro 3.2 GHz Quad-Core Intel Xeon: 2400 ms for 10 cap with 1,000,000 paths.
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:CapFloorIborHullWhiteMethodTest.java

示例7: presentValueMCMultiCurves

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test(enabled = true)
/**
 * Test the present value.
 */
public void presentValueMCMultiCurves() {
  LiborMarketModelMonteCarloMethod methodLmmMc;
  methodLmmMc = new LiborMarketModelMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), NB_PATH);
  final MultipleCurrencyAmount pvLastMC = methodLmmMc.presentValue(CAP_LAST, EUR, LMM_MULTICURVES);
  final double pvLastPreviousRun = 45829.535; // 12500 paths - 1Y jump
  assertEquals("Cap/floor: LMM pricing by Monte Carlo", pvLastPreviousRun, pvLastMC.getAmount(EUR), TOLERANCE_PV);
  final MultipleCurrencyAmount pvLastExplicit = METHOD_LMM_CAP.presentValue(CAP_LAST, LMM_MULTICURVES);
  assertEquals("Cap/floor: LMM pricing by Monte Carlo", pvLastExplicit.getAmount(EUR), pvLastMC.getAmount(EUR), 2.5E+2);
  methodLmmMc = new LiborMarketModelMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), NB_PATH);
  final MultipleCurrencyAmount pv6MC = methodLmmMc.presentValue(CAP_6, EUR, LMM_MULTICURVES);
  final double pv6PreviousRun = 12081.062; // 12500 paths - 1Y jump
  assertEquals("Cap/floor: LMM pricing by Monte Carlo", pv6PreviousRun, pv6MC.getAmount(EUR), TOLERANCE_PV);
  final MultipleCurrencyAmount pv6Explicit = METHOD_LMM_CAP.presentValue(CAP_6, LMM_MULTICURVES);
  assertEquals("Cap/floor: LMM pricing by Monte Carlo", pv6Explicit.getAmount(EUR), pv6MC.getAmount(EUR), 1.0E+2);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:20,代码来源:CapFloorIborLMMDDMethodTest.java

示例8: capFloorParity

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test
/**
 * Tests payer/receiver/fixed parity.
 */
public void capFloorParity() {
  final MultipleCurrencyAmount pvCapExplicit = METHOD_LMM_CAP.presentValue(CAP_LAST, LMM_MULTICURVES);
  final MultipleCurrencyAmount pvFloorExplicit = METHOD_LMM_CAP.presentValue(FLOOR_LAST, LMM_MULTICURVES);
  final MultipleCurrencyAmount pvFixedExplicit = SWAP_PAYER.getFirstLeg().getNthPayment(NB_CPN_IBOR - 1).accept(PVDC, MULTICURVES);
  final MultipleCurrencyAmount pvIborExplicit = SWAP_PAYER.getSecondLeg().getNthPayment(NB_CPN_IBOR - 1).accept(PVDC, MULTICURVES);
  assertEquals("Cap/floor - LMM - present value Explcit- cap/floor/strike/Ibor parity", pvCapExplicit.getAmount(EUR) - pvFloorExplicit.getAmount(EUR) - pvFixedExplicit.getAmount(EUR),
      pvIborExplicit.getAmount(EUR), TOLERANCE_PV);
  LiborMarketModelMonteCarloMethod methodLmmMc;
  methodLmmMc = new LiborMarketModelMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), NB_PATH);
  final MultipleCurrencyAmount pvCapMC = methodLmmMc.presentValue(CAP_LAST, EUR, LMM_MULTICURVES);
  methodLmmMc = new LiborMarketModelMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), NB_PATH);
  final MultipleCurrencyAmount pvFloorMC = methodLmmMc.presentValue(FLOOR_LAST, EUR, LMM_MULTICURVES);
  assertEquals("Cap/floor - LMM - present value - cap/floor/strike/Ibor parity", pvCapMC.getAmount(EUR) - pvFloorMC.getAmount(EUR) - pvFixedExplicit.getAmount(EUR), pvIborExplicit.getAmount(EUR),
      1.0E+3);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:20,代码来源:CapFloorIborLMMDDMethodTest.java

示例9: performance

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test(enabled = false)
/**
 * Tests of performance. "enabled = false" for the standard testing.
 */
public void performance() {
  long startTime, endTime;
  final int nbTest = 10;

  LiborMarketModelMonteCarloMethod methodLmmMc;
  methodLmmMc = new LiborMarketModelMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), NB_PATH);
  final double[] pvMC = new double[nbTest];

  startTime = System.currentTimeMillis();
  for (int looptest = 0; looptest < nbTest; looptest++) {
    pvMC[looptest] = methodLmmMc.presentValue(CAP_LAST, EUR, LMM_MULTICURVES).getAmount(EUR);
  }
  endTime = System.currentTimeMillis();
  System.out.println(nbTest + " cap/floor LMM Monte Carlo method (" + NB_PATH + " paths): " + (endTime - startTime) + " ms");
  // Performance note: LMM Monte Carlo: 15-Sep-11: On Mac Pro 3.2 GHz Quad-Core Intel Xeon: 995 ms for 10 cap (12,500 paths).

}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:CapFloorIborLMMDDMethodTest.java

示例10: presentValueMonteCarlo

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test(enabled = true)
/**
 * Compare explicit formula with Monte-Carlo and long/short and payer/receiver parities.
 */
public void presentValueMonteCarlo() {
  HullWhiteMonteCarloMethod methodMC;
  methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), NB_PATH);
  // Seed fixed to the DEFAULT_SEED for testing purposes.
  final MultipleCurrencyAmount pvPayerLongExplicit = METHOD_HW.presentValue(SWAPTION_LONG_PAYER, HW_MULTICURVES);
  final MultipleCurrencyAmount pvPayerLongMC = methodMC.presentValue(SWAPTION_LONG_PAYER, EUR, HW_MULTICURVES);
  assertEquals("Swaption physical - Hull-White - Monte Carlo", pvPayerLongExplicit.getAmount(EUR), pvPayerLongMC.getAmount(EUR), 1.0E+4);
  final double pvMCPreviousRun = 4221400.891;
  assertEquals("Swaption physical - Hull-White - Monte Carlo", pvMCPreviousRun, pvPayerLongMC.getAmount(EUR), TOLERANCE_PV);
  methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), NB_PATH);
  final MultipleCurrencyAmount pvPayerShortMC = methodMC.presentValue(SWAPTION_SHORT_PAYER, EUR, HW_MULTICURVES);
  assertEquals("Swaption physical - Hull-White - Monte Carlo", -pvPayerLongMC.getAmount(EUR), pvPayerShortMC.getAmount(EUR), TOLERANCE_PV);
  final MultipleCurrencyAmount pvReceiverLongMC = methodMC.presentValue(SWAPTION_LONG_RECEIVER, EUR, HW_MULTICURVES);
  final MultipleCurrencyAmount pvSwap = SWAP_RECEIVER.accept(PVDC, MULTICURVES);
  assertEquals("Swaption physical - Hull-White - Monte Carlo - payer/receiver/swap parity", pvReceiverLongMC.getAmount(EUR) + pvPayerShortMC.getAmount(EUR), pvSwap.getAmount(EUR), 1.0E+5);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:21,代码来源:SwaptionPhysicalFixedIborHullWhiteMethodTest.java

示例11: presentValueMC

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test
/**
 * Test the present value: approximated formula vs Monte Carlo.
 */
public void presentValueMC() {
  LiborMarketModelMonteCarloMethod methodLmmMc;
  methodLmmMc = new LiborMarketModelMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), NB_PATH);
  final MultipleCurrencyAmount pvMC = methodLmmMc.presentValue(SWAPTION_PAYER_LONG, EUR, LMM_MULTICURVES);
  final double pvMCPreviousRun = 1997241.514;
  assertEquals("Swaption physical - LMM - present value Monte Carlo", pvMCPreviousRun, pvMC.getAmount(EUR), TOLERANCE_PV);
  final MultipleCurrencyAmount pvApprox = METHOD_LMM.presentValue(SWAPTION_PAYER_LONG, LMM_MULTICURVES);
  final double pvbp = METHOD_SWAP.presentValueBasisPoint(SWAP_RECEIVER, MULTICURVES);
  final double forward = SWAP_RECEIVER.accept(PRDC, MULTICURVES);
  final BlackFunctionData data = new BlackFunctionData(forward, pvbp, 0.20);
  final EuropeanVanillaOption option = new EuropeanVanillaOption(RATE, SWAPTION_PAYER_LONG.getTimeToExpiry(), FIXED_IS_PAYER);
  final BlackImpliedVolatilityFormula implied = new BlackImpliedVolatilityFormula();
  final double impliedVolMC = implied.getImpliedVolatility(data, option, pvMC.getAmount(EUR));
  final double impliedVolApprox = implied.getImpliedVolatility(data, option, pvApprox.getAmount(EUR));
  assertEquals("Swaption physical - LMM - present value Approximation/Monte Carlo", impliedVolMC, impliedVolApprox, 2.0E-3);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:21,代码来源:SwaptionPhysicalFixedIborLMMDDMethodTest.java

示例12: presentValueMonteCarloConvergence

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test(enabled = false)
/**
 * Test the present value by approximation vs Monte Carlo: convergence.
 */
public void presentValueMonteCarloConvergence() {
  final MultipleCurrencyAmount pvApproximation = METHOD_G2PP_APPROXIMATION.presentValue(SWAPTION_LONG_PAYER, G2PP_MULTICURVES);
  final int[] nbPath = new int[] {12500, 100000, 1000000, 10000000};
  final MultipleCurrencyAmount[] pvMC = new MultipleCurrencyAmount[nbPath.length];
  final double[] pvDiff = new double[nbPath.length];
  for (int loopmc = 0; loopmc < nbPath.length; loopmc++) {
    final G2ppMonteCarloMethod methodMC = new G2ppMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), nbPath[loopmc]);
    pvMC[loopmc] = methodMC.presentValue(SWAPTION_LONG_PAYER, CUR, G2PP_MULTICURVES);
    pvDiff[loopmc] = pvApproximation.getAmount(CUR) - pvMC[loopmc].getAmount(CUR);
  }
  assertEquals("Swaption physical - G2++ - present value - approximation vs Monte Carlo", pvApproximation.getAmount(CUR), pvMC[nbPath.length - 1].getAmount(CUR), 1.0E+3);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:SwaptionPhysicalFixedIborG2ppMethodTest.java

示例13: performanceMC

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test(enabled = false)
/**
 * Tests of performance. "enabled = false" for the standard testing.
 */
public void performanceMC() {
  long startTime, endTime;
  final int nbTest = 10;

  final int nbPath = 12500;
  final G2ppMonteCarloMethod methodMC = new G2ppMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), nbPath);
  @SuppressWarnings("unused")
  MultipleCurrencyAmount pvMC;

  startTime = System.currentTimeMillis();
  for (int looptest = 0; looptest < nbTest; looptest++) {
    pvMC = methodMC.presentValue(SWAPTION_LONG_PAYER, CUR, G2PP_MULTICURVES);
  }
  endTime = System.currentTimeMillis();
  System.out.println(nbTest + " pv swaption physical G2++ Monte Carlo with " + nbPath + " paths: " + (endTime - startTime) + " ms");
  // Performance note: G2++ price: 04-Dec-12: On Mac Pro 3.2 GHz Quad-Core Intel Xeon: 140 ms for 10 swaptions (12500 paths).
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:SwaptionPhysicalFixedIborG2ppMethodTest.java

示例14: presentValueFixedLeg

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test
/**
 * Test the Ratchet present value in the degenerate case where the coupon are fixed (floor=cap).
 */
public void presentValueFixedLeg() {
  HullWhiteMonteCarloMethod methodMC;
  methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), NB_PATH);
  final double[] mainFixed = new double[] {0.0, 0.0, 0.0};
  final double[] floorFixed = new double[] {0.0, 0.0, FIRST_CPN_RATE};
  final double[] capFixed = new double[] {0.0, 0.0, FIRST_CPN_RATE};
  final AnnuityCouponIborRatchetDefinition ratchetFixedDefinition = AnnuityCouponIborRatchetDefinition.withFirstCouponFixed(SETTLEMENT_DATE, ANNUITY_TENOR, NOTIONAL, EURIBOR3M, IS_PAYER,
      FIRST_CPN_RATE, mainFixed, floorFixed, capFixed, TARGET);
  final AnnuityCouponIborRatchet ratchetFixed = ratchetFixedDefinition.toDerivative(REFERENCE_DATE, FIXING_TS);
  final MultipleCurrencyAmount pvFixedMC = methodMC.presentValue(ratchetFixed, CUR, HW_MULTICURVES);

  final AnnuityCouponFixedDefinition fixedDefinition = AnnuityCouponFixedDefinition.from(CUR, SETTLEMENT_DATE, ANNUITY_TENOR, EURIBOR3M.getTenor(), TARGET, EURIBOR3M.getDayCount(),
      EURIBOR3M.getBusinessDayConvention(), EURIBOR3M.isEndOfMonth(), NOTIONAL, FIRST_CPN_RATE, IS_PAYER);
  final AnnuityCouponFixed fixed = fixedDefinition.toDerivative(REFERENCE_DATE);
  final MultipleCurrencyAmount pvFixedExpected = fixed.accept(PVDC, MULTICURVES);
  assertEquals("Annuity Ratchet Ibor - Hull-White - Monte Carlo - Degenerate in Fixed leg", pvFixedExpected.getAmount(CUR), pvFixedMC.getAmount(CUR), 2.0E+2);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:AnnuityCouponIborRatchetHullWhiteMethodTest.java

示例15: presentValueIborLeg

import cern.jet.random.engine.MersenneTwister; //导入依赖的package包/类
@Test(enabled = true)
/**
 * Test the Ratchet present value in the degenerate case where the coupon are ibor (no cap/floor, ibor factor=1.0).
 */
public void presentValueIborLeg() {
  final double[] mainIbor = new double[] {0.0, 1.0, 0.0};
  final double[] floorIbor = new double[] {0.0, 0.0, -10.0};
  final double[] capIbor = new double[] {0.0, 0.0, +50.0};
  final AnnuityCouponIborRatchetDefinition ratchetFixedDefinition = AnnuityCouponIborRatchetDefinition.withFirstCouponFixed(SETTLEMENT_DATE, ANNUITY_TENOR, NOTIONAL, EURIBOR3M, IS_PAYER,
      FIRST_CPN_RATE, mainIbor, floorIbor, capIbor, TARGET);
  final AnnuityCouponIborRatchet ratchetFixed = ratchetFixedDefinition.toDerivative(REFERENCE_DATE, FIXING_TS);
  final AnnuityCouponIborDefinition iborDefinition = AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, ANNUITY_TENOR, NOTIONAL, EURIBOR3M, IS_PAYER, TARGET);
  final Annuity<? extends Coupon> ibor = iborDefinition.toDerivative(REFERENCE_DATE, FIXING_TS);
  final Coupon[] iborFirstFixed = new Coupon[ibor.getNumberOfPayments()];
  iborFirstFixed[0] = ratchetFixed.getNthPayment(0);
  for (int loopcpn = 1; loopcpn < ibor.getNumberOfPayments(); loopcpn++) {
    iborFirstFixed[loopcpn] = ibor.getNthPayment(loopcpn);
  }
  final int nbPath = 175000;
  HullWhiteMonteCarloMethod methodMC;
  methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), nbPath);
  final MultipleCurrencyAmount pvIborMC = methodMC.presentValue(ratchetFixed, CUR, HW_MULTICURVES);
  final MultipleCurrencyAmount pvIborExpected = new Annuity<Payment>(iborFirstFixed).accept(PVDC, MULTICURVES);
  assertEquals("Annuity Ratchet Ibor - Hull-White - Monte Carlo - Degenerate in Ibor leg", pvIborExpected.getAmount(CUR), pvIborMC.getAmount(CUR), 3.0E+3);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:26,代码来源:AnnuityCouponIborRatchetHullWhiteMethodTest.java


注:本文中的cern.jet.random.engine.MersenneTwister类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。