//
// simu2.h  Stochastic Volatility Option Pricing Model
//

class svprice {
  public:
    svprice(double ttm=0.25,int nper=12,double r=.05,double initstd=.15,
      double meanstd=.2,double k=6.0,double sigstd=.5);
    ^
    |
    Stochastic volatility means that volatility is a random process.  We
    have initstd, the initial standard deviation, meanstd, the long-term
    mean standard deviation, k, the mean reversion parameter for standard
    deviation, and sigstd, the volatility of the standard deviation.

    double eurcall(double stock,double strike,long int nsimu=1000);
    ^
    |
    The data type ``long int'' has more precision (digits) than the data type
    ``int.''  100,000 is larger than the largest int on some machines.

  private:
    int npers;
    double tinc, r1per, stockP, sigma0, sigma, meansigma, sigmasigma, kappa,
      c0, c1, c2, c3, c4, c5;
    ^
    |
    As usual the parameters are stored here.  The ci's are products etc. of
    the other parameters.  If they weren't stored separately, the would have
    to be computed again for every period of every simulation, which would
    slow the program significantly.

    double stocktotret();};

//
// simu2test.cc Stochastic Volatility Option Pricing Test File
//
#include 
#include 
#include "simu2.h"

main() {
  long int i,nsimus;
  svprice sim2;
  for(nsimus=10;nsimus<=100000l;nsimus *= 10)
  ^
  |
  This for loop has us multiplying by 10 each time and the test concerns
  the size of nsimus.  In 100000l, the last digit is the letter ``el'' not
  the number ``one,'' and this means that 100000 is a long int.

    cout << nsimus << " " <<
      floor(sim2.eurcall((double) 100.0,(double) 100.0,nsimus)*100.0+0.5)/100.0
      << endl;
      ^
      |
      The floor, etc. rounds to two decimal places.  Floor itself rounds down
      to the nearest integer.  It is probably better to do this with the
      manipulator setprecision().

  cout << endl;
  for(i=0;i<20;i++)
    cout << "100000 " << 
      floor(sim2.eurcall((double) 100.0,(double) 100.0,(long int) 100000l)*100.0+0.5)/100.0
      << endl;
  return(0);}

//
// simu2.cc  Stochastic Volatility Option Pricing Model
//
#include 
#include 
#include 
#include "simu2.h"
#define unifrand() ((double) rand()/((double) RAND_MAX))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))

svprice::svprice(double ttm,int nper,double r,double initstd, double
    meanstd, double k, double sigstd) {
  npers = nper;
  tinc = ttm/(double) nper;
  r1per = 1.0 + r*tinc;
  sigma0 = initstd;
  meansigma = meanstd;
  sigmasigma = sigstd;
  kappa = k;
  c0 = kappa * tinc * meansigma;
  c1 = 1.0 - kappa * tinc;
  c2 = 1.0 - sigmasigma * sqrt(tinc)*0.5*sqrt((double) 12);
  c3 = sigmasigma * sqrt(tinc) * sqrt((double) 12);
  c4 = sqrt(tinc)*sqrt((double) 12);}
  ^
  |
  There is nothing really new in the constructor.  The constants are
  explained a bit below.

double svprice::eurcall(double stock,double strike,long int nsimu) {
  long int i,n;
  double x;
  x=0.0;
  for(n=0;n