net.finmath.montecarlo.interestrate.simple.SimpleLIBORMarketModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of finmath-lib Show documentation
Show all versions of finmath-lib Show documentation
finmath lib is a Mathematical Finance Library in Java.
It provides algorithms and methodologies related to mathematical finance.
The newest version!
/* * Created on 09.02.2004 */ package net.finmath.montecarlo.interestrate.simple; import java.util.Arrays; import java.util.Map; import net.finmath.montecarlo.BrownianMotion; import net.finmath.montecarlo.BrownianMotionFromMersenneRandomNumbers; import net.finmath.montecarlo.RandomVariableFromDoubleArray; import net.finmath.montecarlo.interestrate.models.LIBORMarketModelFromCovarianceModel; import net.finmath.montecarlo.interestrate.models.covariance.LIBORCorrelationModel; import net.finmath.montecarlo.interestrate.models.covariance.LIBORCorrelationModelExponentialDecay; import net.finmath.montecarlo.interestrate.models.covariance.LIBORCovarianceModel; import net.finmath.montecarlo.interestrate.models.covariance.LIBORCovarianceModelFromVolatilityAndCorrelation; import net.finmath.montecarlo.interestrate.models.covariance.LIBORVolatilityModel; import net.finmath.montecarlo.process.MonteCarloProcess; import net.finmath.stochastic.RandomVariable; import net.finmath.time.TimeDiscretization; /** * Implements a basic LIBOR market model with a some drift approximation methods. * * This is a simpler version. Useful for studying. * * A more flexible / complex version of the model can be created by using {@link net.finmath.montecarlo.interestrate.models.LIBORMarketModelFromCovarianceModel} * as an input to an {@link net.finmath.montecarlo.process.EulerSchemeFromProcessModel}. * * @author Christian Fries * @version 0.5 * @since finmath-lib 4.1.0 */ public class SimpleLIBORMarketModel extends AbstractLIBORMarketModel { public enum Driftapproximation { EULER, LINE_INTEGRAL, PREDICTOR_CORRECTOR } public enum Measure { SPOT, TERMINAL } private final double[] liborInitialValues; private LIBORCovarianceModel covarianceModel; private Driftapproximation driftAproximationMethod = Driftapproximation.EULER; private Measure measure = Measure.SPOT; /** * Creates a LIBOR Market Model for given covariance. * * @param timeDiscretization The time discretization of the process (simulation time). * @param liborPeriodDiscretization The discretization of the interest rate curve into forward rates (tenor structure). * @param numberOfPaths The number of paths. * @param liborInitialValues The initial values for the forward rates. * @param covarianceModel The covariance model to use. */ public SimpleLIBORMarketModel( final TimeDiscretization timeDiscretization, final TimeDiscretization liborPeriodDiscretization, final int numberOfPaths, final double[] liborInitialValues, final LIBORCovarianceModel covarianceModel ) { super( liborPeriodDiscretization, new BrownianMotionFromMersenneRandomNumbers(timeDiscretization, covarianceModel.getNumberOfFactors(), numberOfPaths, 3141 /* seed */) ); this.liborInitialValues = liborInitialValues; this.covarianceModel = covarianceModel; } /** * Creates a LIBOR Market Model for given covariance. * * @param liborPeriodDiscretization The discretization of the interest rate curve into forward rates (tenor structure). * @param liborInitialValues The initial values for the forward rates. * @param covarianceModel The covariance model to use. * @param brownianMotion The brownian driver for the Monte-Carlo simulation. */ public SimpleLIBORMarketModel( final TimeDiscretization liborPeriodDiscretization, final double[] liborInitialValues, final LIBORCovarianceModel covarianceModel, final BrownianMotion brownianMotion ) { super(liborPeriodDiscretization, brownianMotion); if(covarianceModel.getNumberOfFactors() > brownianMotion.getNumberOfFactors()) { throw new RuntimeException("Number of factors in covariance model is larger than number of Brownian drivers."); } this.liborInitialValues = liborInitialValues; this.covarianceModel = covarianceModel; } /** * Creates a LIBOR Market Model for given volatility and correlation model. * * @param timeDiscretizationFromArray The time discretization of the process (simulation time). * @param liborPeriodDiscretization The discretization of the interest rate curve into forward rates (tenor structure). * @param numberOfPaths The number of paths. * @param liborInitialValues The initial values for the forward rates. * @param volatilityModel The volatility model to use. * @param correlationModel The correlation model to use. */ public SimpleLIBORMarketModel( final TimeDiscretization timeDiscretizationFromArray, final TimeDiscretization liborPeriodDiscretization, final int numberOfPaths, final double[] liborInitialValues, final LIBORVolatilityModel volatilityModel, final LIBORCorrelationModel correlationModel ) { super( liborPeriodDiscretization, new BrownianMotionFromMersenneRandomNumbers(timeDiscretizationFromArray, correlationModel.getNumberOfFactors(), numberOfPaths, 3141 /* seed */) ); this.liborInitialValues = liborInitialValues; covarianceModel = new LIBORCovarianceModelFromVolatilityAndCorrelation(timeDiscretizationFromArray, liborPeriodDiscretization, volatilityModel, correlationModel); } /** * Creates a one factor LIBOR Market Model (correlation = 1). * * @param timeDiscretizationFromArray The time discretization of the process (simulation time). * @param liborPeriodDiscretization The discretization of the interest rate curve into forward rates (tenor structure). * @param numberOfPaths The number of paths. * @param liborInitialValues The initial values for the forward rates. * @param volatilityModel The volatility model to use. */ public SimpleLIBORMarketModel( final TimeDiscretization timeDiscretizationFromArray, final TimeDiscretization liborPeriodDiscretization, final int numberOfPaths, final double[] liborInitialValues, final LIBORVolatilityModel volatilityModel ) { super( liborPeriodDiscretization, new BrownianMotionFromMersenneRandomNumbers(timeDiscretizationFromArray, 1 /* numberOfFactors */, numberOfPaths, 3141 /* seed */) ); this.liborInitialValues = liborInitialValues; covarianceModel = new LIBORCovarianceModelFromVolatilityAndCorrelation(timeDiscretizationFromArray, liborPeriodDiscretization, volatilityModel, new LIBORCorrelationModelExponentialDecay(timeDiscretizationFromArray, liborPeriodDiscretization, 1, 0.0, false)); } /* (non-Javadoc) * @see com.spacelike.fdml.monteCarlo.stockOptionPricing.LogNormalProcess#getInitialValue() */ @Override public RandomVariable[] getInitialValue() { final RandomVariable[] initialValueRandomVariable = new RandomVariable[getNumberOfComponents()]; for(int componentIndex=0; componentIndex
*/ @Override public RandomVariable getNumeraire(final int timeIndex) { final double time = getTime(timeIndex); // Get the start of the product int firstLiborIndex = this.getLiborPeriodIndex(time); // while(liborPeriodDiscretization[firstLiborIndex] < time) firstLiborIndex++; // Get the end of the product int lastLiborIndex = getLiborPeriodDiscretization().getNumberOfTimeSteps()-1; if(measure == Measure.SPOT) { // Spot measure firstLiborIndex = 0; lastLiborIndex = this.getLiborPeriodIndex(time)-1; if(lastLiborIndex < -1) { System.out.println("Interpolation on Numeraire not supported."); } } /** * Calculation of the numeraire (terminal measure) */ final double[] numeraire = new double[getNumberOfPaths()]; // Initialize to 1.0 Arrays.fill(numeraire,1.0); // The product for(int liborIndex = firstLiborIndex; liborIndex<=lastLiborIndex; liborIndex++) { final RandomVariable libor = getProcessValue(Math.min(timeIndex,liborIndex), liborIndex); final double periodLength = getLiborPeriodDiscretization().getTimeStep(liborIndex); if(measure == Measure.SPOT) { for(int path=0; path= this.getLiborPeriod(componentIndex)) { drift[componentIndex] = null; continue; } drift[componentIndex] = this.getDrift(timeIndex, componentIndex, realizationAtTimeIndex, realizationPredictor); } return drift; } /* (non-Javadoc) * @see com.spacelike.fdml.monteCarlo.stockOptionPricing.LogNormalProcess#getDrift(int, int) */ @Override public RandomVariable getDrift(final int timeIndex, final int componentIndex, final RandomVariable[] realizationAtTimeIndex, final RandomVariable[] realizationPredictor) { // The following is the drift of the LIBOR component final int numberOfPaths = getNumberOfPaths(); final double time = getTime(timeIndex); /* * We implemented several different methods to calculate the drift */ final RandomVariable[] liborVectorStart = realizationAtTimeIndex; final RandomVariable[] liborVectorEnd = realizationPredictor; if(driftAproximationMethod == Driftapproximation.PREDICTOR_CORRECTOR && liborVectorEnd != null) { final double[] drift = getLMMTerminasureDriftEuler(timeIndex, componentIndex, liborVectorStart); final double[] driftEulerWithPredictor = getLMMTerminasureDriftEuler(timeIndex, componentIndex, liborVectorEnd); for(int pathIndex=0; pathIndex RandomVariable dataModified) { throw new RuntimeException("Method not implemented"); } @Override public Object getCloneWithModifiedSeed(final int seed) { return new SimpleLIBORMarketModel( getLiborPeriodDiscretization(), liborInitialValues, getCovarianceModel(), new BrownianMotionFromMersenneRandomNumbers(getTimeDiscretization(), covarianceModel.getNumberOfFactors(), getNumberOfPaths(), seed) ); } /* (non-Javadoc) * @see net.finmath.montecarlo.interestrate.LIBORModelMonteCarloSimulationModel#getModel() */ @Override public LIBORMarketModelFromCovarianceModel getModel() { // TODO Auto-generated method stub return null; } /* (non-Javadoc) * @see net.finmath.montecarlo.interestrate.LIBORModelMonteCarloSimulationModel#getProcess() */ @Override public MonteCarloProcess getProcess() { // TODO Auto-generated method stub return null; } /* (non-Javadoc) * @see net.finmath.montecarlo.MonteCarloSimulationModel#getRandomVariableForConstant(double) */ @Override public RandomVariable getRandomVariableForConstant(final double value) { return getBrownianMotion().getRandomVariableForConstant(value); } @Override public Map getModelParameters() { // TODO Add implementation throw new UnsupportedOperationException(); } }