Package com.opengamma.analytics.math.random

Examples of com.opengamma.analytics.math.random.NormalRandomNumberGenerator


    // The matrix of simulated recovery rates per simulation to output
    double[][] simulatedRecoveryRateScenarios = new double[numberOfSimulations][numberOfObligors];

    // Construct a N(0, 1) random number generator
    NormalRandomNumberGenerator normRand = new NormalRandomNumberGenerator(0.0, 1.0);

    // Construct a N(0, 1) distribution object (for calculating the default barrier level)
    NormalDistribution normDist = new NormalDistribution(0.0, 1.0);

    // Compute the vector of systemic factors
    final double[] systemicFactor = normRand.getVector(numberOfSimulations);

    // Main loop of simulation
    for (int alpha = 0; alpha < numberOfSimulations; alpha++) {

      // Loop over each of the obligors
      for (int i = 0; i < numberOfObligors; i++) {

        // Did obligor i default on scenario alpha ...
        if (simulatedDefaultScenarios[alpha][i] == SimulatedObligorDefaultState.DEFAULTED) {

          // ... yes, then calculate the stochastic recovery rate

          // Calculate an idiosyncratic N(0, 1) deviate
          final double[] eta = normRand.getVector(1);

          // Get the correlation (coupling) of the sampled recovery rate with the systemic factor
          final double beta = scenarioGenerator.getBeta()[i];

          // Compute the recovery rate latent variable for this obligor for this simulation
View Full Code Here


  // Method to generate a vector of N(0, 1) deviates corresponding to the systemic factor for each simulation
  private double[] generateSystemicFactors(final int numberOfSimulations, final int defaultSimulationSeed) {

    // Construct a N(0, 1) random number generator
    NormalRandomNumberGenerator normRand = new NormalRandomNumberGenerator(0.0, 1.0);

    // Compute the vector of systemic factors
    final double[] systemicFactor = normRand.getVector(numberOfSimulations);

    return systemicFactor;
  }
View Full Code Here

    // Determine the number of simulations and number of obligors in the universe
    int numberOfSimulations = scenarioGenerator.getNumberofSimulations();
    int numberOfObligors = scenarioGenerator.getObligorUniverse().getNumberOfObligors();

    // Construct a N(0, 1) random number generator
    NormalRandomNumberGenerator normRand = new NormalRandomNumberGenerator(0.0, 1.0);

    // The matrix of simulated defaults per simulation to output
    SimulatedObligorDefaultState[][] simulatedDefaultScenarios = new SimulatedObligorDefaultState[numberOfSimulations][numberOfObligors];

    // Compute the default barrier level for each obligor
    final double[] defaultBarrierLevel = generateDefaultBarrierLevels(scenarioGenerator);

    // Compute the vector of systemic factors (one sample for each simulation)
    final double[] systemicFactor = generateSystemicFactors(numberOfSimulations, scenarioGenerator.getDefaultSimulationSeed());

    // Main loop of simulation
    for (int alpha = 0; alpha < numberOfSimulations; alpha++) {

      // Construct a vector of idiosyncratic N(0, 1) deviates for this simulation
      final double[] epsilon = normRand.getVector(numberOfObligors);

      // Loop over each of the obligors
      for (int i = 0; i < numberOfObligors; i++) {

        // Get the correlation (coupling) of the default of this obligor with the systemic factor
View Full Code Here

    Validate.notNull(swaption);
    Validate.notNull(curves);
    if (!(curves instanceof HullWhiteOneFactorPiecewiseConstantDataBundle)) {
      throw new UnsupportedOperationException("The PresentValueHullWhiteMonteCarloCalculator visitor visitSwaptionPhysicalFixedIbor requires a HullWhiteOneFactorPiecewiseConstantDataBundle as data.");
    }
    final HullWhiteMonteCarloMethod methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), _nbPath);
    final CurrencyAmount pvMC = methodMC
        .presentValue(swaption, swaption.getCurrency(), swaption.getUnderlyingSwap().getFirstLeg().getDiscountCurve(), (HullWhiteOneFactorPiecewiseConstantDataBundle) curves);
    return pvMC.getAmount();
  }
View Full Code Here

    Validate.notNull(annuity);
    Validate.notNull(curves);
    if (!(curves instanceof HullWhiteOneFactorPiecewiseConstantDataBundle)) {
      throw new UnsupportedOperationException("The PresentValueHullWhiteMonteCarloCalculator visitor visitSwaptionPhysicalFixedIbor requires a HullWhiteOneFactorPiecewiseConstantDataBundle as data.");
    }
    final HullWhiteMonteCarloMethod methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), _nbPath);
    final CurrencyAmount pvMC = methodMC.presentValue(annuity, annuity.getCurrency(), annuity.getDiscountCurve(), (HullWhiteOneFactorPiecewiseConstantDataBundle) curves);
    return pvMC.getAmount();
  }
View Full Code Here

    _nbPath = nbPath;
  }

  @Override
  public MultipleCurrencyAmount visitAnnuityCouponIborRatchet(final AnnuityCouponIborRatchet annuity, final HullWhiteOneFactorProviderInterface hullWhite) {
    HullWhiteMonteCarloMethod methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), _nbPath);
    return methodMC.presentValue(annuity, annuity.getCurrency(), hullWhite);
  }
View Full Code Here

    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);
  }
View Full Code Here

    _nbPath = nbPath;
  }

  @Override
  public MultipleCurrencyMulticurveSensitivity visitAnnuityCouponIborRatchet(final AnnuityCouponIborRatchet annuity, final HullWhiteOneFactorProviderInterface hullWhite) {
    HullWhiteMonteCarloMethod methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), _nbPath);
    return methodMC.presentValueCurveSensitivity(annuity, annuity.getCurrency(), hullWhite);
  }
View Full Code Here

  /**
   * 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);
View Full Code Here

   * Tests the curve sensitivity in Monte Carlo approach.
   */
  public void presentValueCurveSensitivityMonteCarlo() {
    final double toleranceDelta = 1.0E+6; // 100 USD by bp
    final MultipleCurrencyMulticurveSensitivity pvcsExplicit = METHOD_HW.presentValueCurveSensitivity(SWAPTION_LONG_PAYER, HW_MULTICURVES).cleaned(TOLERANCE_PV_DELTA);
    final HullWhiteMonteCarloMethod methodMC = new HullWhiteMonteCarloMethod(new NormalRandomNumberGenerator(0.0, 1.0, new MersenneTwister()), NB_PATH);
    final MultipleCurrencyMulticurveSensitivity pvcsMC = methodMC.presentValueCurveSensitivity(SWAPTION_LONG_PAYER, EUR, HW_MULTICURVES).cleaned(TOLERANCE_PV_DELTA);
    AssertSensivityObjects.assertEquals("Swaption physical - Hull-White - presentValueCurveSensitivity - payer/receiver/swap parity", pvcsExplicit, pvcsMC, toleranceDelta);
  }
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.math.random.NormalRandomNumberGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.