import umontreal.iro.lecuyer.rng.*; import umontreal.iro.lecuyer.stochprocess.*; import umontreal.iro.lecuyer.stat.Tally; import umontreal.iro.lecuyer.util.*; public class AsianStoch { double strike; // Strike price. int s; // Number of observation times. double discount; // Discount factor exp(-r * zeta[t]). StochasticProcess proc; // Array zeta[0..s+1] must contain zeta[0]=0.0, plus the s observation times. public AsianStoch (double r, double sigma, double strike, double s0, int s, double[] zeta, RandomStream stream) { this.strike = strike; this.s = s; discount = Math.exp (-r * zeta[s]); proc = new GeometricBrownianMotion (s0, r, sigma, stream); // Possibilité d'initialiser proc d'autres façons: //Par exemple, on peut facilement passer au pont brownien //BrownianMotion bm = new BrownianMotionBridge (0, 0, 1, stream); //proc = new GeometricBrownianMotion (s0, r, sigma, bm); // Les paramètres de bm sont remplacés proc.setObservationTimes (zeta, s); } // Generates the process S. public void generatePath () { proc.generatePath (); } // Computes and returns the discounted option payoff. public double getPayoff () { double[] path = proc.getPath(); double average = 0.0; // Average of the GBM process. for (int j = 1; j <= s; j++) average += path[j]; average /= s; if (average > strike) return discount * (average - strike); else return 0.0; } // Performs n indep. runs using stream and collects statistics in statValue. public void simulateRuns (int n, Tally statValue) { statValue.init(); for (int i=0; i