SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
GeometricVarianceGammaProcess.java
1/*
2 * Class: GeometricVarianceGammaProcess
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 Pierre Tremblay
9 * @since July 2003
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
45 protected VarianceGammaProcess vargamma;
46 protected double theta, nu, mu, sigma, omega, muPlusOmega;
47 protected double[] mudt;
48
59 public GeometricVarianceGammaProcess(double s0, double theta, double sigma, double nu, double mu,
60 RandomStream stream) {
61 vargamma = new VarianceGammaProcess(0.0, theta, sigma, nu, stream);
62 setParams(s0, theta, sigma, nu, mu);
63 }
64
72 public GeometricVarianceGammaProcess(double s0, double mu, VarianceGammaProcess vargamma) {
73 this.vargamma = vargamma;
74 setParams(s0, vargamma.getTheta(), vargamma.getSigma(), vargamma.getNu(), mu);
75 }
76
77 public double nextObservation() {
78 double nextX = vargamma.nextObservation();
79 observationIndex = vargamma.getCurrentObservationIndex();
80 // Could be different than simply 'observationIndex++' because of the
81 // possibility of Gamma/Brownian bridge
82 observationCounter++;
83
84 double s = x0 * Math.exp(muPlusOmega * (t[observationIndex] - t[0]) + nextX);
85 path[observationIndex] = s;
86 return s;
87 }
88
89 public double[] generatePath() {
90 double s = x0;
92 double[] vgpath = vargamma.generatePath();
93 for (int i = 0; i < d; i++) {
94 s *= Math.exp(mudt[i] + vgpath[i + 1] - vgpath[i]);
95 path[i + 1] = s;
96 }
97 observationIndex = d;
98 observationCounter++;
99 return path;
100 }
101
102 // allows the user to create a path by specifiying the uniform random numbers to
103 // be used
104 public double[] generatePath(double[] uniform01) {
105 double s = x0;
107
108 double[] vgpath = vargamma.generatePath(uniform01);
109 for (int i = 0; i < d; i++) {
110 s *= Math.exp(mudt[i] + vgpath[i + 1] - vgpath[i]);
111 path[i + 1] = s;
112 }
113 observationIndex = d;
114 observationCounter++;
115 return path;
116 }
117
118 // method not verified by JS... old stuff
119 public double getCurrentUpperBound() {
120 // Find index for last observation generated (chronologically)
121 int j = 0; // By default, t0 !
122 int i = observationCounter - 1;
123 double tForIthObserv;
124 while (i > 0) {
125 tForIthObserv = t[observationIndexFromCounter[i]];
126 if (tForIthObserv <= t[observationCounter] && tForIthObserv > t[j])
127 j = i;
128 i--;
129 }
130
131 // Calculate bound following recipe
132 double u = 0.0;
133 GammaProcess gpos = ((VarianceGammaProcessDiff) vargamma).getGpos();
134 double[] gposPath = gpos.getPath();
135 double deltaGpos = gposPath[observationIndex] - gposPath[j];
136 double s = path[observationIndex];
137 if (muPlusOmega < 0)
138 u = s * Math.exp(deltaGpos);
139 else
140 u = s * Math.exp(muPlusOmega * (t[observationIndex] - t[j]) + deltaGpos);
141 return u;
142 }
143
149 public void resetStartProcess() {
150 observationIndex = 0;
151 observationCounter = 0;
152 vargamma.resetStartProcess();
153 }
154
162 public void setParams(double s0, double theta, double sigma, double nu, double mu) {
163 this.x0 = s0;
164 this.theta = theta;
165 this.sigma = sigma;
166 this.nu = nu;
167 this.mu = mu;
168 if (observationTimesSet)
169 init(); // Otherwise no need to.
170 }
171
175 public double getTheta() {
176 return theta;
177 }
178
182 public double getMu() {
183 return mu;
184 }
185
189 public double getNu() {
190 return nu;
191 }
192
196 public double getSigma() {
197 return sigma;
198 }
199
204 public double getOmega() {
205 return omega;
206 }
207
213 return vargamma;
214 }
215
216 protected void init() {
217 super.init();
218 if (1 <= theta * nu + sigma * sigma * nu / 2.0)
219 throw new IllegalArgumentException("theta*nu + sigma*sigma*nu / 2 >= 1");
220 omega = Math.log(1 - theta * nu - sigma * sigma * nu / 2.0) / nu;
221 muPlusOmega = mu + omega;
222
223 if (observationTimesSet) {
224 // Telling the variance gamma proc. about the observ. times
225 vargamma.setObservationTimes(t, d);
226
227 // We need to know in which order the observations are generated
228 this.observationIndexFromCounter = vargamma.getArrayMappingCounterToIndex();
229
230 mudt = new double[d];
231 for (int i = 0; i < d; i++)
232 mudt[i] = muPlusOmega * (t[i + 1] - t[i]);
233 }
234 }
235
236 public void setStream(RandomStream stream) {
237 vargamma.setStream(stream);
238 }
239
241 return vargamma.getStream();
242 }
243
244}
GeometricVarianceGammaProcess(double s0, double theta, double sigma, double nu, double mu, RandomStream stream)
Constructs a new GeometricVarianceGammaProcess with parameters.
double[] generatePath()
Generates, returns, and saves the sample path .
GeometricVarianceGammaProcess(double s0, double mu, VarianceGammaProcess vargamma)
Constructs a new GeometricVarianceGammaProcess.
VarianceGammaProcess getVarianceGammaProcess()
Returns a reference to the variance gamma process defined in the constructor.
RandomStream getStream()
Returns the random stream of the underlying generator.
double nextObservation()
Generates and returns the next observation of the stochastic process.
double getOmega()
Returns the value of the quantity defined in ( omegaEqn ).
void resetStartProcess()
Resets the GeometricaVarianceGammaProcess, but also applies the resetStartProcess method to the Varia...
void setStream(RandomStream stream)
Resets the random stream of the underlying generator to stream.
void setParams(double s0, double theta, double sigma, double nu, double mu)
Sets the parameters , , , and of the process.
Abstract base class for a stochastic process sampled (or observed) at a finite number of time points...
int[] getArrayMappingCounterToIndex()
Returns a reference to an array that maps an integer to , the index of the observation correspondin...
This class represents a variance gamma (VG) process .
double[] generatePath()
Generates and returns the path.
void setObservationTimes(double t[], int d)
Sets the observation times on the VarianceGammaProcess as usual, but also sets the observation times ...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...