The numerical schemes submitted from the java window are automatically inserted in the VMarket source code (e.g. solution 2.03) and compiled on the server before you can download them for execution locally in your browser. This webpage reviews a limited number of commands for those who are not familiar with the java programming language, but nevertheless who would like to modify the applets. More details concerning the source code can be found in the program tree, the name index and the program listing. For a complete tutorial in java programming, consult the free course from Sun Microsystems.

Algorithm for time evolution.
The VMarket = Virtual MARKET applet is a wrapper to perform a stepwise evolution of functions, i.e. solving time-dependent differential equations using an algorithm of the form

  1. At time=0 use the terminal payoff from a contract (e.g. put option, discount function) to initialize various arrays f0[i],f[i],g[i] with the price corresponding to dicrete values of the underlying share (or spot rate) sampled on a mesh x[i], i=0.. x.length-1.
  2. Plot f (black curve), f0 (grey), and g (blue, not always visible).
  3. Use the java code predefined in the applet or submitted from the java window to calculate the new values fp obtained after a small time step using the present f and sometimes the past values fm.
  4. Shift the time levels by updating the variables time=time+timeStep and the solution arrays fm=f; f=fp.
  5. Goto 2 until finished.
Only the third step can be modified by the user in the java window; for example, a loop
   double scale = runData.getParamValue(rundata.UserDoubleNm);
   for (int i=0; i<=n; i++) {
     fp[i]=scale*f[i];
   }
executes an artificial evolution, where the next value fp is obtained from a simple scaling of the present value f, where the scaling factor corresponds to the TAG parameter UserDouble defined in the applet. When programming, remember that you have to force your browser to reload the applet after each modification to prevent it from using an older version that is often stored in the browser cache.

VMarket variables.
The list of run parameters is a java object called runData is used to defines local variables (double = 16 digits real, int = 9 digits signed integer) using statements of the form
  vanilla call option boolean isCall=ic.equals(vmarket.CALL);
  vanilla put option boolean isPut =ic.equals(vmarket.PUT);
  total run time double rTime=runData.getParamValue(rundata.RunTimeNm);
  drift double drift=runData.getParamValue(rundata.DriftNm);
  volatility double sigma=runData.getParamValue(rundata.VolatilityNm);
  distribution double kappa=runData.getParamValue(rundata.LogNkappaNm);
  interest rate double rate =runData.getParamValue(rundata.SpotRateNm);
  dividend double divid=runData.getParamValue(rundata.DividendNm);
  exercise price double K =runData.getParamValue(rundata.StrikePriceNm);
  relative barrier double bar =runData.getParamValue(rundata.BarrierNm);
  market price of risk double lamb =runData.getParamValue(rundata.MktPriceRskNm);
  mean reversion value double ca =runData.getParamValue(rundata.MeanRevTargNm);
  mean reversion speed double cb =runData.getParamValue(rundata.MeanRevVeloNm);
  initial condition double ic0 =runData.getParamValue(rundata.Shape0Nm);
  lower value x-axis double x0 =runData.getParamValue(rundata.MeshLeftNm);
  length of x-axis double len =runData.getParamValue(rundata.MeshLengthNm);
  number mesh points int n =runData.getParamValueInt(rundata.MeshPointsNm);
  number realizations int N =runData.getParamValueInt(rundata.WalkersNm);
  time step double step =runData.getParamValue(rundata.TimeStepNm)();
  implicit time param double theta=runData.getParamValue(rundata.TimeThetaNm);
  tunable quadrature double tune =runData.getParamValue(rundata.TuneQuadNm);
  user defined integer int myInt=runData.getParamValueInt(rundata.UserIntNm);
  user defined real double myDbl=runData.getParamValue(rundata.UserDoubleNm);

The evolution is then computed with the help of predefined arrays containing the solution (an object called solution)
  time in the simulation double time;
  last index of solution int n = x.length-1;
  mesh points, intervals double[] x,dx;
  solution functions double[] f0,f,g;
  old, present future double[] fm,f,fp;
  derivatives double[] dfm,df,dfp;
  current realization double[] currentState;

Note that in java as well as in C and C++, the index of arrays starts with zero (x[0]) and finishes with an index lower by one element less than its size (x[x.length-1]).

Debugging.
Having corrected all the compiler errors does unfortunately not mean that your scheme immediately behaves the way you want... You may have to temporarily inactivate an error by commenting it out with the /* java comment delimiters */

   /* This mistake divides by zero but has been commented out
   double error = fp[n]/0;
   */
   System.out.println(fp[i]);
or monitor the value of a quantity, here the values of the array fp, by printing it to the java console of your browser. From the values that are printed after a single step, it is often possible to track down the mistakes.

Common errors.
Avoid the most common difficulties when you start programming