SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
AsianGBMRQMC.java
1package tutorial;
2
3import java.io.IOException;
4import umontreal.ssj.rng.*;
5import umontreal.ssj.hups.*;
6import umontreal.ssj.stat.Tally;
7import umontreal.ssj.util.Chrono;
8
9// An extension of AsianGBM that uses RQMC point sets.
10public class AsianGBMRQMC extends AsianGBM {
11
12 public AsianGBMRQMC(double r, double sigma, double strike, double s0, int s, double[] zeta) {
13 super(r, sigma, strike, s0, s, zeta);
14 }
15
16 // Makes m independent randomizations of the RQMC point set prqmc.
17 // For each of them, performs one simulation run for each point
18 // of prqmc, and adds the average over these points to the collector statRQMC.
19 public void simulateRunsRQMC(int m, RQMCPointSet prqmc, Tally statRQMC) {
20 Tally statValue = new Tally("stat on value of Asian option");
21 int n = prqmc.getNumPoints();
22 PointSetIterator stream = prqmc.iterator();
23 for (int j = 0; j < m; j++) {
24 prqmc.randomize();
25 stream.resetStartStream();
26 simulateRuns(n, stream, statValue);
27 statRQMC.add(statValue.average());
28 }
29 }
30
31 public static void main(String[] args) throws IOException {
32 int d = 12;
33 double[] zeta = new double[d + 1];
34 for (int j = 0; j <= d; j++)
35 zeta[j] = (double) j / (double) d;
36 AsianGBMRQMC process = new AsianGBMRQMC(0.05, 0.5, 100.0, 100.0, d, zeta);
37 Tally statMC = new Tally("value of Asian option");
38 Tally statRQMC = new Tally("RQMC averages for Asian option under GBM");
39 Chrono timer = new Chrono();
40
41 // We first perform a Monte Carlo experiment, to compare with RQMC.
42 int n = 100000;
43 System.out.println("Ordinary MC:\n");
44 process.simulateRuns(n, new LFSR113(), statMC);
46 System.out.println(statMC.report(0.95, 3));
47 System.out.println("Total CPU time: " + timer.format());
48 System.out.println("------------------------\n");
49 double varMC = statMC.variance();
50 double cpuMC = timer.getSeconds() / n; // CPU seconds per run.
51
52 // Then we make a RQMC experiment, and compare the work-normalized variances (or
53 // efficiencies).
54 timer.init();
55 DigitalNet p = new SobolSequence(16, 31, d); // n = 2^{16} points in d dim.
57 RQMCPointSet prqmc = new RQMCPointSet(p, rand);
58 n = p.getNumPoints(); // Number of RQMC points.
59 int m = 50; // Number of RQMC randomizations.
60 process.simulateRunsRQMC(m, prqmc, statRQMC);
61 System.out.println("RQMC with Sobol point set with " + n + " points and affine matrix scramble:\n");
63 System.out.println(statRQMC.report(0.95, 3));
64 System.out.println("Total CPU time: " + timer.format());
65 System.out.println("------------------------\n");
66 double varRQMC = p.getNumPoints() * statRQMC.variance();
67 double cpuRQMC = timer.getSeconds() / (m * n);
68
69 System.out.printf("Variance ratio: %9.4g%n", varMC / varRQMC);
70 System.out.printf("Efficiency ratio: %9.4g%n", (varMC * cpuMC) / (varRQMC * cpuRQMC));
71 }
72}
This class provides the basic structures for storing and manipulating linear digital nets in base ,...
This class implements a umontreal.ssj.hups.PointSetRandomization that performs a left matrix scrambli...
int getNumPoints()
Returns the number of points.
This class is used for randomized quasi-Monte Carlo (RQMC) simulations.
void randomize()
Randomizes the point set.
int getNumPoints()
Returns the number of points in the associated point set.
PointSetIterator iterator()
Returns a new point set iterator for the point set associated to this object.
This class implements digital nets and digital sequences in base 2 formed by the first points of a S...
Extends RandomStreamBase using a composite linear feedback shift register (LFSR) (or Tausworthe) RNG ...
Definition LFSR113.java:47
A subclass of StatProbe.
Definition Tally.java:47
double average()
Returns the average value of the observations since the last initialization.
Definition Tally.java:155
void setConfidenceIntervalStudent()
Indicates that a confidence interval on the true mean, based on the normality assumption,...
Definition Tally.java:582
double variance()
Returns the sample variance of the observations since the last initialization.
Definition Tally.java:174
void add(double x)
Gives a new observation x to the statistical collector.
Definition Tally.java:109
String report()
Returns a formatted string that contains a report on this probe.
Definition Tally.java:397
String format()
Converts the CPU time used by the program since its last call to init for this AbstractChrono to a St...
void init()
Initializes this AbstractChrono to zero.
double getSeconds()
Returns the CPU time in seconds used by the program since the last call to init for this AbstractChro...
The Chrono class extends the umontreal.ssj.util.AbstractChrono class and computes the CPU time for th...
Definition Chrono.java:37
This is the interface for iterators that permit one to go through the points of a PointSet and the su...
This interface is for a randomization that can be used to randomize a umontreal.ssj....
void resetStartStream()
Reinitializes the stream to its initial state : and are set to .