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
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.
f (black curve), f0 (grey), and
g (blue, not always visible).
fp obtained after a small time step
using the present f and sometimes the past values fm.
time=time+timeStep
and the solution arrays fm=f; f=fp.
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
|
The evolution is then computed with the help of predefined arrays containing
the solution (an object called
solution)
|
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
new:
int i = 3; // Declare i as an integer double[] c; // Declare c[] array 16 digits nbrs c = new double[i]; // Memory for c[0], c[1], c[2] BandMatrix A; // Declare A as a BandMatrix object A = new BandMatrix(3,10); // Memory for 3 bands with 10 doubles
c[0] before the memory has been
attributed with a new statement leads to the infamous
java.lang.NullPointerException error, while the element
c[3] throws java.lang.ArrayIndexOutOfBoundsException:3,
because the array is accessed outside its valid range 0,1,2.=
whereas the comparing equal sign by a double ==
int a = 42;
if (a == 17) System.out.println("a is equal to 17");
if (a != 17) System.out.println("a is not equal to 17");
will print the text "a is not equal to 17" to the
java console.