<?php
if (isset($nh)) 
  echo "<body text='#000000' bgcolor='#FFFFFF'>"; ?>
<?php
 if (!isset($user_dir)) $user_dir='.';
 if (!isset($nh)) {
  if ($opt =='0') {
   exit();
  } else {
   echo "<html>
    <head><meta name=robots content=noindex,nofollow>
    <title>2.03 Resistance and support levels</title>
    </head><body text='#000000' bgcolor='#FFFFFF'>
    <table border=0 bgcolor=#dcdcdc cols=10 cellpadding=5 width=800 cellspacing=0>
     <tr align=bottom><td nowrap>
      <a href=javascript:history.go(-1) onMouseover=\"window.status=' # previous'; return true\"
             ><img src='../IMAGES/nav_previous.png' border=0 align=bottom></a>
      <a href=javascript:history.go(-2) onMouseover=\"window.status=' # 2 previous'; return true\"
             ><img src='../IMAGES/nav_up.png' border=0 align=bottom></a>
     <img src='../IMAGES/nav_next_gr.png' border=0 align=bottom>
      <a href='".$user_dir."/../../SYL/node1.php' onMouseover=\"window.status=' # course'; return true\"
            ><img src='../IMAGES/nav_contents.png' border=0 align=bottom></a>
      &nbsp;&nbsp;<b><font size=+1>2.03 Resistance and support levels</font></b></td><td>&nbsp;</td>
     </tr></table><br clear=both><br>";
     # Creates problems with reload  echo "<table border=0 width=800><td>";
  }
 }; ?>
                 
 
<p>
                                                                             
<font color="#0000FF">
<em>Rather than showing a complete solution, the teacher decided here to give you his 
own applet and guide you through a series of experiments illustrating the effect of
resistance / support levels. To complete this exercise, your task will be to implement 
your own scheme in the applet and discuss what you observe.</em>
<font color="#000000">

<p>
Examine first the evolution of prices in a market <b>without resistance / support levels</b>, 
simply by running the applet with the preset value <em>UserInteger=1</em>.
Each red dot corresponds to a possible evolution starting from the current (spot) price 
S<sub>0</sub> chosen with <em>StrikePrice=9.0</em> and evolves horizontally with a log-normal random 
walk here prescribed with a 6% <em>Drift</em> and a 30% <em>Volatility</em>.
The black line accumulates the final realizations and can be understood as a probability 
density (or distribution function, vertical axis in per cent) of finding the future price 
in a unit interval (horizontal axis).

<ol type="1"><p>
<li> Observe how a simulation with 300 prices is rather noisy. Increase the number of
      <em>Walkers</em> to a value that still allows you to rapidly compute the 9 months 
      evolution chosen with <em>RunTime=0.75</em>.</li>
<p>
<li> Switch from <em>DistribFct*</em> to <em>DistribFct</em> and repeat a calculation without
      displaying the prices. Describe the distribution function you obtain.</li>
<p>
<li> Press <em>Toggle Display</em> twice to re-normalize the plot and click inside the plot 
      area to measure the coordinates. Relying a homogeneous mesh S<sub>n</sub> = nh to integrate 
      the area below the distribution 
      P(S &lt; S<sub>0</sub>) =  <font face="symbol">ò</font
><sub>0</sub><sup>S<sub>0</sub></sup> p(S<sub>0</sub>,0;S,T) dS  <font face="symbol">»</font
>  
      h(<font face="symbol">å</font
><sub>n = 0</sub><sup>N</sup> p(S<sub>n</sub>) <font face="symbol">-</font
>[p(0)+p(N)]/2),
      you can calculate the probability that the price will drop during the time interval 
      [0;T] of the simulation.</li>
</ol>

<p>
Now <a href="../../edu/SRC/faq.php#6">reload</a> the default parameters and simulate the evolution 
of prices in a market <b>with a resistance / support level</b> by setting <em>UserInteger=2</em>.

<ol type="1"><p>
<li> Can you tell how the motion of each individual prices is affected? Discuss where and 
      how the distribution function is altered.</li>
<p>
<li> Use the parameters <em>Barrier</em> and <em>UserDouble</em> to modify the position and the
      intensity of the resistance / support level.</li>
</ol>
Check the <a href="../../edu/SRC/assign.php">assignment 4.11</a> for a continuation of this problem
in the context of option pricing.

<p>
                </font></font><br><p><applet codebase="<?php echo $user_dir ?>/applet/" code=vmarket align=center width=660 height=390>
       <param name=topic               value="Exercise">
       <param name=scheme              value="Exercise 2.03">
       <param name=ic                  value="Gaussian">
       <param name=method              value="DistribFct*">
       <param name=RunTime             value=0.75>
       <param name=Drift               value=0.06>
       <param name=Volatility          value=0.3>
       <param name=Shape0              value=100.>
       <param name=Shape1              value=0.01>
       <param name=MeshLength          value=16.>
       <param name=MeshPoints          value=17>
       <param name=Walkers             value=300>
       <param name=TimeStep            value=0.00397>
       <param name=StrikePrice         value=9.>
       <param name=Barrier             value=10.>
       <param name=UserInteger         value=1>
       <param name=UserDouble          value=0.2>
</applet><br><p><br>
<a href="<?php echo $user_dir ?>/applet/version/help_tag.php">VMarket applet</a>: press <B>START/STOP</B> 
for execution.

        <br><p><hr><b>Numerical scheme in Java:</b><pre>
double timeStep= runData.getParamValue("TimeStep"); // Run parameters
double mu      = runData.getParamValue("Drift");
double sigma   = runData.getParamValue("Volatility");
int    type    = runData.getParamValueInt("UserInteger");

if (type == 1) { // Log-normal walk for stock prices (no modification required)

  for(int k=0; k&lt;numberOfRealisations; k++){
    currentState[k][0] += currentState[k][0] * 
        ( mu*timeStep +
          sigma*random.nextGaussian()*Math.sqrt(timeStep) );
  }

} else if (type == 2) { // Simulate resistance/support levels (please modify)

  double barrier   = runData.getParamValue("Barrier"); // Extra parameters
  double intensity = runData.getParamValue("UserDouble");
  double width     = 0.1*barrier;
  double odds      = 2*intensity-1; 

// Examples of useful functions in Java
// double uniform01  = Math.random();         // random number in U(0,1)
// double gaussian01 = random.nextGaussian(); // random number in N(0,1)
// double e   = Math.exp(1.);
// double one = Math.log(e);
// System.out.println("Debug: type="+type);   // print to browser Java-console

  for(int k=0; k&lt;numberOfRealisations; k++){
    currentState[k][0] += currentState[k][0] * 
        ( mu*timeStep +
          sigma*random.nextGaussian()*Math.sqrt(timeStep) );
  }

} // if (type)
        </pre>
<?php
  echo "<br><p><address>
    <table border=0 bgcolor=#dcdcdc cols=10 cellpadding=5 width=800 cellspacing=0>
     <tr align=bottom><td nowrap>
      <a href=javascript:history.go(-1) onMouseover=\"window.status=' # previous'; return true\"
             ><img src='../IMAGES/nav_previous.png' border=0 align=bottom></a>
      <a href=javascript:history.go(-2) onMouseover=\"window.status=' # 2 previous'; return true\"
             ><img src='../IMAGES/nav_up.png' border=0 align=bottom></a>
    <img src='../IMAGES/nav_next_gr.png' border=0 align=bottom>
      <a href='".$user_dir."/../../SYL/node1.php' onMouseover=\"window.status=' # course'; return true\"
             ><img src='../IMAGES/nav_contents.png' border=0 align=bottom></a></td>
     <td nowrap>Copyright&nbsp;&copy;&nbsp;Doc Andre Jaun &amp; 
      <a href='http://localhost/opt/' onMouseover=\"window.status=' # home'; return true\"
    >Lifelong-Learners/opt</a> at  10:41:00,  May 04th, 2004   </td></tr></table>
    </address></body></html>"; ?>
