SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
VarianceGammaProcessDiff.java
1/*
2 * Class: VarianceGammaProcessDiff
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 2004
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
49public class VarianceGammaProcessDiff extends VarianceGammaProcess {
50 protected GammaProcess gpos;
51 protected GammaProcess gneg;
52 protected double mup, mun, nup, nun;
53
69 public VarianceGammaProcessDiff(double s0, double theta, double sigma, double nu, RandomStream stream) {
70 this(s0, theta, sigma, nu, new GammaProcess(0.0, 1.0, 1.0, stream), new GammaProcess(0.0, 1.0, 1.0, stream));
71 // Params mu, nu of the 2 gamma processes are redefined in init()
72 // which will be called after a call to 'setObservTimes'
73 }
74
85 public VarianceGammaProcessDiff(double s0, double theta, double sigma, double nu, GammaProcess gpos,
86 GammaProcess gneg) {
87 this.gpos = gpos;
88 this.gneg = gneg;
89 setParams(s0, theta, sigma, nu);
90 gneg.setStream(gpos.getStream()); // to avoid confusion with stream because there is only
91 // one stream in the other constructor
92 }
93
94 public double nextObservation() {
95 // This implementation takes possible bridge sampling into account
96 double s = x0 + gpos.nextObservation() - gneg.nextObservation();
97 observationIndex = gpos.getCurrentObservationIndex();
98 path[observationIndex] = s;
99 observationCounter++;
100 return s;
101 }
102
103// no longer useful, this method was created to automaticaly alternate
104// between the two processes the uniform random variables used in the
105// in the simulation. However, this method does not work if the two
106// GammaProcess are PCA...
107// public double[] generatePath() {
108// gpos.resetStartProcess();
109// gneg.resetStartProcess();
110// double s;
111// for (int i=1; i<=d; i++) {
112// s = x0 + gpos.nextObservation() - gneg.nextObservation();
113// path[gpos.getCurrentObservationIndex()] = s;
114// // Note: we must get the observCounter from gpos in the case that
115// // the process is generated by a Gamma bridge
116// // The observCounter of gneg should be the same because both
117// // gamma processes should be generated the same way
118// }
119// observationIndex = d;
120// observationCounter = d;
121// return path;
122// }
123
132 public double[] generatePath() {
133 double[] pathUP = gpos.generatePath();
134 double[] pathDOWN = gneg.generatePath();
135
136 for (int i = 0; i < d; i++) {
137 path[i + 1] = x0 + pathUP[i + 1] - pathDOWN[i + 1];
138 }
139 observationIndex = d;
140 observationCounter = d;
141 return path;
142 }
143
156 public double[] generatePath(double[] uniform01) {
157 int dd = uniform01.length;
158 int d = dd / 2;
159
160 if (dd % 2 != 0) {
161 throw new IllegalArgumentException("The Array uniform01 must have a even length");
162 }
163
164 double[] QMCpointsUP = new double[d];
165 double[] QMCpointsDW = new double[d];
166
167 for (int i = 0; i < d; i++) {
168 QMCpointsUP[i] = uniform01[2 * i]; // keeps the odd numbers for the gamma process
169 QMCpointsDW[i] = uniform01[2 * i + 1]; // and the even for the BM process
170 }
171 gpos.resetStartProcess();
172 gneg.resetStartProcess();
173
174 double[] pathUP = gpos.generatePath(QMCpointsUP);
175 double[] pathDOWN = gneg.generatePath(QMCpointsDW);
176
177 for (int i = 0; i < d; i++) {
178 path[i + 1] = x0 + pathUP[i + 1] - pathDOWN[i + 1];
179 }
180 observationIndex = d;
181 observationCounter = d;
182 return path;
183 }
184
191 public void resetStartProcess() {
192 observationIndex = 0;
193 observationCounter = 0;
194 gpos.resetStartProcess();
195 gneg.resetStartProcess();
196 }
197
203 return gpos;
204 }
205
211 return gneg;
212 }
213
214 protected void init() {
215 // super.init() is not called because the init() in VarianceGammaProcess
216 // is very different.
217 mup = 0.5 * (Math.sqrt(theta * theta + 2 * sigma * sigma / nu) + theta);
218 mun = 0.5 * (Math.sqrt(theta * theta + 2 * sigma * sigma / nu) - theta);
219 nup = mup * mup * nu;
220 nun = mun * mun * nu;
221 if (observationTimesSet) {
222 path[0] = x0;
223 gpos.setParams(t[0], mup, nup);
224 gneg.setParams(t[0], mun, nun);
225 }
226 }
227
232 public void setObservationTimes(double t[], int d) {
233 gpos.setObservationTimes(t, d);
234 gneg.setObservationTimes(t, d);
235 super.setObservationTimes(t, d);
236// the initial value is set to t[0] in the init, which is called in
237// super.setObservationTimes(t, d).
238 }
239
244 return gpos.getStream();
245 }
246
252 public void setStream(RandomStream stream) {
253 gpos.setStream(stream);
254 gneg.setStream(stream);
255 }
256
257}
This class represents a gamma process fmad98a  (page 82) with mean parameter.
void setParams(double s0, double mu, double nu)
Sets the parameters , and of the process.
void setStream(RandomStream stream)
Sets the umontreal.ssj.rng.RandomStream of the two.
VarianceGammaProcessDiff(double s0, double theta, double sigma, double nu, GammaProcess gpos, GammaProcess gneg)
The parameters of the GammaProcess objects for and are set to those of ( dblGammaParams ) and their...
double[] generatePath(double[] uniform01)
Similar to the usual generatePath(), but here the uniform random numbers used for the simulation must...
double[] generatePath()
Generates, returns and saves the path.
GammaProcess getGpos()
Returns a reference to the GammaProcess object gpos used to generate the component of the process.
void resetStartProcess()
Sets the observation times on the VarianceGammaProcessDiff as usual, but also applies the resetStartP...
VarianceGammaProcessDiff(double s0, double theta, double sigma, double nu, RandomStream stream)
Constructs a new VarianceGammaProcessDiff with parameters.
double nextObservation()
Generates the observation for the next time.
GammaProcess getGneg()
Returns a reference to the GammaProcess object gneg used to generate the component of the process.
void setObservationTimes(double t[], int d)
Sets the observation times on the VarianceGammaProcesDiff as usual, but also sets the observation tim...
RandomStream getStream()
Returns the RandomStream of the process.
void setParams(double s0, double theta, double sigma, double nu)
Sets the parameters s0, theta,.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...