/* *
* Title:
* Description:
* Copyright: Copyright (c)
* Company:
* @author
* @version 1.0
*/
package umontreal.iro.lecuyer.stochprocess;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
import umontreal.iro.lecuyer.randvar.*;
/**
* .
*
* Represents a geometric Brownian motion (GBM) process
* {S(t), t >= 0},
* which evolves according to the stochastic differential equation
*
*
* where μ and σ are the drift and volatility parameters,
* and
* {B(t), t >= 0} is a standard Brownian motion
* (for which
* B(t)∼N(0, t)).
* This process can also be written as the exponential of a Brownian motion:
*
*
* where
* X(t) = (μ - σ2/2)t + σtB(t).
* The GBM process is simulated by simulating the BM process X and taking the exponential.
* This BM process is stored internally.
*
*/
public class GeometricBrownianMotion extends StochasticProcess {
protected NormalGen gen;
protected BrownianMotion bm; // The underlying BM process X.
protected double mu,
sigma;
protected double[] mudt;
/**
* Same as GeometricBrownianMotion (s0, mu, sigma,
* new BrownianMotion (0.0, 0.0, 1.0, stream)).
*
*/
public GeometricBrownianMotion (double s0, double mu, double sigma,
RandomStream stream) {
this (s0, mu, sigma, new BrownianMotion (0.0, 0.0, 1.0, stream));
}
/**
* Constructs a new GeometricBrownianMotion with parameters
*
* μ = mu ,
* σ = sigma , and
* S(t0) = s0 ,
* using bm as the underlying {@link BrownianMotion}.
* The parameters of bm are automatically reset to
*
* μ - σ2/2 and σ, regardless of the original parameters
* of bm.
* The observation times are the same as those of bm. The generation
* method depends on that of bm (sequential, bridge sampling, PCA, etc.).
*
*/
public GeometricBrownianMotion (double s0, double mu, double sigma,
BrownianMotion bm) {
this.bm = bm;
setParams (s0, mu, sigma);
}
public void setObservationTimes (double[] t, int d) {
this.d = d;
super.setObservationTimes (t, d);
bm.setObservationTimes (t, d);
}
public double nextObservation() {
// Note : this implementation is general, to deal with
// the possibility of generating bm with bridge sampling, for example. ???
double s = x0 * Math.exp (bm.nextObservation());
observationIndex = bm.getCurrentObservationIndex();
path[observationIndex] = s;
// Could be different than simply 'observationCounter++' because of the
// possibility of Brownian bridge
return s;
}
public double[] generatePath() {
path[0] = x0;
bm.generatePath ();
for (int i = 1; i <= d; ++i)
path[i] = x0 * Math.exp (bm.getObservation(i));
observationCounter = d;
return path;
}
public double[] generatePath (RandomStream stream) {
setStream (stream);
return generatePath();
}
/**
* Same as in StochasticProcess, but also invokes
* resetStartProcess for the underlying BrownianMotion object.
*
*/
public void resetStartProcess() {
observationCounter = 0;
bm.resetStartProcess();
}
/**
* Sets the parameters
* S(t0) = s0 ,
* μ = mu and
*
* σ = sigma of the process.
* Warning: This method will recompute some quantities stored internally,
* which may be slow if called repeatedly.
*
*/
public void setParams (double s0, double mu, double sigma) {
this.x0 = s0;
this.mu = mu;
this.sigma = sigma;
bm.setParams (0.0, mu - 0.5 * sigma * sigma, sigma);
if (observationTimesSet) init(); // Otherwise not needed.
}
/**
* Resets the {@link umontreal.iro.lecuyer.rng.RandomStream RandomStream}
* for the underlying Brownian motion to stream.
*
*/
public void setStream (RandomStream stream) { (bm.gen).setStream (stream); }
/**
* Returns the {@link umontreal.iro.lecuyer.rng.RandomStream RandomStream}
* for the underlying Brownian motion.
*
*/
public RandomStream getStream() { return (bm.gen).getStream (); }
/**
* Returns the value of μ.
*
*/
public double getMu() { return mu; }
/**
* Returns the value of σ.
*
*/
public double getSigma() { return sigma; }
/**
* Returns the {@link umontreal.iro.lecuyer.randvar.NormalGen NormalGen} used.
*
*/
public NormalGen getGen() { return gen; }
/**
* Returns a reference to the {@link BrownianMotion} object
* used to generate the process.
*
*/
public BrownianMotion getBrownianMotion() {
return bm;
}
protected void init() {
super.init(); // Maybe useless...
}
}
Ads help maintain this website.