SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
GeometricBrownianMotion.java
1/*
2 * Class: GeometricBrownianMotion
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.stochprocess;
26
27import umontreal.ssj.rng.*;
28import umontreal.ssj.probdist.*;
29import umontreal.ssj.randvar.*;
30
51
52 protected NormalGen gen;
53 protected BrownianMotion bm; // The underlying BM process X.
54 protected double mu, sigma;
55 protected double[] mudt;
56
61 public GeometricBrownianMotion(double s0, double mu, double sigma, RandomStream stream) {
62 this(s0, mu, sigma, new BrownianMotion(0.0, 0.0, 1.0, stream));
63 }
64
76 public GeometricBrownianMotion(double s0, double mu, double sigma, BrownianMotion bm) {
77 this.bm = bm;
78 setParams(s0, mu, sigma);
79 }
80
81 public void setObservationTimes(double[] t, int d) {
82 this.d = d;
83 super.setObservationTimes(t, d);
84 bm.setObservationTimes(t, d);
85 }
86
87 public double nextObservation() {
88 // Note : this implementation is general, to deal with
89 // the possibility of generating bm with bridge sampling, for example. ???
90
91 double s = x0 * Math.exp(bm.nextObservation());
92 observationIndex = bm.getCurrentObservationIndex();
93 path[observationIndex] = s;
94 // Could be different than simply 'observationCounter++' because of the
95 // possibility of Brownian bridge
96
97 return s;
98 }
99
100 public double[] generatePath() {
101 path[0] = x0;
102 bm.generatePath();
103 for (int i = 1; i <= d; ++i)
104 path[i] = x0 * Math.exp(bm.getObservation(i));
105 observationCounter = d;
106 return path;
107 }
108
109 public double[] generatePath(RandomStream stream) {
110 setStream(stream);
111 return generatePath();
112 }
113
118 public void resetStartProcess() {
119 observationCounter = 0;
120 bm.resetStartProcess();
121 }
122
129 public void setParams(double s0, double mu, double sigma) {
130 this.x0 = s0;
131 this.mu = mu;
132 this.sigma = sigma;
133 bm.setParams(0.0, mu - 0.5 * sigma * sigma, sigma);
134 if (observationTimesSet)
135 init(); // Otherwise not needed.
136 }
137
142 public void setStream(RandomStream stream) {
143 (bm.gen).setStream(stream);
144 }
145
151 return (bm.gen).getStream();
152 }
153
157 public double getMu() {
158 return mu;
159 }
160
164 public double getSigma() {
165 return sigma;
166 }
167
171 public NormalGen getGen() {
172 return gen;
173 }
174
180 return bm;
181 }
182
183 protected void init() {
184 super.init(); // Maybe useless...
185 }
186
187}
This class implements methods for generating random variates from the normal distribution .
This class represents a Brownian motion process , sampled at times .
void setStream(RandomStream stream)
Resets the umontreal.ssj.rng.RandomStream for the underlying Brownian motion to stream.
NormalGen getGen()
Returns the umontreal.ssj.randvar.NormalGen used.
GeometricBrownianMotion(double s0, double mu, double sigma, BrownianMotion bm)
Constructs a new GeometricBrownianMotion with parameters , , and , using bm as the underlying Browni...
RandomStream getStream()
Returns the umontreal.ssj.rng.RandomStream for the underlying Brownian motion.
BrownianMotion getBrownianMotion()
Returns a reference to the BrownianMotion object used to generate the process.
double[] generatePath()
Generates, returns, and saves the sample path .
double[] generatePath(RandomStream stream)
Same as generatePath(), but first resets the stream to stream.
void setParams(double s0, double mu, double sigma)
Sets the parameters , and of the process.
void setObservationTimes(double[] t, int d)
Sets the observation times of the process to a copy of T, with.
GeometricBrownianMotion(double s0, double mu, double sigma, RandomStream stream)
Same as GeometricBrownianMotion (s0, mu, sigma, new BrownianMotion (0.0, 0.0, 1.0,...
void resetStartProcess()
Same as in StochasticProcess, but also invokes resetStartProcess for the underlying BrownianMotion ob...
double nextObservation()
Generates and returns the next observation of the stochastic process.
Abstract base class for a stochastic process sampled (or observed) at a finite number of time points...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...