3import java.io.IOException;
4import umontreal.ssj.rng.*;
5import umontreal.ssj.probdist.NormalDist;
6import umontreal.ssj.stat.Tally;
7import umontreal.ssj.util.*;
14 double[] sigmaSqrtDelta;
19 public AsianGBM(
double r,
double sigma,
double strike,
double s0,
int d,
double[] zeta) {
22 discount = Math.exp(-r * zeta[d]);
23 double mu = r - 0.5 * sigma * sigma;
24 muDelta =
new double[d];
25 sigmaSqrtDelta =
new double[d];
26 logS =
new double[d + 1];
28 for (
int j = 0; j < d; j++) {
29 delta = zeta[j + 1] - zeta[j];
30 muDelta[j] = mu * delta;
31 sigmaSqrtDelta[j] = sigma * Math.sqrt(delta);
33 logS[0] = Math.log(s0);
38 for (
int j = 0; j < d; j++)
43 public double getPayoff() {
45 for (
int j = 1; j <= d; j++)
46 average += Math.exp(logS[j]);
49 return discount * (average - strike);
57 for (
int i = 0; i < n; i++) {
59 statValue.
add(getPayoff());
64 public static void main(String[] args)
throws IOException {
66 double[] zeta =
new double[d + 1];
68 for (
int j = 1; j <= d; j++)
69 zeta[j] = (
double) j / (double) d;
70 AsianGBM process =
new AsianGBM(0.05, 0.5, 100.0, 100.0, d, zeta);
71 Tally statValue =
new Tally(
"Stats on value of Asian option");
74 process.simulateRuns(n,
new LFSR113(), statValue);
76 System.out.println(statValue.
report(0.95, 3));
77 System.out.println(
"Total CPU time: " + timer.
format() +
"\n");
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a (page 80)).
static double inverseF01(double u)
Same as inverseF(0, 1, u).
Extends RandomStreamBase using a composite linear feedback shift register (LFSR) (or Tausworthe) RNG ...
void setConfidenceIntervalStudent()
Indicates that a confidence interval on the true mean, based on the normality assumption,...
void init()
Initializes the statistical collector.
void add(double x)
Gives a new observation x to the statistical collector.
String report()
Returns a formatted string that contains a report on this probe.
String format()
Converts the CPU time used by the program since its last call to init for this AbstractChrono to a St...
The Chrono class extends the umontreal.ssj.util.AbstractChrono class and computes the CPU time for th...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...
double nextDouble()
Returns a (pseudo)random number from the uniform distribution over the interval , using this stream,...
void resetNextSubstream()
Reinitializes the stream to the beginning of its next substream: