SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
TestAsianRQMCSeries.java
1package tutorial;
2
3import java.io.*;
4import java.util.ArrayList;
5import umontreal.ssj.rng.*;
6import umontreal.ssj.hups.*;
7import umontreal.ssj.mcqmctools.*;
8import umontreal.ssj.stat.Tally;
9import umontreal.ssj.stat.PgfDataTable;
10
11public class TestAsianRQMCSeries extends AsianGBM implements MonteCarloModelDouble {
12
13 public TestAsianRQMCSeries(double r, double sigma, double strike, double s0, int s, double[] zeta) {
14 super(r, sigma, strike, s0, s, zeta);
15 }
16
17 @Override
18 public void simulate(RandomStream stream) {
19 generatePath(stream);
20 }
21
22 @Override
23 public double getPerformance() {
24 return getPayoff();
25 }
26
27 public int getDimension() {
28 return d;
29 }
30
31 public String toString() {
32 return "Asian option under GBM, for testing";
33 }
34
35 public String getTag() {
36 return "AsianRQMCSeries";
37 }
38
39 public static void main(String[] args) throws IOException {
40 // public static void main() {
41 int s = 12; // Dimension (number of time steps).
42 int dim = s;
43 double[] zeta = new double[s + 1]; // The observation times.
44 for (int j = 0; j <= s; j++)
45 zeta[j] = (double) j / (double) s;
46 TestAsianRQMCSeries model = new TestAsianRQMCSeries(0.05, 0.5, 100.0, 100.0, s, zeta);
47 Tally statValue = new Tally("value of Asian option");
48 // Tally statRQMC = new Tally("RQMC averages for Asian option");
49
50 // RQMCExperimentDouble exper = new RQMCExperimentDouble();
51 int n = 10000;
52 System.out.println("Ordinary MC:\n");
53 System.out.println(
54 MonteCarloExperiment.simulateRunsDefaultReportStudent(model, n, new MRG32k3a(), statValue, 0.95, s));
55
56 int base = 2; // Basis for the loglog plots.
57 int numSets = 10; // Number of sets in the series.
58 int numSkipReg = 1; // Number of sets skipped for the regression.
59 int i;
60 int m = 50; // Number of RQMC randomizations.
61 int[] N = { 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152 }; // 13
62 int[] a = { 149, 275, 857, 1731, 2431, 6915, 12545, 19463, 50673, 96407, 204843, 443165, 768165 };
63
64 // Create a list of series of RQMC point sets.
65 ArrayList<RQMCPointSet[]> listOfSeries = new ArrayList<RQMCPointSet[]>();
66 PointSet p;
67 PointSetRandomization rand;
68 RandomStream noise = new MRG32k3a();
69
70 // Korobov lattice + baker
71 RQMCPointSet[] theRQMCSetLattice = new RQMCPointSet[numSets];
72 rand = new RandomShift(noise);
73 for (i = 0; i < numSets; ++i) {
74 p = new BakerTransformedPointSet(new KorobovLattice(N[i], a[i], dim));
75 theRQMCSetLattice[i] = new RQMCPointSet(p, rand);
76 }
77 theRQMCSetLattice[0].setLabel("Lattice+baker+shift");
78 listOfSeries.add(theRQMCSetLattice);
79
80 // Sobol + LMS + shift
81 RQMCPointSet[] theRQMCSetSobol = new RQMCPointSet[numSets];
82 int mink = 9; // Smallest power of 2 considered.
83 rand = new LMScrambleShift(noise);
84 for (i = 0; i < numSets; ++i) {
85 p = (new SobolSequence(i + mink, 31, dim));
86 theRQMCSetSobol[i] = new RQMCPointSet(p, rand);
87 }
88 theRQMCSetSobol[0].setLabel("Sobol+LMS+Shift");
89 listOfSeries.add(theRQMCSetSobol);
90
91 RQMCExperimentSeries experSeries = new RQMCExperimentSeries(theRQMCSetLattice, base);
92 experSeries.testVarianceRate(model, m);
93 System.out.println(experSeries.reportVarianceRate(numSkipReg, true));
94 System.out.println((experSeries.toPgfDataTable("Korobov+baker")).drawPgfPlotSingleCurve("Korobov+baker", "axis",
95 3, 4, 2, "", "marks=*"));
96
97 // Perform an experiment with a list of series of RQMC point sets.
98 ArrayList<PgfDataTable> listCurves = new ArrayList<PgfDataTable>();
99 System.out.println(experSeries.testVarianceRateManyPointTypes(model, listOfSeries, m, numSkipReg, true, true,
100 true, listCurves));
101 System.out.println("\n Now printing data table for the two curves ***** \n\n\n");
102 // Prints the data of each curve as a table.
103 for (PgfDataTable curve : listCurves)
104 System.out.println(curve.formatTable());
105 // Produces LaTeX code to draw these curves with pgfplot.
106 String plot = PgfDataTable.drawPgfPlotManyCurves("Korobov and Sobol", "loglogaxis", 0, 2, listCurves, 2, "", " ");
107 System.out.println(plot);
108
109 // Produces a complete LaTeX file with the plots.
110 String pfile = (PgfDataTable.pgfplotFileHeader() + plot + PgfDataTable.pgfplotEndDocument());
111 Writer file = new FileWriter("testPlotAsianRQMC.tex");
112 file.write(pfile);
113 file.close();
114 }
115
116}
double getPerformance()
Recovers and returns the realization of the performance measure, of type double.
String toString()
Returns a description of the model and its parameters.
void simulate(RandomStream stream)
Simulates the model for one run.
String getTag()
Returns a short model name (tag) to be used in reports.
void setLabel(String label)
Gives a label (a short string) to identify this object, e.g., when making plots.
Provides generic tools to perform simple Monte Carlo experiments with a simulation model that impleme...
static String simulateRunsDefaultReportStudent(MonteCarloModelDouble model, int n, RandomStream stream, Tally statValue, double level, int d, Chrono timer)
Performs n independent runs using n substreams of stream, collects statistics in statValue,...
PgfDataTable toPgfDataTable(String tableName, String tableLabel)
Takes the data from the most recent experiment and returns it in a PgfDataTable.
String reportVarianceRate(int numSkip, boolean details)
Produces and returns a report on the last experiment.
void testVarianceRate(MonteCarloModelDouble model, int m)
Performs an RQMC experiment with the given model, with this series of RQMC point sets.
String testVarianceRateManyPointTypes(MonteCarloModelDouble model, ArrayList< RQMCPointSet[]> list, int m, int numSkip, boolean makePgfTable, boolean printReport, boolean details, ArrayList< PgfDataTable > listCurves)
Performs an experiment (testVarianceRate) for each point set series in the given list,...
Extends the abstract class RandomStreamBase by using as a backbone (or main) generator the combined m...
Definition MRG32k3a.java:46
A subclass of StatProbe.
Definition Tally.java:47
An interface for a very simple simulation model for which Monte Carlo (MC) and RQMC experiments are t...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...