<?xml version="1.0" encoding="iso-8859-1" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" 
"http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd" > 
<?xml-stylesheet type="text/css" href="duration.css"?> 
<html  
xmlns="http://www.w3.org/1999/xhtml"  
><head><title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> 
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> 
<!-- xhtml,mozilla --> 
<meta name="src" content="duration.tex" /> 
<meta name="date" content="2013-04-05 05:38:00" /> 
<link rel="stylesheet" type="text/css" href="duration.css" /> 
</head><body 
>
<!--l. 8--><p class="noindent" >Steven R. Dunbar <br 
class="newline" />Department of Mathematics <br 
class="newline" />203 Avery Hall <br 
class="newline" />University of Nebraska-Lincoln <br 
class="newline" />Lincoln, NE 68588-0130 <br 
class="newline" /><span 
class="cmtt-12">http://www.math.unl.edu </span><br 
class="newline" />Voice: 402-472-3731 <br 
class="newline" />Fax: 402-472-8466                  </p>
<div class="center" 
>
<!--l. 1--><p class="noindent" >
</p><!--l. 6--><p class="noindent" > <span 
class="cmbx-12x-x-144">Stochastic Processes and</span><br />
<span 
class="cmbx-12x-x-144">Advanced Mathematical Finance</span><br />
</p>
</div>
<!--l. 19--><p class="noindent" >__________________________________________________________________________
</p>
<div class="center" 
>
<!--l. 21--><p class="noindent" >
</p><!--l. 21--><p class="noindent" ><span 
class="cmr-17">Duration of the Gambler&#x2019;s Ruin</span></p></div>
<!--l. 23--><p class="indent" >   _______________________________________________________________________
</p><!--l. 1--><p class="indent" >   Note: To best read these pages, you will need the latest version of the Mozilla
Firefox browser, with the STIX fonts installed, The Chrome browser will also
present a mostly readable version. In a few sections, you will also need the
latest Java plug-in, and JavaScript must be enabled. If you use a browser
other than Firefox you should be able to access the pages and run the
applets. However, mathematical expressions will probably not display
correctly. Firefox is currently the only browser that fully supports all of the
standards.
</p><!--l. 27--><p class="indent" >   _______________________________________________________________________________________________
</p><!--l. 29--><p class="indent" >   <img 
src="../../../../CommonInformation/Lessons/rating.png" alt="Rating"  
 />
                                                                          

                                                                          
</p>
   <h3 class="likesectionHead"><a 
 id="x1-1000"></a>Rating</h3>
<!--l. 33--><p class="noindent" >Mathematically Mature: may contain mathematics beyond calculus with
proofs.
</p><!--l. 36--><p class="indent" >   _______________________________________________________________________________________________
</p><!--l. 38--><p class="indent" >   <img 
src="../../../../CommonInformation/Lessons/question_mark.png" alt="Section Starter Question"  
 />
</p>
   <h3 class="likesectionHead"><a 
 id="x1-2000"></a>Section Starter Question</h3>
<!--l. 41--><p class="noindent" >Consider a gambler who wins or loses a dollar on each turn of a fair game with
probabilities <!--l. 42--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi> <mo 
class="MathClass-rel">=</mo> <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>2</mn></mrow></math>
and <!--l. 42--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>q</mi> <mo 
class="MathClass-rel">=</mo> <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>2</mn></mrow></math>
respectively. Let his initial capital be $10. The game continues until the gambler&#x2019;s
capital either is reduced to 0 or has increased to $20. What is the length of the
shortest possible game the gambler could play? What are the chances of this
shortest possible game? What is the length of the second shortest possible game?
How would you find the probability of this second shortest possible game
occurring?
</p><!--l. 50--><p class="indent" >   _______________________________________________________________________________________________
</p><!--l. 52--><p class="indent" >   <img 
src="../../../../CommonInformation/Lessons/keyconcepts.png" alt="Key Concepts"  
 />
</p>
   <h3 class="likesectionHead"><a 
 id="x1-3000"></a>Key Concepts</h3>
<!--l. 55--><p class="noindent" >
      </p><ol  class="enumerate1" >
      <li 
  class="enumerate" id="x1-3002x1">The
      principle of first-step analysis, also known as conditional expectations,
      provides equations for important properties of coin-flipping games and
      random walks. The important properties include ruin probabilities and
      the duration of the game until ruin.
                                                                          

                                                                          
      </li>
      <li 
  class="enumerate" id="x1-3004x2">Difference  equations  derived  from  first-step  analysis  or  conditional
      expectations provide the way to deduce the expected length of the game
      in the gambler&#x2019;s ruin, just as for the probability of ruin or victory.</li></ol>
<!--l. 69--><p class="noindent" >__________________________________________________________________________
</p><!--l. 71--><p class="indent" >   <img 
src="../../../../CommonInformation/Lessons/vocabulary.png" alt="Vocabulary"  
 />
</p>
   <h3 class="likesectionHead"><a 
 id="x1-4000"></a>Vocabulary</h3>
<!--l. 73--><p class="noindent" >
      </p><ol  class="enumerate1" >
      <li 
  class="enumerate" id="x1-4002x1"><span 
class="cmbx-12">Expectation  by  conditioning  </span>is  the  process  of  deriving  an
      expectation by conditioning the outcome over an exhaustive, mutually
      exclusive set of events, each of which leads to a simpler probability
      calculation, then weighting by the probability of each outcome of the
      conditioning events.
      </li>
      <li 
  class="enumerate" id="x1-4004x2"><span 
class="cmbx-12">First  Step  Analysis  </span>is  how  J.  Michael  Steele  refers  to  the
      simple expectation by conditioning that we use to analyze the ruin
      probabilities and expected duration. It is a more specific description
      for coin-tossing games of the more general technique of expectation by
      conditioning.</li></ol>
<!--l. 88--><p class="noindent" >__________________________________________________________________________
</p><!--l. 90--><p class="indent" >   <img 
src="../../../../CommonInformation/Lessons/mathematicalideas.png" alt="Mathematical Ideas"  
 />
</p>
   <h3 class="likesectionHead"><a 
 id="x1-5000"></a>Mathematical Ideas</h3>
                                                                          

                                                                          
<!--l. 93--><p class="noindent" >
</p>
   <h4 class="likesubsectionHead"><a 
 id="x1-6000"></a>Understanding a Stochastic Process</h4>
<!--l. 95--><p class="noindent" >We start with a sequence of Bernoulli random variables,
<!--l. 95--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mn>1</mn></mrow></msub 
><mo 
class="MathClass-punc">,</mo><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mn>2</mn></mrow></msub 
><mo 
class="MathClass-punc">,</mo><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mn>3</mn></mrow></msub 
><mo 
class="MathClass-punc">,</mo><mo 
class="MathClass-op">&#x2026;</mo></mrow></math> where
<!--l. 96--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>i</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></math> with
probability <!--l. 96--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi></mrow></math> and
<!--l. 96--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>i</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mo 
class="MathClass-bin">&#x2212;</mo><mn>1</mn></mrow></math> with probability
<!--l. 97--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>q</mi></mrow></math>. We start with
an initial value <!--l. 97--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></math>
and set <!--l. 98--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mn>0</mn></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></math>
for convenience. We define the sequence of sums
<!--l. 99--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mi 
>n</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo><msubsup><mrow 
><mo 
class="MathClass-op"> &#x2211;</mo>
  <!--nolimits--></mrow><mrow 
><mi 
>i</mi><mo 
class="MathClass-rel">=</mo><mn>0</mn></mrow><mrow 
><mi 
>n</mi></mrow></msubsup 
><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
>
<mi 
>i</mi></mrow></msub 
></mrow></math>. We are interested in
the stochastic process <!--l. 100--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>1</mn></mrow></msub 
><mo 
class="MathClass-punc">,</mo><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>2</mn></mrow></msub 
><mo 
class="MathClass-punc">,</mo><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>3</mn></mrow></msub 
><mo 
class="MathClass-punc">,</mo><mo 
class="MathClass-op">&#x2026;</mo></mrow></math>.
It turns out this is a complicated sequence to understand in full, so we single out
particular simpler features to understand first. For example, we can look at
how many trials the process will experience until it achieves the value
<!--l. 104--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mn>0</mn></mrow></math> or
<!--l. 104--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>a</mi></mrow></math>. In symbols,
consider <!--l. 104--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>N</mi> <mo 
class="MathClass-rel">=</mo><mo class="qopname"> min</mo><mrow ><mo 
class="MathClass-open">{</mo><mrow><mi 
>n</mi> <mo 
class="MathClass-punc">:</mo> <msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mi 
>n</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mn>0</mn><mo 
class="MathClass-punc">,</mo><!--mstyle 
class="text"--><mtext  >&#x00A0;&#x00A0;or&#x00A0;</mtext><!--/mstyle--><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mi 
>n</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>a</mi></mrow><mo 
class="MathClass-close">}</mo></mrow></mrow></math>
It is possible to consider the probability distribution of this
newly defined random variable. Even this turns out to be fairly
complicated, so we look at the expected value of the number of trials,
<!--l. 108--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>D</mi> <mo 
class="MathClass-rel">=</mo> <mi 
>E</mi> <mfenced separators="" 
open="["  close="]" ><mrow><mi 
>N</mi></mrow></mfenced></mrow></math>. This
is a special case of a larger class of probability problems called <span 
class="cmti-12">first-passage</span>
<span 
class="cmti-12">distributions </span>for <span 
class="cmti-12">first-passage times</span>.
</p><!--l. 112--><p class="noindent" >
</p>
   <h4 class="likesubsectionHead"><a 
 id="x1-7000"></a>Expected length of the game</h4>
<!--l. 114--><p class="noindent" >Note that in the following we implicitly assume that the expected duration of the
game is finite. This fact is true, see below for a proof.
</p>
   <div class="newtheorem">
<!--l. 118--><p class="noindent" ><span class="head">
<a 
 id="x1-7001r1"></a>
                                                                          

                                                                          
<span 
class="cmbx-12">Theorem 1.</span>  </span><span 
class="cmti-12">The expected duration of the game in the classical ruin problem</span>
<span 
class="cmti-12">is</span>
</p>
   <div class="math-display"><!--l. 120--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                     <msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo>   <mfrac><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow> 
<mrow 
><mi 
>q</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>p</mi></mrow></mfrac> <mo 
class="MathClass-bin">&#x2212;</mo>  <mfrac><mrow 
><mi 
>a</mi></mrow> 
<mrow 
><mi 
>q</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>p</mi></mrow></mfrac> <mfrac><mrow 
><mn>1</mn> <mo 
class="MathClass-bin">&#x2212;</mo> <msup><mrow 
><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi><mo 
class="MathClass-bin">&#x2215;</mo><mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msup 
></mrow> 
 <mrow 
><mn>1</mn> <mo 
class="MathClass-bin">&#x2212;</mo> <msup><mrow 
><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi><mo 
class="MathClass-bin">&#x2215;</mo><mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow><mrow 
><mi 
>a</mi></mrow></msup 
></mrow></mfrac> <mspace width="1em" class="quad"/><!--mstyle 
class="text"--><mtext  >&#x00A0;&#x00A0;&#x00A0;for&#x00A0;</mtext><!--/mstyle--><mspace width="1em" class="quad"/><mi 
>p</mi><mo 
class="MathClass-rel">&#x2260;</mo><mi 
>q</mi>
</mrow></math></div>
<!--l. 123--><p class="nopar" > <span 
class="cmti-12">and</span>
</p>
   <div class="math-display"><!--l. 124--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                             <msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>a</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow><mo 
class="MathClass-close">)</mo></mrow><mspace width="1em" class="quad"/><!--mstyle 
class="text"--><mtext  >&#x00A0;&#x00A0;for&#x00A0;</mtext><!--/mstyle--><mspace width="1em" class="quad"/><mi 
>p</mi> <mo 
class="MathClass-rel">=</mo> <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>2</mn> <mo 
class="MathClass-rel">=</mo> <mi 
>q</mi><mo 
class="MathClass-punc">.</mo>
</mrow></math></div>
<!--l. 126--><p class="nopar" >
</p>
   </div>
<!--l. 129--><p class="indent" >
</p>
   <div class="proof">
<!--l. 130--><p class="indent" >   <span class="head">
                                                                          

                                                                          
<span 
class="cmti-12">Proof.</span> </span>If the first trial results in success, the game continues as if the initial
position had been <!--l. 131--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mn>1</mn></mrow></math>.
The conditional expectation of the duration conditioned on success at the first
trial is therefore <!--l. 133--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mn>1</mn></mrow></math>.
Likewise if the first trial results in a loss, the duration conditioned on the loss
at the first trial is <!--l. 135--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2212;</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mn>1</mn></mrow></math>.
</p><!--l. 137--><p class="indent" >   This argument shows that the expected duration satisfies the difference
equation, obtained by expectation by conditioning
</p>
   <div class="math-display"><!--l. 139--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                               <msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>p</mi><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mi 
>q</mi><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2212;</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mn>1</mn>
</mrow></math></div>
<!--l. 141--><p class="nopar" > with the boundary conditions
</p>
   <div class="math-display"><!--l. 142--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                                       <msub><mrow 
><mi 
>D</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mn>0</mn><mo 
class="MathClass-punc">,</mo><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><mi 
>a</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mn>0</mn><mo 
class="MathClass-punc">.</mo>
</mrow></math></div>
<!--l. 144--><p class="nopar" >
</p><!--l. 146--><p class="indent" >   The   appearance   of   the   term   1   makes   the   difference   equation
non-homogeneous. Taking a cue from linear algebra, or more specifically the
                                                                          

                                                                          
theory of linear non-homogeneous differential equations, we need to find the
general solution to the homogeneous equation
</p>
   <div class="math-display"><!--l. 152--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                                <msubsup><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow><mrow 
><mi 
>h</mi></mrow></msubsup 
> <mo 
class="MathClass-rel">=</mo> <mi 
>p</mi><msubsup><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
>
<mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow><mrow 
><mi 
>h</mi></mrow></msubsup 
> <mo 
class="MathClass-bin">+</mo> <mi 
>q</mi><msubsup><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
>
<mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2212;</mo><mn>1</mn></mrow><mrow 
><mi 
>h</mi></mrow></msubsup 
>
</mrow></math></div>
<!--l. 154--><p class="nopar" > and a particular solution to the non-homogeneous equation. We already know
the general solution to the homogeneous equation is <!--l. 155--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msubsup><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow><mrow 
><mi 
>h</mi></mrow></msubsup 
> <mo 
class="MathClass-rel">=</mo> <mi 
>A</mi> <mo 
class="MathClass-bin">+</mo> <mi 
>B</mi><msup><mrow 
><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi><mo 
class="MathClass-bin">&#x2215;</mo><mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msup 
></mrow></math>.
The best way to find the particular solution is inspired guessing, based on
good  experience.  We  can  re-write  the  non-homogeneous  equation  for  the
particular solution as
</p>
   <div class="math-display"><!--l. 160--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                             <mo 
class="MathClass-bin">&#x2212;</mo><mn>1</mn> <mo 
class="MathClass-rel">=</mo> <mi 
>p</mi><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-bin">&#x2212;</mo> <msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mi 
>q</mi><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2212;</mo><mn>1</mn></mrow></msub 
><mo 
class="MathClass-punc">.</mo>
</mrow></math></div>
<!--l. 162--><p class="nopar" > The right side is a weighted second difference, a difference equation analog
of the second derivative. Functions whose second derivative is a constant are
quadratic functions. Therefore, it make sense to try a function of the form
<!--l. 165--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msubsup><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow><mrow 
><mi 
>p</mi></mrow></msubsup 
> <mo 
class="MathClass-rel">=</mo> <mi 
>k</mi> <mo 
class="MathClass-bin">+</mo> <mi 
>l</mi><msub><mrow 
><mi 
>T</mi></mrow><mrow 
>
<mn>0</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mi 
>m</mi><msubsup><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow><mrow 
><mn>2</mn></mrow></msubsup 
></mrow></math>.
In the exercises, we show that the particular solution is actually <!--l. 167--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2215;</mo><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow></math>
if <!--l. 167--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi><mo 
class="MathClass-rel">&#x2260;</mo><mi 
>q</mi></mrow></math>.
                                                                          

                                                                          
</p><!--l. 169--><p class="indent" >   It follows that the general solution of the duration equation is:
</p>
   <div class="math-display"><!--l. 170--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                           <msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2215;</mo><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow> <mo 
class="MathClass-bin">+</mo> <mi 
>A</mi> <mo 
class="MathClass-bin">+</mo> <mi 
>B</mi><msup><mrow 
><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi><mo 
class="MathClass-bin">&#x2215;</mo><mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
>
    </mrow></msup 
><mo 
class="MathClass-punc">.</mo>
</mrow></math></div>
<!--l. 172--><p class="nopar" > The boundary conditions require that <!--l. 172--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>A</mi> <mo 
class="MathClass-bin">+</mo> <mi 
>B</mi> <mo 
class="MathClass-rel">=</mo> <mn>0</mn></mrow></math>,
and <!--l. 172--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>A</mi> <mo 
class="MathClass-bin">+</mo> <mi 
>B</mi><msup><mrow 
><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi><mo 
class="MathClass-bin">&#x2215;</mo><mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow><mrow 
><mi 
>a</mi></mrow></msup 
> <mo 
class="MathClass-bin">+</mo> <mi 
>a</mi><mo 
class="MathClass-bin">&#x2215;</mo><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow> <mo 
class="MathClass-rel">=</mo> <mn>0</mn></mrow></math>.
Solving for <!--l. 173--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>A</mi></mrow></math>
and <!--l. 173--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>B</mi></mrow></math>,
we find
</p>
   <div class="math-display"><!--l. 174--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                            <msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo>   <mfrac><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow> 
<mrow 
><mi 
>q</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>p</mi></mrow></mfrac> <mo 
class="MathClass-bin">&#x2212;</mo>  <mfrac><mrow 
><mi 
>a</mi></mrow> 
<mrow 
><mi 
>q</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>p</mi></mrow></mfrac> <mfrac><mrow 
><mn>1</mn> <mo 
class="MathClass-bin">&#x2212;</mo> <msup><mrow 
><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi><mo 
class="MathClass-bin">&#x2215;</mo><mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msup 
></mrow> 
 <mrow 
><mn>1</mn> <mo 
class="MathClass-bin">&#x2212;</mo> <msup><mrow 
><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi><mo 
class="MathClass-bin">&#x2215;</mo><mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow><mrow 
><mi 
>a</mi></mrow></msup 
></mrow></mfrac> <mo 
class="MathClass-punc">.</mo>
</mrow></math></div>
<!--l. 177--><p class="nopar" >
</p><!--l. 179--><p class="indent" >   The calculations are not valid if <!--l. 179--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi> <mo 
class="MathClass-rel">=</mo> <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>2</mn> <mo 
class="MathClass-rel">=</mo> <mi 
>q</mi></mrow></math>.
In this case, the particular solution <!--l. 180--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2215;</mo><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow></math>
no longer makes sense for the equation
</p>
                                                                          

                                                                          
   <div class="math-display"><!--l. 182--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                          <msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mrow ><mo 
class="MathClass-open">(</mo><mrow><mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>2</mn></mrow><mo 
class="MathClass-close">)</mo></mrow><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mrow ><mo 
class="MathClass-open">(</mo><mrow><mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>2</mn></mrow><mo 
class="MathClass-close">)</mo></mrow><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2212;</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mn>1</mn>
</mrow></math></div>
<!--l. 184--><p class="nopar" > The reasoning about the particular solution remains the same however, and
we can show that the particular solution is <!--l. 185--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mo 
class="MathClass-bin">&#x2212;</mo><msup><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow><mrow 
><mn>2</mn></mrow></msup 
></mrow></math>.
It follows that the general solution is of the form <!--l. 186--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mo 
class="MathClass-bin">&#x2212;</mo><msup><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow><mrow 
><mn>2</mn></mrow></msup 
> <mo 
class="MathClass-bin">+</mo> <mi 
>A</mi> <mo 
class="MathClass-bin">+</mo> <mi 
>B</mi><msub><mrow 
><mi 
>T</mi></mrow><mrow 
>
<mn>0</mn></mrow></msub 
></mrow></math>.
The required solution satisfying the boundary conditions is
</p>
   <div class="math-display"><!--l. 189--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                                     <msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>a</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow><mo 
class="MathClass-close">)</mo></mrow><mo 
class="MathClass-punc">.</mo>
</mrow></math></div>
<!--l. 191--><p class="nopar" >
                                                                         &#x25A1;
</p>
   </div>
   <div class="newtheorem">
<!--l. 195--><p class="noindent" ><span class="head">
<a 
 id="x1-7002r1"></a>
<span 
class="cmbx-12">Corollary 1.</span>  </span><span 
class="cmti-12">Playing until ruin with no upper goal for victory against an</span>
                                                                          

                                                                          
<span 
class="cmti-12">infinitely rich adversary, the expected duration of the game until ruin is</span>
</p>
   <div class="math-display"><!--l. 199--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                                   <msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2215;</mo><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow><mspace width="1em" class="quad"/><!--mstyle 
class="text"--><mtext  >&#x00A0;&#x00A0;for&#x00A0;</mtext><!--/mstyle--><mspace width="1em" class="quad"/><mi 
>p</mi><mo 
class="MathClass-rel">&#x2260;</mo><mi 
>q</mi>
</mrow></math></div>
<!--l. 201--><p class="nopar" > <span 
class="cmti-12">and</span>
</p>
   <div class="math-display"><!--l. 202--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                                  <mi 
>&#x221E;</mi><mspace width="1em" class="quad"/><!--mstyle 
class="text"--><mtext  >&#x00A0;for&#x00A0;</mtext><!--/mstyle--><mspace width="1em" class="quad"/><mi 
>p</mi> <mo 
class="MathClass-rel">=</mo> <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>2</mn> <mo 
class="MathClass-rel">=</mo> <mi 
>q</mi><mo 
class="MathClass-punc">.</mo>
</mrow></math></div>
<!--l. 204--><p class="nopar" >
</p>
   </div>
<!--l. 207--><p class="indent" >
</p>
   <div class="proof">
<!--l. 208--><p class="indent" >   <span class="head">
<span 
class="cmti-12">Proof.</span> </span>Pass                        to                        the                        limit
                                                                          

                                                                          
<!--l. 208--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>a</mi> <mo 
class="MathClass-rel">&#x2192;</mo><mi 
>&#x221E;</mi></mrow></math>
in the preceding formulas.                                                                &#x25A1;
</p>
   </div>
<!--l. 211--><p class="noindent" >
</p>
   <h4 class="likesubsectionHead"><a 
 id="x1-8000"></a>Illustration 1</h4>
<!--l. 213--><p class="noindent" >The duration can be considerably longer than we expect naively. For instance in a
fair game, with two players with $500 each flipping a coin until one is
ruined, the average duration of the game is 250,000 trials. If a gambler
has only $1 and his adversary $1000, with a fair coin toss, the average
duration of the game is 999 trials, although some games will be quite
short! Very long games can occur with sufficient probability to give a long
average.
</p><!--l. 221--><p class="noindent" >
</p>
   <h4 class="likesubsectionHead"><a 
 id="x1-9000"></a>Some Calculations for Illustration</h4>
   <div class="tabular"> <table id="TBL-1" class="tabular" 
cellspacing="0" cellpadding="0" rules="groups" 
><colgroup id="TBL-1-1g"><col 
id="TBL-1-1" /></colgroup><colgroup id="TBL-1-2g"><col 
id="TBL-1-2" /></colgroup><colgroup id="TBL-1-3g"><col 
id="TBL-1-3" /></colgroup><colgroup id="TBL-1-4g"><col 
id="TBL-1-4" /></colgroup><colgroup id="TBL-1-5g"><col 
id="TBL-1-5" /></colgroup><colgroup id="TBL-1-6g"><col 
id="TBL-1-6" /></colgroup><colgroup id="TBL-1-7g"><col 
id="TBL-1-7" /></colgroup><colgroup id="TBL-1-8g"><col 
id="TBL-1-8" /></colgroup><tr 
class="hline"><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td></tr><tr  
 style="vertical-align:baseline;" id="TBL-1-1-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-1-1"  
class="td11"><!--l. 225--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi></mrow></math></td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-1-2"  
class="td11"><!--l. 225--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>q</mi></mrow></math></td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-1-3"  
class="td11"><!--l. 225--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></math></td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-1-4"  
class="td11"><!--l. 225--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>a</mi></mrow></math></td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-1-5"  
class="td11">Probability</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-1-6"  
class="td11"> Expected</td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-1-2-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-2-1"  
class="td11">                                                                </td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-2-2"  
class="td11">                                                               </td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-2-3"  
class="td11">                                                               </td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-2-4"  
class="td11">                                                               </td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-2-5"  
class="td11">   of Ruin</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-2-6"  
class="td11"> Duration</td></tr><tr 
class="hline"><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td></tr><tr  
 style="vertical-align:baseline;" id="TBL-1-3-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-3-1"  
class="td11"> 0.5</td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-3-2"  
class="td11"> 0.5</td> <td  style="text-align:left; white-space:nowrap;" id="TBL-1-3-3"  
class="td11">9 </td> <td  style="text-align:left; white-space:nowrap;" id="TBL-1-3-4"  
class="td11">10 </td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-3-5"  
class="td11"> 0.1000</td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-3-6"  
class="td11"> 9</td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-1-4-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-4-1"  
class="td11">                                                             0.5</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-4-2"  
class="td11">                                                             0.5</td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-4-3"  
class="td11">90                                                                                                 </td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-4-4"  
class="td11">100                                                                                               </td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-4-5"  
class="td11">    0.1000</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-4-6"  
class="td11">      900</td></tr><tr  
 style="vertical-align:baseline;" id="TBL-1-5-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-5-1"  
class="td11"> 0.5</td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-5-2"  
class="td11"> 0.5</td> <td  style="text-align:left; white-space:nowrap;" id="TBL-1-5-3"  
class="td11">900 </td> <td  style="text-align:left; white-space:nowrap;" id="TBL-1-5-4"  
class="td11">1,000 </td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-5-5"  
class="td11"> 0.1000</td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-5-6"  
class="td11"> 90,000</td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-1-6-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-6-1"  
class="td11">                                                             0.5</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-6-2"  
class="td11">                                                             0.5</td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-6-3"  
class="td11">950                                                                                               </td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-6-4"  
class="td11">1,000                                                                                             </td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-6-5"  
class="td11">    0.0500</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-6-6"  
class="td11">   47,500</td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-1-7-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-7-1"  
class="td11">                                                             0.5</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-7-2"  
class="td11">                                                             0.5</td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-7-3"  
class="td11">8,000                                                                                             </td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-7-4"  
class="td11">10,000                                                                                           </td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-7-5"  
class="td11">    0.2000</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-7-6"  
class="td11">16,000,000</td>
</tr><tr 
class="hline"><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td></tr><tr  
 style="vertical-align:baseline;" id="TBL-1-8-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-8-1"  
class="td11">                                                            0.45</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-8-2"  
class="td11">                                                            0.55</td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-8-3"  
class="td11">9                                                                                                  </td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-8-4"  
class="td11">10                                                                                                 </td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-8-5"  
class="td11">    0.2101</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-8-6"  
class="td11">       11</td></tr><tr  
 style="vertical-align:baseline;" id="TBL-1-9-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-9-1"  
class="td11"> 0.45</td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-9-2"  
class="td11"> 0.55</td> <td  style="text-align:left; white-space:nowrap;" id="TBL-1-9-3"  
class="td11">90 </td> <td  style="text-align:left; white-space:nowrap;" id="TBL-1-9-4"  
class="td11">100 </td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-9-5"  
class="td11"> 0.8656</td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-9-6"  
class="td11"> 766</td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-1-10-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-10-1"  
class="td11">                                                            0.45</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-10-2"  
class="td11">                                                            0.55</td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-10-3"  
class="td11">99                                                                                                 </td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-10-4"  
class="td11">100                                                                                               </td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-10-5"  
class="td11">    0.1818</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-10-6"  
class="td11">      172</td></tr><tr  
 style="vertical-align:baseline;" id="TBL-1-11-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-11-1"  
class="td11"> 0.4</td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-11-2"  
class="td11"> 0.6</td> <td  style="text-align:left; white-space:nowrap;" id="TBL-1-11-3"  
class="td11">90 </td> <td  style="text-align:left; white-space:nowrap;" id="TBL-1-11-4"  
class="td11">100 </td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-11-5"  
class="td11"> 0.9827</td> <td  style="text-align:right; white-space:nowrap;" id="TBL-1-11-6"  
class="td11"> 441</td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-1-12-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-12-1"  
class="td11">                                                             0.4</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-12-2"  
class="td11">                                                             0.6</td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-12-3"  
class="td11">99                                                                                                 </td><td  style="text-align:left; white-space:nowrap;" id="TBL-1-12-4"  
class="td11">100                                                                                               </td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-12-5"  
class="td11">    0.3333</td><td  style="text-align:right; white-space:nowrap;" id="TBL-1-12-6"  
class="td11">      162</td></tr><tr 
class="hline"><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td><td><hr /></td></tr><tr  
 style="vertical-align:baseline;" id="TBL-1-13-"><td  style="text-align:right; white-space:nowrap;" id="TBL-1-13-1"  
class="td11"> </td> </tr></table>
</div>
<!--l. 243--><p class="noindent" >
</p>
   <h4 class="likesubsectionHead"><a 
 id="x1-10000"></a>Proof that the duration is finite</h4>
                                                                          

                                                                          
<!--l. 245--><p class="noindent" >The following discussion of finiteness of the duration of the game is adapted from
<span class="cite">[<a 
href="#Xsteele01">2</a>]</span> by J. Michael Steele.
</p><!--l. 249--><p class="indent" >   When we check the arguments for the probability of ruin or the duration
of the game, we find a logical gap. We have assumed that the duration
<!--l. 250--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
></mrow></math> of the
game is finite. How do we know for sure that the gambler&#x2019;s net winnings will eventually
reach <!--l. 252--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>a</mi></mrow></math>
or <!--l. 252--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mn>0</mn></mrow></math>?
This important fact requires proof.
</p><!--l. 255--><p class="indent" >   The proof uses a common argument in probability, an &#x201C;extreme case argument&#x201D;.
We identify an &#x201C;extreme&#x201D; event with a small but positive probability of occurring.
We are interested in the complementary &#x201C;good&#x201D; event which at least avoids the
extreme event. Therefore the complementary event must happen with probability not
quite <!--l. 259--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mn>1</mn></mrow></math>.
The avoidance must happen infinitely many independent times, but the
probability of such a run of &#x201C;good&#x201D; events must go to zero.
</p><!--l. 263--><p class="indent" >   For the gambler&#x2019;s ruin, we are interested in the event of the game
continuing forever. Consider the extreme event that the gambler wins
<!--l. 264--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>a</mi></mrow></math> times
in a row. If the gambler is not already ruined (at 0), then such a streak of
<!--l. 266--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>a</mi></mrow></math>
wins in a row is guaranteed to boost his fortune above
<!--l. 267--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>a</mi></mrow></math>
and end the game in victory for the gambler. Such a run of luck
is unlikely, but it has positive probability, in fact, probability
<!--l. 269--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>P</mi> <mo 
class="MathClass-rel">=</mo> <msup><mrow 
><mi 
>p</mi></mrow><mrow 
><mi 
>a</mi></mrow></msup 
></mrow></math>. We
let <!--l. 269--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>E</mi></mrow><mrow 
><mi 
>k</mi></mrow></msub 
></mrow></math>
denote the event that the gambler wins on each turn in the time interval
<!--l. 270--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mrow ><mo 
class="MathClass-open">[</mo><mrow><mi 
>k</mi><mi 
>a</mi><mo 
class="MathClass-punc">,</mo> <mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>k</mi> <mo 
class="MathClass-bin">+</mo> <mn>1</mn></mrow><mo 
class="MathClass-close">)</mo></mrow><mi 
>a</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mn>1</mn></mrow><mo 
class="MathClass-close">]</mo></mrow></mrow></math>, so
the <!--l. 271--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>E</mi></mrow><mrow 
><mi 
>k</mi></mrow></msub 
></mrow></math>
are independent events. Hence the complementary events
<!--l. 272--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msubsup><mrow 
><mi 
>E</mi></mrow><mrow 
><mi 
>k</mi></mrow><mrow 
><mi 
>C</mi></mrow></msubsup 
> <mo 
class="MathClass-rel">=</mo> <mi 
>&#x03A9;</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <msub><mrow 
><mi 
>E</mi></mrow><mrow 
>
<mi 
>k</mi></mrow></msub 
></mrow></math> are also independent.
Then <!--l. 272--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>D</mi> <mo 
class="MathClass-rel">&#x003E;</mo> <mi 
>n</mi><mi 
>a</mi></mrow></math> at least implies
that all of the <!--l. 273--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>E</mi></mrow><mrow 
><mi 
>k</mi></mrow></msub 
></mrow></math>
with <!--l. 273--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mn>0</mn> <mo 
class="MathClass-rel">&#x2264;</mo> <mi 
>k</mi> <mo 
class="MathClass-rel">&#x2264;</mo> <mi 
>n</mi></mrow></math>
fail to occur. Thus, we find
</p>
                                                                          

                                                                          
   <div class="math-display"><!--l. 275--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                       <mi 
>&#x2119;</mi> <mfenced separators="" 
open="["  close="]" ><mrow><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">&#x003E;</mo> <mi 
>n</mi><mi 
>a</mi></mrow></mfenced> <mo 
class="MathClass-rel">&#x2264;</mo> <mi 
>&#x2119;</mi> <mfenced separators="" 
open="["  close="]" ><mrow><munderover accentunder="false" accent="false"><mrow  
><mo mathsize="big" 
>&#x22C2;</mo>
  </mrow><mrow 
><mi 
>k</mi><mo 
class="MathClass-rel">=</mo><mn>0</mn></mrow><mrow 
><mi 
>n</mi></mrow></munderover 
><msubsup><mrow 
><mi 
>E</mi></mrow><mrow 
>
<mi 
>k</mi></mrow><mrow 
><mi 
>C</mi></mrow></msubsup 
></mrow></mfenced> <mo 
class="MathClass-rel">=</mo> <msup><mrow 
><mrow ><mo 
class="MathClass-open">(</mo><mrow><mn>1</mn> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>P</mi></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow><mrow 
><mi 
>n</mi></mrow></msup 
><mo 
class="MathClass-punc">.</mo>
</mrow></math></div>
<!--l. 277--><p class="nopar" > Note that
</p>
   <div class="math-display"><!--l. 278--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                        <mi 
>&#x2119;</mi> <mfenced separators="" 
open="["  close="]" ><mrow><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>&#x221E;</mi><mo 
class="MathClass-rel">|</mo><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>z</mi></mrow></mfenced> <mo 
class="MathClass-rel">&#x2264;</mo> <mi 
>&#x2119;</mi> <mfenced separators="" 
open="["  close="]" ><mrow><mi 
>D</mi> <mo 
class="MathClass-rel">&#x003E;</mo> <mi 
>n</mi><mi 
>a</mi><mo 
class="MathClass-rel">|</mo><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>z</mi></mrow></mfenced>
</mrow></math></div>
<!--l. 280--><p class="nopar" > for all <!--l. 280--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>n</mi></mrow></math>.
Hence, <!--l. 280--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>&#x2119;</mi> <mfenced separators="" 
open="["  close="]" ><mrow><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>&#x221E;</mi></mrow></mfenced> <mo 
class="MathClass-rel">=</mo> <mn>0</mn></mrow></math>,
justifying our earlier assumption.
</p><!--l. 283--><p class="noindent" >
</p>
   <h4 class="likesubsectionHead"><a 
 id="x1-11000"></a>Sources</h4>
<!--l. 285--><p class="noindent" >This section is adapted from <span class="cite">[<a 
href="#Xsteele01">2</a>]</span> with additional background information from
<span class="cite">[<a 
href="#Xfeller73">1</a>]</span>.
</p><!--l. 289--><p class="indent" >   <img 
src="../../../../CommonInformation/Lessons/computer.png" alt="Algorithms, Scripts, Simulations"  
 />
                                                                          

                                                                          
</p>
   <h3 class="likesectionHead"><a 
 id="x1-12000"></a>Algorithms, Scripts, Simulations</h3>
<!--l. 292--><p class="noindent" >
</p>
   <h4 class="likesubsectionHead"><a 
 id="x1-13000"></a>Algorithm</h4>
<!--l. 294--><p class="noindent" >The goal is to simulate the duration until ruin or victory
as a function of starting value. First set the probability
<!--l. 296--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi></mrow></math>, number of Bernoulli
trials <!--l. 297--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>n</mi></mrow></math>, and number of
experiments <!--l. 297--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>k</mi></mrow></math>. Set the
ruin and victory values <!--l. 298--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>r</mi></mrow></math>
and <!--l. 298--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>v</mi></mrow></math>, also
interpreted as the boundaries for the random walk. For each starting value from ruin to
victory, fill an <!--l. 300--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>n</mi> <mo 
class="MathClass-bin">&#x00D7;</mo> <mi 
>k</mi></mrow></math>
matrix with the Bernoulli random variables. For languages with multi-dimensional
arrays each the data is kept in a three-dimensional array of size
<!--l. 303--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>n</mi> <mo 
class="MathClass-bin">&#x00D7;</mo> <mi 
>k</mi> <mo 
class="MathClass-bin">&#x00D7;</mo> <mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>v</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>r</mi> <mo 
class="MathClass-bin">+</mo> <mn>1</mn></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow></math>.
Cumulatively sum the Bernoulli random variables to create the fortune or
random walk. For each starting value, for each random walk or fortune path,
find the duration until ruin or victory is encountered. For each starting
value, find the mean of the duration until ruin or victory. Finally, find a
least squares polynomial fit for the duration as a function of the starting
value.
</p><!--l. 1--><p class="noindent" >
</p>
   <h4 class="likesubsectionHead"><a 
 id="x1-14000"></a>Scripts</h4>
<!--l. 2--><p class="noindent" >
      </p><dl class="description"><dt class="description">
<span 
class="cmbx-12">Geogebra</span> </dt><dd 
class="description">
      </dd><dt class="description">
<span 
class="cmbx-12">R</span> </dt><dd 
class="description">
                                                                          

                                                                          
      <!--l. 9--><p class="noindent" ><a 
href="http://www.math.unl.edu/~sdunbar1/MathematicalFinance/Lessons/FirstStepAnalysis/Duration/duration.R" >R script for duration.</a>.
</p>
      <!--l. 11-->
      <div class="lstlisting"><span class="label"><a 
 id="x1-14001r1"></a></span>p&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 12--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;0.5&#x00A0;<br /><span class="label"><a 
 id="x1-14002r2"></a></span>n&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 13--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;300&#x00A0;<br /><span class="label"><a 
 id="x1-14003r3"></a></span>k&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 14--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;200&#x00A0;<br /><span class="label"><a 
 id="x1-14004r4"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14005r5"></a></span>victory&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 16--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;10&#x00A0;<br /><span class="label"><a 
 id="x1-14006r6"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">top</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">boundary</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">for</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">random</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">walk</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14007r7"></a></span>ruin&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 18--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;0&#x00A0;<br /><span class="label"><a 
 id="x1-14008r8"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">bottom</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">boundary</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">for</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">random</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">walk</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14009r9"></a></span>interval&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 20--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;victory&#x00A0;<!--l. 20--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;ruin&#x00A0;+&#x00A0;1&#x00A0;<br /><span class="label"><a 
 id="x1-14010r10"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14011r11"></a></span>winLose&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 22--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;2&#x00A0;<span class="lstinline"></span><span 
class="cmbsy-10x-x-120">&#x2217;</span>&#x00A0;(<span 
class="cmbx-12">array</span>(&#x00A0;0+(<span 
class="cmbx-12">runif</span>(n<span class="lstinline"></span><span 
class="cmbsy-10x-x-120">&#x2217;</span>k<span class="lstinline"></span><span 
class="cmbsy-10x-x-120">&#x2217;</span>interval)&#x00A0;<span 
class="cmmi-12">&#x003C;</span>=&#x00A0;p),&#x00A0;<span 
class="cmbx-12">dim</span>=<span 
class="cmbx-12">c</span>(n,k,&#x00A0;<br /><span class="label"><a 
 id="x1-14012r12"></a></span>interval)))&#x00A0;<!--l. 23--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;1&#x00A0;<br /><span class="label"><a 
 id="x1-14013r13"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">0+</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">coerces</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">Boolean</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">to</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">numeric</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14014r14"></a></span>totals&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 25--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;<span 
class="cmbx-12">apply</span>(&#x00A0;winLose,&#x00A0;2:3,&#x00A0;<span 
class="cmbx-12">cumsum</span>)&#x00A0;<br /><span class="label"><a 
 id="x1-14015r15"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">second</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">argument</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x2018;&#x2018;2:3&#x2019;&#x2019;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">means</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">column</span><!--l. 26--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmti-12">wise</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">in</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">each</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">panel</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14016r16"></a></span><span 
class="cmbx-12">start</span>&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 27--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;<span 
class="cmbx-12">outer</span>(&#x00A0;<span 
class="cmbx-12">array</span>(1,&#x00A0;<span 
class="cmbx-12">dim</span>=<span 
class="cmbx-12">c</span>(n+1,k)),&#x00A0;ruin:victory,&#x00A0;&#x201D;<span class="lstinline"></span><span 
class="cmbsy-10x-x-120">&#x2217;</span>&#x201D;)&#x00A0;<br /><span class="label"><a 
 id="x1-14017r17"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14018r18"></a></span>paths&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 29--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;<span 
class="cmbx-12">array</span>(&#x00A0;0&#x00A0;,&#x00A0;<span 
class="cmbx-12">dim</span>=<span 
class="cmbx-12">c</span>(n+1,&#x00A0;k,&#x00A0;interval)&#x00A0;)&#x00A0;<br /><span class="label"><a 
 id="x1-14019r19"></a></span>paths[2:(n+1),&#x00A0;1:k,&#x00A0;1:interval]&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 30--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;totals&#x00A0;<br /><span class="label"><a 
 id="x1-14020r20"></a></span>paths&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 31--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;paths&#x00A0;+&#x00A0;<span 
class="cmbx-12">start</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14021r21"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14022r22"></a></span>hitVictory&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 33--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;<span 
class="cmbx-12">apply</span>(paths,&#x00A0;2:3,&#x00A0;(<span 
class="cmbx-12">function</span>(x)<span 
class="cmbx-12">match</span>(victory,x,&#x00A0;nomatch=n+2)));&#x00A0;<br /><span class="label"><a 
 id="x1-14023r23"></a></span>hitRuin&#x00A0;<span class="lstinline"></span><span 
class="cmbx-12">&#x00A0;</span><span 
class="cmbx-12">&#x00A0;</span><span 
class="cmbx-12">&#x00A0;</span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 34--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;<span 
class="cmbx-12">apply</span>(paths,&#x00A0;2:3,&#x00A0;(<span 
class="cmbx-12">function</span>(x)<span 
class="cmbx-12">match</span>(ruin,&#x00A0;&#x00A0;&#x00A0;x,&#x00A0;nomatch=n+2)));&#x00A0;<br /><span class="label"><a 
 id="x1-14024r24"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">second</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">argument</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x2018;&#x2018;2:3&#x2019;&#x2019;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">means</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">column</span><!--l. 35--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmti-12">wise</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">in</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">each</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">panel</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14025r25"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">If</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">no</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">ruin</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">or</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">victory</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">on</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">a</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">walk</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">nomatch</span><span 
class="cmti-12">=</span><span 
class="cmti-12">n</span><span 
class="cmti-12">+2</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">sets</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">hitting</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14026r26"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">time</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">to</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">be</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">two</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">more</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">than</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">number</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">of</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">steps</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">one</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">more</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">than</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14027r27"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">column</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">length</span><span 
class="cmti-12">.</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">Without</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">nomatch</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">option</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">get</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">NA</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">which</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14028r28"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">works</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">poorly</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">with</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">comparison</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">hitRuin</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmmi-12">&#x003C;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">hitVictory</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">next</span><span 
class="cmti-12">.</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14029r29"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14030r30"></a></span>duration&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 41--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;<span 
class="cmbx-12">pmin</span>(hitVictory,&#x00A0;hitRuin)&#x00A0;<!--l. 41--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;1&#x00A0;<br /><span class="label"><a 
 id="x1-14031r31"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">Subtract</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">since</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">R</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">arrays</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">are</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><!--l. 42--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmti-12">based</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">so</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">duration</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">is</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">less</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">than</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">index</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14032r32"></a></span><span 
class="cmbx-12">is</span>.<span 
class="cmbx-12">na</span>(duration)&#x00A0;=&#x00A0;duration&#x00A0;<span 
class="cmmi-12">&#x003E;</span>&#x00A0;n&#x00A0;<br /><span class="label"><a 
 id="x1-14033r33"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">Remove</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">durations</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">greater</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">than</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">length</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">of</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">trials</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14034r34"></a></span>meanDuration&#x00A0;=&#x00A0;colMeans(&#x00A0;duration,&#x00A0;<span 
class="cmbx-12">na</span>.<span 
class="cmbx-12">rm</span>=TRUE)&#x00A0;<br /><span class="label"><a 
 id="x1-14035r35"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14036r36"></a></span>startValues&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 47--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;(ruin:victory);&#x00A0;<br /><span class="label"><a 
 id="x1-14037r37"></a></span>durationFunction&#x00A0;<span class="lstinline"></span><span 
class="cmmib-10x-x-120">&#x003C;</span><!--l. 48--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;<span 
class="cmbx-12">lm</span>(&#x00A0;meanDuration&#x00A0;<span class="lstinline"></span><span 
class="cmbx-12">&#x02DC;</span>&#x00A0;<span 
class="cmbx-12">poly</span>(startValues,2,raw=TRUE)&#x00A0;)&#x00A0;<br /><span class="label"><a 
 id="x1-14038r38"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">lm</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">is</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">R</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">function</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">for</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">linear</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">models</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">a</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">more</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">general</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">view</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">of</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14039r39"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">least</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">squares</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">linear</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">fitting</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">for</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">response</span><span 
class="cmti-12">&#x00A0;</span><span class="lstinline"></span><span 
class="cmbx-12">&#x02DC;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">terms</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14040r40"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14041r41"></a></span><span 
class="cmbx-12">plot</span>(startValues,&#x00A0;meanDuration,&#x00A0;<span 
class="cmbx-12">col</span>&#x00A0;=&#x00A0;&#x201D;blue&#x201D;);&#x00A0;<br /><span class="label"><a 
 id="x1-14042r42"></a></span><span 
class="cmbx-12">lines</span>(startValues,&#x00A0;<span 
class="cmbx-12">predict</span>(durationFunction,&#x00A0;<span 
class="cmbx-12">data</span>=startValues),&#x00A0;<span 
class="cmbx-12">col</span>&#x00A0;=&#x00A0;&#x201D;red&#x201D;)&#x00A0;<br /><span class="label"><a 
 id="x1-14043r43"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14044r44"></a></span><span 
class="cmbx-12">cat</span>(sprintf(&#x201D;Duration_function_is:_%f__+_%f_x_+_%f_x&#x02C6;2_<span 
class="cmsy-10x-x-120">&#x2216;</span>n&#x201D;,&#x00A0;<br /><span class="label"><a 
 id="x1-14045r45"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">coefficients</span>(durationFunction)[1],&#x00A0;<span 
class="cmbx-12">coefficients</span>(durationFunction)[2],&#x00A0;<br /><span class="label"><a 
 id="x1-14046r46"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">coefficients</span>(durationFunction)[3]&#x00A0;))
      
      </div>
      </dd><dt class="description">
<span 
class="cmbx-12">Octave</span> </dt><dd 
class="description">
      <!--l. 64--><p class="noindent" ><a 
href="http://www.math.unl.edu/~sdunbar1/MathematicalFinance/Lessons/FirstStepAnalysis/Duration/duration.m" >Octave script for ruin probabilities</a>.
</p>
      <!--l. 66-->
      <div class="lstlisting"><span class="label"><a 
 id="x1-14049r1"></a></span>p&#x00A0;=&#x00A0;0.5;&#x00A0;<br /><span class="label"><a 
 id="x1-14050r2"></a></span>n&#x00A0;=&#x00A0;300;&#x00A0;<br /><span class="label"><a 
 id="x1-14051r3"></a></span>k&#x00A0;=&#x00A0;200;&#x00A0;<br /><span class="label"><a 
 id="x1-14052r4"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14053r5"></a></span>victory&#x00A0;=&#x00A0;&#x00A0;10;&#x00A0;<br /><span class="label"><a 
 id="x1-14054r6"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">top</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">boundary</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">for</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">random</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">walk</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14055r7"></a></span>ruin&#x00A0;&#x00A0;&#x00A0;&#x00A0;=&#x00A0;0;&#x00A0;<br /><span class="label"><a 
 id="x1-14056r8"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">bottom</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">boundary</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">for</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">random</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">walk</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14057r9"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14058r10"></a></span>probRuinBeforeVictory&#x00A0;=&#x00A0;<span 
class="cmbx-12">zeros</span>(1,&#x00A0;victory<!--l. 76--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>ruin+1);&#x00A0;<br /><span class="label"><a 
 id="x1-14059r11"></a></span><span 
class="cmbx-12">for</span>&#x00A0;start&#x00A0;=&#x00A0;ruin:victory&#x00A0;<br /><span class="label"><a 
 id="x1-14060r12"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14061r13"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;winLose&#x00A0;=&#x00A0;2&#x00A0;<span 
class="cmsy-10x-x-120">&#x2217;</span>&#x00A0;(<span 
class="cmbx-12">rand</span>(n,k)&#x00A0;<span 
class="cmmi-12">&#x003C;</span>=&#x00A0;p)&#x00A0;<!--l. 79--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;1;&#x00A0;<br /><span class="label"><a 
 id="x1-14062r14"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><!--l. 80--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmti-12">1</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">for</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">Tails</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">for</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">Heads</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14063r15"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;totals&#x00A0;=&#x00A0;<span 
class="cmbx-12">cumsum</span>(winLose);&#x00A0;<br /><span class="label"><a 
 id="x1-14064r16"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><!--l. 82--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmti-12">n</span><span 
class="cmti-12">..</span><span 
class="cmti-12">n</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">(</span><span 
class="cmti-12">every</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">other</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">integer</span><span 
class="cmti-12">)</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">binomial</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">rv</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">sample</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14065r17"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14066r18"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;paths&#x00A0;=&#x00A0;[<span 
class="cmbx-12">zeros</span>(1,k);&#x00A0;totals]&#x00A0;+&#x00A0;start;&#x00A0;<br /><span class="label"><a 
 id="x1-14067r19"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;victoryOrRuin&#x00A0;=&#x00A0;<span 
class="cmbx-12">zeros</span>(1,k);&#x00A0;<br /><span class="label"><a 
 id="x1-14068r20"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">for</span>&#x00A0;j&#x00A0;=&#x00A0;1:k&#x00A0;<br /><span class="label"><a 
 id="x1-14069r21"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;hitVictory&#x00A0;=&#x00A0;<span 
class="cmbx-12">find</span>(paths(:,j)&#x00A0;<span 
class="cmmi-12">&#x003E;</span>=&#x00A0;victory);&#x00A0;<br /><span class="label"><a 
 id="x1-14070r22"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;hitRuin&#x00A0;&#x00A0;=&#x00A0;<span 
class="cmbx-12">find</span>(paths(:,j)&#x00A0;<span 
class="cmmi-12">&#x003C;</span>=&#x00A0;ruin);&#x00A0;<br /><span class="label"><a 
 id="x1-14071r23"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">if</span>&#x00A0;(&#x00A0;!rows(hitVictory)&#x00A0;&#x0026;&#x0026;&#x00A0;!rows(hitRuin)&#x00A0;)&#x00A0;<br /><span class="label"><a 
 id="x1-14072r24"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">no</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">victory</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">no</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">ruin</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14073r25"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">do</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">nothing</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14074r26"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">elseif</span>&#x00A0;(&#x00A0;rows(hitVictory)&#x00A0;&#x0026;&#x0026;&#x00A0;!rows(hitRuin)&#x00A0;)&#x00A0;<br /><span class="label"><a 
 id="x1-14075r27"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">victory</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">no</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">ruin</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14076r28"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;victoryOrRuin(j)&#x00A0;=&#x00A0;hitVictory(1)<!--l. 94--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>1;&#x00A0;<br /><span class="label"><a 
 id="x1-14077r29"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">##</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">subtract</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">since</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">vectors</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">are</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><!--l. 95--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmti-12">based</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14078r30"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">elseif</span>&#x00A0;(&#x00A0;!rows(hitVictory)&#x00A0;&#x0026;&#x0026;&#x00A0;rows(hitRuin)&#x00A0;)&#x00A0;<br /><span class="label"><a 
 id="x1-14079r31"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">no</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">victory</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">but</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">hit</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">ruin</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14080r32"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;victoryOrRuin(j)&#x00A0;=&#x00A0;<!--l. 98--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>(hitRuin(1)<!--l. 98--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>1);&#x00A0;<br /><span class="label"><a 
 id="x1-14081r33"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">##</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">subtract</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">since</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">vectors</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">are</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><!--l. 99--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmti-12">based</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14082r34"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">else</span>&#x00A0;<span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">(</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">rows</span><span 
class="cmti-12">(</span><span 
class="cmti-12">hitvictory</span><span 
class="cmti-12">)</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x0026;&#x0026;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">rows</span><span 
class="cmti-12">(</span><span 
class="cmti-12">hitruin</span><span 
class="cmti-12">)</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">)</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14083r35"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">victory</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">and</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">ruin</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14084r36"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">if</span>&#x00A0;(&#x00A0;hitVictory(1)&#x00A0;<span 
class="cmmi-12">&#x003C;</span>&#x00A0;hitRuin(1)&#x00A0;)&#x00A0;<br /><span class="label"><a 
 id="x1-14085r37"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;victoryOrRuin(j)&#x00A0;=&#x00A0;hitVictory(1)<!--l. 103--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>1;&#x00A0;<br /><span class="label"><a 
 id="x1-14086r38"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">code</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">hitting</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">victory</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14087r39"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">##</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">subtract</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">since</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">vectors</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">are</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><!--l. 105--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmti-12">based</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14088r40"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">else</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14089r41"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;victoryOrRuin(j)&#x00A0;=&#x00A0;<!--l. 107--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>(hitRuin(1)<!--l. 107--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>1);&#x00A0;<br /><span class="label"><a 
 id="x1-14090r42"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">code</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">hitting</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">ruin</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">as</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">negative</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14091r43"></a></span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">##</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">subtract</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">since</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">vectors</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">are</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">1</span><!--l. 109--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmti-12">based</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14092r44"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">endif</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14093r45"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">endif</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14094r46"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">endfor</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14095r47"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14096r48"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;durationUntilVictoryOrRuin(start&#x00A0;+&#x00A0;(<!--l. 114--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>ruin+1))&#x00A0;=&#x00A0;<span 
class="cmbx-12">mean</span>(<span 
class="cmbx-12">abs</span>(&#x00A0;victoryOrRuin&#x00A0;));&#x00A0;<br /><span class="label"><a 
 id="x1-14097r49"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14098r50"></a></span><span 
class="cmbx-12">endfor</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14099r51"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14100r52"></a></span>durationFunction&#x00A0;=&#x00A0;<span 
class="cmbx-12">polyfit</span>([ruin:victory],&#x00A0;durationUntilVictoryOrRuin,&#x00A0;<span 
class="cmsy-10x-x-120">&#x2216;</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14101r53"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;2);&#x00A0;<br /><span class="label"><a 
 id="x1-14102r54"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14103r55"></a></span><span 
class="cmbx-12">plot</span>([ruin:victory],&#x00A0;durationUntilVictoryOrRuin,&#x00A0;&#x2019;+r&#x2019;);&#x00A0;<br /><span class="label"><a 
 id="x1-14104r56"></a></span><span 
class="cmbx-12">hold</span>&#x00A0;on;&#x00A0;<br /><span class="label"><a 
 id="x1-14105r57"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14106r58"></a></span>x&#x00A0;=&#x00A0;<span 
class="cmbx-12">linspace</span>(ruin,&#x00A0;victory,&#x00A0;101);&#x00A0;<br /><span class="label"><a 
 id="x1-14107r59"></a></span>fittedDuration&#x00A0;=&#x00A0;<span 
class="cmbx-12">polyval</span>(durationFunction,&#x00A0;x);&#x00A0;<br /><span class="label"><a 
 id="x1-14108r60"></a></span><span 
class="cmbx-12">plot</span>(x,&#x00A0;fittedDuration,&#x00A0;&#x2019;<!--l. 126--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x2019;);&#x00A0;<br /><span class="label"><a 
 id="x1-14109r61"></a></span><span 
class="cmbx-12">hold</span>&#x00A0;off;&#x00A0;<br /><span class="label"><a 
 id="x1-14110r62"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14111r63"></a></span><span 
class="cmbx-12">disp</span>(&#x201D;Duration_function_is_a_2_+_a_1_x_+_a_0_x&#x02C6;2_where:&#x201D;)&#x00A0;<br /><span class="label"><a 
 id="x1-14112r64"></a></span><span 
class="cmbx-12">disp</span>(&#x201D;a_2&#x201D;),&#x00A0;<span 
class="cmbx-12">disp</span>(durationFunction(3)),&#x00A0;<br /><span class="label"><a 
 id="x1-14113r65"></a></span><span 
class="cmbx-12">disp</span>(&#x201D;a_1&#x201D;),&#x00A0;<span 
class="cmbx-12">disp</span>(durationFunction(2)),&#x00A0;<br /><span class="label"><a 
 id="x1-14114r66"></a></span><span 
class="cmbx-12">disp</span>(&#x201D;a_0&#x201D;),&#x00A0;<span 
class="cmbx-12">disp</span>(durationFunction(1))
      
      </div>
      </dd><dt class="description">
<span 
class="cmbx-12">Perl</span> </dt><dd 
class="description">
      <!--l. 139--><p class="noindent" ><a 
href="http://www.math.unl.edu/~sdunbar1/MathematicalFinance/Lessons/FirstStepAnalysis/Duration/duration.pl" >Perl PDL script for ruin probabilities</a>.
</p>
      <!--l. 141-->
      <div class="lstlisting"><span class="label"><a 
 id="x1-14117r1"></a></span><span 
class="cmbx-12">use</span>&#x00A0;PDL::NiceSlice;&#x00A0;<br /><span class="label"><a 
 id="x1-14118r2"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14119r3"></a></span>$p&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;=&#x00A0;0.5;&#x00A0;<br /><span class="label"><a 
 id="x1-14120r4"></a></span>$n&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;=&#x00A0;300;&#x00A0;<br /><span class="label"><a 
 id="x1-14121r5"></a></span>$k&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;=&#x00A0;200;&#x00A0;<br /><span class="label"><a 
 id="x1-14122r6"></a></span>$victory&#x00A0;&#x00A0;=&#x00A0;10;&#x00A0;<br /><span class="label"><a 
 id="x1-14123r7"></a></span>$ruin&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;=&#x00A0;0;&#x00A0;<br /><span class="label"><a 
 id="x1-14124r8"></a></span>$interval&#x00A0;=&#x00A0;$victory&#x00A0;<!--l. 149--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;$ruin&#x00A0;+&#x00A0;1;&#x00A0;<br /><span class="label"><a 
 id="x1-14125r9"></a></span>$winLose&#x00A0;&#x00A0;=&#x00A0;2&#x00A0;<span 
class="cmsy-10x-x-120">&#x2217;</span>&#x00A0;(&#x00A0;random(&#x00A0;$k,&#x00A0;$n,&#x00A0;$interval&#x00A0;)&#x00A0;<span 
class="cmmi-12">&#x003C;</span>=&#x00A0;$p&#x00A0;)&#x00A0;<!--l. 150--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;1;&#x00A0;<br /><span class="label"><a 
 id="x1-14126r10"></a></span>$totals&#x00A0;&#x00A0;&#x00A0;=&#x00A0;(&#x00A0;cumusumover&#x00A0;$winLose<!--l. 151--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>xchg(&#x00A0;0,&#x00A0;1&#x00A0;)&#x00A0;)<!--l. 151--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>transpose;&#x00A0;<br /><span class="label"><a 
 id="x1-14127r11"></a></span>$start&#x00A0;&#x00A0;&#x00A0;&#x00A0;=&#x00A0;zeroes(&#x00A0;$k,&#x00A0;$n&#x00A0;+&#x00A0;1,&#x00A0;$interval&#x00A0;)<!--l. 152--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>zlinvals(&#x00A0;$ruin,&#x00A0;$victory&#x00A0;);&#x00A0;<br /><span class="label"><a 
 id="x1-14128r12"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14129r13"></a></span>$paths&#x00A0;=&#x00A0;zeroes(&#x00A0;$k,&#x00A0;$n&#x00A0;+&#x00A0;1,&#x00A0;$interval&#x00A0;);&#x00A0;<br /><span class="label"><a 
 id="x1-14130r14"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14131r15"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">use</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">PDL</span><span 
class="cmti-12">:</span><span 
class="cmti-12">NiceSlice</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">on</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">next</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">line</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14132r16"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">Note</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">use</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">of</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">concat</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">operator</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">here</span><span 
class="cmti-12">.</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14133r17"></a></span>$paths&#x00A0;(&#x00A0;0&#x00A0;:&#x00A0;(&#x00A0;$k&#x00A0;<!--l. 158--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;1&#x00A0;),&#x00A0;1&#x00A0;:&#x00A0;$n,&#x00A0;0&#x00A0;:&#x00A0;(&#x00A0;$interval&#x00A0;<!--l. 158--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;1&#x00A0;)&#x00A0;)&#x00A0;.=&#x00A0;$totals;&#x00A0;<br /><span class="label"><a 
 id="x1-14134r18"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14135r19"></a></span>$paths&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;&#x00A0;=&#x00A0;$paths&#x00A0;+&#x00A0;$start;&#x00A0;<br /><span class="label"><a 
 id="x1-14136r20"></a></span>$hitVictory&#x00A0;=&#x00A0;$paths<!--l. 161--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>setbadif(&#x00A0;$paths&#x00A0;<span 
class="cmmi-12">&#x003C;</span>&#x00A0;$victory&#x00A0;);&#x00A0;<br /><span class="label"><a 
 id="x1-14137r21"></a></span>$hitRuin&#x00A0;&#x00A0;&#x00A0;&#x00A0;=&#x00A0;$paths<!--l. 162--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>setbadif(&#x00A0;$paths&#x00A0;<span 
class="cmmi-12">&#x003E;</span>&#x00A0;$ruin&#x00A0;);&#x00A0;<br /><span class="label"><a 
 id="x1-14138r22"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14139r23"></a></span>$victoryIndex&#x00A0;=&#x00A0;<br /><span class="label"><a 
 id="x1-14140r24"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;(&#x00A0;$hitVictory&#x00A0;(&#x00A0;,,&#x00A0;:&#x00A0;)<!--l. 165--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>xchg(&#x00A0;0,&#x00A0;1&#x00A0;)<!--l. 165--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>minimum_ind&#x00A0;)&#x00A0;<br /><span class="label"><a 
 id="x1-14141r25"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;<!--l. 166--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>inplace<!--l. 166--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>setbadtoval(&#x00A0;$n&#x00A0;+&#x00A0;1&#x00A0;);&#x00A0;<br /><span class="label"><a 
 id="x1-14142r26"></a></span>$ruinIndex&#x00A0;=&#x00A0;<br /><span class="label"><a 
 id="x1-14143r27"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;(&#x00A0;$hitRuin&#x00A0;(&#x00A0;,,&#x00A0;:&#x00A0;)<!--l. 168--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>xchg(&#x00A0;0,&#x00A0;1&#x00A0;)<!--l. 168--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>maximum_ind&#x00A0;)&#x00A0;<br /><span class="label"><a 
 id="x1-14144r28"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;<!--l. 169--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>inplace<!--l. 169--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>setbadtoval(&#x00A0;$n&#x00A0;+&#x00A0;1&#x00A0;);&#x00A0;<br /><span class="label"><a 
 id="x1-14145r29"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14146r30"></a></span>$durationUntilRuinOrVictory&#x00A0;=&#x00A0;<br /><span class="label"><a 
 id="x1-14147r31"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;(&#x00A0;$victoryIndex<!--l. 172--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>glue(&#x00A0;2,&#x00A0;$ruinIndex&#x00A0;)<!--l. 172--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>xchg(&#x00A0;2,&#x00A0;1&#x00A0;)&#x00A0;)<!--l. 172--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>xchg(&#x00A0;0,&#x00A0;1&#x00A0;)&#x00A0;<br /><span class="label"><a 
 id="x1-14148r32"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;<!--l. 173--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>setvaltobad(&#x00A0;$n&#x00A0;+&#x00A0;1&#x00A0;)<!--l. 173--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>minimum;&#x00A0;<br /><span class="label"><a 
 id="x1-14149r33"></a></span>(&#x00A0;$mean,&#x00A0;$prms,&#x00A0;$median,&#x00A0;$min,&#x00A0;$max,&#x00A0;$adev,&#x00A0;$rms&#x00A0;)&#x00A0;=&#x00A0;<br /><span class="label"><a 
 id="x1-14150r34"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;statsover($durationUntilRuinOrVictory);&#x00A0;<br /><span class="label"><a 
 id="x1-14151r35"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14152r36"></a></span><span 
class="cmbx-12">use</span>&#x00A0;PDL::Fit::Polynomial;&#x00A0;<br /><span class="label"><a 
 id="x1-14153r37"></a></span>$x&#x00A0;=&#x00A0;zeroes($interval)<!--l. 178--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmmi-12">&#x003E;</span>xlinvals(&#x00A0;$ruin,&#x00A0;$victory&#x00A0;);&#x00A0;<br /><span class="label"><a 
 id="x1-14154r38"></a></span>(&#x00A0;$ruinFunction,&#x00A0;$coeffs&#x00A0;)&#x00A0;=&#x00A0;fitpoly1d&#x00A0;$x,&#x00A0;$mean,&#x00A0;3;&#x00A0;<br /><span class="label"><a 
 id="x1-14155r39"></a></span><span 
class="cmbx-12">print</span>&#x00A0;&#x201D;Duration_function_is:_&#x201D;,&#x00A0;$coeffs&#x00A0;(0),&#x00A0;&#x201D;+&#x201D;,&#x00A0;$coeffs&#x00A0;(1),&#x00A0;&#x201D;x+&#x201D;,&#x00A0;<br /><span class="label"><a 
 id="x1-14156r40"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;$coeffs&#x00A0;(2),&#x00A0;&#x201D;x&#x02C6;2&#x201D;,&#x00A0;&#x201D;<span 
class="cmsy-10x-x-120">&#x2216;</span>n&#x201D;;
      
      </div>
      </dd><dt class="description">
<span 
class="cmbx-12">SciPy</span> </dt><dd 
class="description">
      <!--l. 187--><p class="noindent" ><a 
href="http://www.math.unl.edu/~sdunbar1/MathematicalFinance/Lessons/FirstStepAnalysis/Duration/duration.py" >Scientific Python script for ruin probabilities</a>.
</p>
      <!--l. 189-->
      <div class="lstlisting"><span class="label"><a 
 id="x1-14157r1"></a></span><span 
class="cmbx-12">import</span>&#x00A0;scipy&#x00A0;<br /><span class="label"><a 
 id="x1-14158r2"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14159r3"></a></span>p&#x00A0;=&#x00A0;0.5&#x00A0;<br /><span class="label"><a 
 id="x1-14160r4"></a></span>n&#x00A0;=&#x00A0;300&#x00A0;<br /><span class="label"><a 
 id="x1-14161r5"></a></span>k&#x00A0;=&#x00A0;200&#x00A0;<br /><span class="label"><a 
 id="x1-14162r6"></a></span>victory&#x00A0;=&#x00A0;10;&#x00A0;<br /><span class="label"><a 
 id="x1-14163r7"></a></span>ruin&#x00A0;=&#x00A0;0;&#x00A0;<br /><span class="label"><a 
 id="x1-14164r8"></a></span>interval&#x00A0;=&#x00A0;victory&#x00A0;<!--l. 197--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;ruin&#x00A0;+&#x00A0;1&#x00A0;<br /><span class="label"><a 
 id="x1-14165r9"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14166r10"></a></span>winLose&#x00A0;=&#x00A0;2<span 
class="cmsy-10x-x-120">&#x2217;</span>(&#x00A0;scipy.random.random((n,k,interval))&#x00A0;<span 
class="cmmi-12">&#x003C;</span>=&#x00A0;p&#x00A0;)&#x00A0;<!--l. 199--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math>&#x00A0;1&#x00A0;<br /><span class="label"><a 
 id="x1-14167r11"></a></span>totals&#x00A0;=&#x00A0;scipy.cumsum(winLose,&#x00A0;axis&#x00A0;=&#x00A0;0)&#x00A0;<br /><span class="label"><a 
 id="x1-14168r12"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14169r13"></a></span>start&#x00A0;=&#x00A0;scipy.multiply.outer(&#x00A0;scipy.ones((n+1,k),&#x00A0;dtype=int),&#x00A0;scipy.arange(ruin,&#x00A0;victory+1,&#x00A0;dtype=int))&#x00A0;<br /><span class="label"><a 
 id="x1-14170r14"></a></span>paths&#x00A0;=&#x00A0;scipy.zeros((n+1,k,interval),&#x00A0;dtype=int)&#x00A0;<br /><span class="label"><a 
 id="x1-14171r15"></a></span>paths[&#x00A0;1:n+1,&#x00A0;:,:]&#x00A0;=&#x00A0;totals&#x00A0;<br /><span class="label"><a 
 id="x1-14172r16"></a></span>paths&#x00A0;=&#x00A0;paths&#x00A0;+&#x00A0;start&#x00A0;<br /><span class="label"><a 
 id="x1-14173r17"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14174r18"></a></span><span 
class="cmbx-12">def</span>&#x00A0;match(a,b,nomatch=None):&#x00A0;<br /><span class="label"><a 
 id="x1-14175r19"></a></span>&#x00A0;&#x00A0;&#x00A0;&#x00A0;<span 
class="cmbx-12">return</span>&#x00A0;&#x00A0;b.index(a)&#x00A0;<span 
class="cmbx-12">if</span>&#x00A0;a&#x00A0;<span 
class="cmbx-12">in</span>&#x00A0;b&#x00A0;<span 
class="cmbx-12">else</span>&#x00A0;nomatch&#x00A0;<br /><span class="label"><a 
 id="x1-14176r20"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">arguments</span><span 
class="cmti-12">:</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">a</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">is</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">a</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">scalar</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">b</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">is</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">a</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">python</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">list</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">value</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">of</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">nomatch</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">is</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">scalar</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14177r21"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">returns</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">position</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">of</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">first</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">match</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">of</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">its</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">first</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">argument</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">in</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">its</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">second</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">argument</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14178r22"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">but</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">if</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">a</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">is</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">not</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">there</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">returns</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">value</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">nomatch</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14179r23"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">modeled</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">on</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">R</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">function</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">&#x201D;</span><span 
class="cmti-12">match</span><span 
class="cmti-12">&#x201D;,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">but</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">with</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">less</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">generality</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14180r24"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14181r25"></a></span>hitVictory&#x00A0;=&#x00A0;scipy.apply_along_axis(<span 
class="cmbx-12">lambda</span>&#x00A0;x:(&#x00A0;match(victory,x.tolist(),nomatch=n+2)),&#x00A0;0,&#x00A0;paths)&#x00A0;<br /><span class="label"><a 
 id="x1-14182r26"></a></span>hitRuin&#x00A0;=&#x00A0;scipy.apply_along_axis(<span 
class="cmbx-12">lambda</span>&#x00A0;x:match(ruin,x.tolist(),nomatch=n+2),&#x00A0;0,&#x00A0;paths)&#x00A0;<br /><span class="label"><a 
 id="x1-14183r27"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">If</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">no</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">ruin</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">or</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">victory</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">on</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">a</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">walk</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">nomatch</span><span 
class="cmti-12">=</span><span 
class="cmti-12">n</span><span 
class="cmti-12">+2</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">sets</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">hitting</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14184r28"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">time</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">to</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">be</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">two</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">more</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">than</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">number</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">of</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">steps</span><span 
class="cmti-12">,</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">one</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">more</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">than</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14185r29"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">the</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">column</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">length</span><span 
class="cmti-12">.</span>&#x00A0;<br /><span class="label"><a 
 id="x1-14186r30"></a></span>durationUntilRuinOrVictory&#x00A0;=&#x00A0;scipy.minimum(hitVictory,&#x00A0;hitRuin)&#x00A0;<br /><span class="label"><a 
 id="x1-14187r31"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14188r32"></a></span><span 
class="cmbx-12">import</span>&#x00A0;numpy.ma&#x00A0;<br /><span class="label"><a 
 id="x1-14189r33"></a></span>durationMasked&#x00A0;=&#x00A0;scipy.ma.masked_greater(durationUntilRuinOrVictory,&#x00A0;n)&#x00A0;<br /><span class="label"><a 
 id="x1-14190r34"></a></span>&#x00A0;<br /><span class="label"><a 
 id="x1-14191r35"></a></span>meanDuration&#x00A0;=&#x00A0;scipy.mean(durationUntilRuinOrVictory,&#x00A0;axis&#x00A0;=&#x00A0;0)&#x00A0;<br /><span class="label"><a 
 id="x1-14192r36"></a></span>durationFunction&#x00A0;=&#x00A0;scipy.polyfit(&#x00A0;scipy.arange(ruin,&#x00A0;victory+1,&#x00A0;dtype=int),&#x00A0;meanDuration,&#x00A0;2)&#x00A0;<br /><span class="label"><a 
 id="x1-14193r37"></a></span><span 
class="cmbx-12">print</span>&#x00A0;&#x201D;Duration_function_is:_&#x201D;,&#x00A0;durationFunction[2],&#x00A0;&#x201D;+&#x201D;,&#x00A0;durationFunction[1],&#x00A0;&#x201D;x+&#x201D;,&#x00A0;durationFunction[0],&#x00A0;&#x201D;x&#x02C6;2&#x201D;&#x00A0;<br /><span class="label"><a 
 id="x1-14194r38"></a></span><span 
class="cmti-12">#</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">should</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">return</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">coefficients</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">to</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">(</span><span 
class="cmti-12">x</span><!--l. 227--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmti-12">ruin</span><span 
class="cmti-12">)</span><span 
class="cmsy-10x-x-120">&#x2217;</span><span 
class="cmti-12">(</span><span 
class="cmti-12">victory</span><span 
class="cmti-12">&#x00A0;</span><!--l. 227--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mo 
class="MathClass-bin">&#x2212;</mo></math><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">x</span><span 
class="cmti-12">),</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">descending</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">degree</span><span 
class="cmti-12">&#x00A0;</span><span 
class="cmti-12">order</span>
      
                                                                          

                                                                          
      </div>
      </dd></dl>
<!--l. 313--><p class="noindent" >__________________________________________________________________________
</p><!--l. 315--><p class="indent" >   <img 
src="../../../../CommonInformation/Lessons/solveproblems.png" alt="Problems to Work"  
 />
</p>
   <h3 class="likesectionHead"><a 
 id="x1-15000"></a>Problems to Work for Understanding</h3>
<!--l. 317--><p class="noindent" >
      </p><ol  class="enumerate1" >
      <li 
  class="enumerate" id="x1-15002x1">
           <ol  class="enumerate2" >
           <li 
  class="enumerate" id="x1-15004x1">Using a trial function of the form <!--l. 322--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msubsup><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow><mrow 
><mi 
>p</mi></mrow></msubsup 
> <mo 
class="MathClass-rel">=</mo> <mi 
>k</mi> <mo 
class="MathClass-bin">+</mo> <mi 
>l</mi><msub><mrow 
><mi 
>T</mi></mrow><mrow 
>
<mn>0</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mi 
>m</mi><msubsup><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow><mrow 
><mn>2</mn></mrow></msubsup 
></mrow></math>,
           show that a particular solution of the non-homogeneous equation
<div class="math-display"><!--l. 325--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                       <msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>p</mi><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mi 
>q</mi><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2212;</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mn>1</mn>
</mrow></math></div>
           <!--l. 327--><p class="nopar" > is <!--l. 327--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2215;</mo><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>q</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>p</mi></mrow><mo 
class="MathClass-close">)</mo></mrow></mrow></math>.
           </p></li>
           <li 
  class="enumerate" id="x1-15006x2">Using a trial function of the form <!--l. 329--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msubsup><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow><mrow 
><mi 
>p</mi></mrow></msubsup 
> <mo 
class="MathClass-rel">=</mo> <mi 
>k</mi> <mo 
class="MathClass-bin">+</mo> <mi 
>l</mi><msub><mrow 
><mi 
>T</mi></mrow><mrow 
>
<mn>0</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mi 
>m</mi><msubsup><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow><mrow 
><mn>2</mn></mrow></msubsup 
></mrow></math>,
           show that a particular solution of the non-homogeneous equation
                                                                          

                                                                          
<div class="math-display"><!--l. 332--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" ><mrow 
>
                       <msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mfrac><mrow 
><mn>1</mn></mrow> 
<mrow 
><mn>2</mn></mrow></mfrac><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mfrac><mrow 
><mn>1</mn></mrow> 
<mrow 
><mn>2</mn></mrow></mfrac><msub><mrow 
><mi 
>D</mi></mrow><mrow 
><msub><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow></msub 
><mo 
class="MathClass-bin">&#x2212;</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-bin">+</mo> <mn>1</mn>
</mrow></math></div>
           <!--l. 335--><p class="nopar" > is <!--l. 335--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mo 
class="MathClass-bin">&#x2212;</mo><msubsup><mrow 
><mi 
>T</mi></mrow><mrow 
><mn>0</mn></mrow><mrow 
><mn>2</mn></mrow></msubsup 
></mrow></math>.</p></li></ol>
      </li>
      <li 
  class="enumerate" id="x1-15008x2">A gambler starts with $2 and wants to win $2 more to get to a total of $4
      before being ruined by losing all his money. He plays a coin-flipping game,
      with a coin that changes with his fortune.
           <ol  class="enumerate2" >
           <li 
  class="enumerate" id="x1-15010x1">If the gambler has $2 he plays with a coin that gives probability
           <!--l. 345--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi> <mo 
class="MathClass-rel">=</mo> <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>2</mn></mrow></math>
           of winning a dollar and probability <!--l. 346--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>q</mi> <mo 
class="MathClass-rel">=</mo> <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>2</mn></mrow></math>
           of losing a dollar.
           </li>
           <li 
  class="enumerate" id="x1-15012x2">If the gambler has $3 he plays with a coin that gives probability
           <!--l. 349--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi> <mo 
class="MathClass-rel">=</mo> <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>4</mn></mrow></math>
           of winning a dollar and probability <!--l. 350--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>q</mi> <mo 
class="MathClass-rel">=</mo> <mn>3</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>4</mn></mrow></math>
           of losing a dollar.
           </li>
           <li 
  class="enumerate" id="x1-15014x3">If the gambler has $1 he plays with a coin that gives probability
           <!--l. 353--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi> <mo 
class="MathClass-rel">=</mo> <mn>3</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>4</mn></mrow></math>
           of winning a dollar and probability <!--l. 354--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>q</mi> <mo 
class="MathClass-rel">=</mo> <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>4</mn></mrow></math>
           of losing a dollar.</li></ol>
      <!--l. 356--><p class="noindent" >Use &#x201C;first step analysis&#x201D; to write three equations in three unknowns (with
      two additional boundary conditions) that give the expected duration of the
      game that the gambler plays. Solve the equations to find the expected
      duration.
                                                                          

                                                                          
      </p></li>
      <li 
  class="enumerate" id="x1-15016x3">A gambler plays a coin flipping game in which the probability of winning on a flip
      is <!--l. 363--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi> <mo 
class="MathClass-rel">=</mo> <mn>0</mn><mo 
class="MathClass-punc">.</mo><mn>4</mn></mrow></math>
      and the probability of losing on a flip is
      <!--l. 364--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>q</mi> <mo 
class="MathClass-rel">=</mo> <mn>1</mn> <mo 
class="MathClass-bin">&#x2212;</mo> <mi 
>p</mi> <mo 
class="MathClass-rel">=</mo> <mn>0</mn><mo 
class="MathClass-punc">.</mo><mn>6</mn></mrow></math>.
      The gambler wants to reach the victory level of $16 before being ruined with
      a fortune of $0. The gambler starts with $8, bets $2 on each flip when the
      fortune is $6, $8, $10 and bets $4 when the fortune is $4 or $12. Compute
      the probability of ruin in this game.
      </li>
      <li 
  class="enumerate" id="x1-15018x4">This problem is adapted from <span 
class="cmti-12">Stochastic Calculus and Financial</span>
      <span 
class="cmti-12">Applications </span>by J. Michael Steele, Springer, New York, 2001, Chapter
      1, Section 1.6, page 9. Information on buy-backs is adapted from
      investorwords.com. This problem suggests how results on biased random
      walks can be worked into more realistic models.
      <!--l. 402--><p class="noindent" >Consider a naive model for a stock that has a support level of $20/share
      because of a corporate buy-back program. (This means the company will
      buy back stock if shares dip below $20 per share. In the case of stocks, this
      reduces the number of shares outstanding, giving each remaining
      shareholder a larger percentage ownership of the company. This is usually
      considered a sign that the company&#x2019;s management is optimistic about the
      future and believes that the current share price is undervalued. Reasons for
      buy-backs include putting unused cash to use, raising earnings per
      share, increasing internal control of the company, and obtaining
      stock for employee stock option plans or pension plans.) Suppose
      also that the stock price moves randomly with a downward bias
      when the price is above $20, and randomly with an upward bias
      when the price is below $20. To make the problem concrete, we let
      <!--l. 416--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi></mrow></msub 
></mrow></math> denote the stock
      price at time <!--l. 417--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>n</mi></mrow></math>,
      and we express our stock support hypothesis by the assumptions
      that
                                                                          

                                                                          
      <!--tex4ht:inline--></p><!--l. 419--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" >
<mtable 
class="eqnarray-star" columnalign="right center left" >
<mtr><mtd 
class="eqnarray-1"> <mi 
>&#x2119;</mi> <mfenced separators="" 
open="["  close="]" ><mrow><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mn>2</mn><mn>1</mn><mo 
class="MathClass-rel">|</mo><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mn>2</mn><mn>0</mn></mrow></mfenced></mtd><mtd 
class="eqnarray-2">    <mo 
class="MathClass-rel">=</mo></mtd><mtd 
class="eqnarray-3">    <mn>9</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>1</mn><mn>0</mn></mtd><mtd 
class="eqnarray-4"> <mtext class="eqnarray"></mtext></mtd>
</mtr><mtr><mtd 
class="eqnarray-1"> <mi 
>&#x2119;</mi> <mfenced separators="" 
open="["  close="]" ><mrow><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mn>1</mn><mn>9</mn><mo 
class="MathClass-rel">|</mo><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mn>2</mn><mn>0</mn></mrow></mfenced></mtd><mtd 
class="eqnarray-2">    <mo 
class="MathClass-rel">=</mo></mtd><mtd 
class="eqnarray-3">    <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>1</mn><mn>0</mn></mtd><mtd 
class="eqnarray-4"> <mtext class="eqnarray"></mtext></mtd>                                                      </mtr></mtable>
</math>
      <!--l. 422--><p class="nopar" >
      </p><!--l. 424--><p class="noindent" >We then reflect the downward bias at price levels above $20 by requiring that for
      <!--l. 425--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>k</mi> <mo 
class="MathClass-rel">&#x003E;</mo> <mn>2</mn><mn>0</mn></mrow></math>:
      <!--tex4ht:inline--></p><!--l. 426--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" >
<mtable 
class="eqnarray-star" columnalign="right center left" >
<mtr><mtd 
class="eqnarray-1"> <mi 
>&#x2119;</mi> <mfenced separators="" 
open="["  close="]" ><mrow><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>k</mi> <mo 
class="MathClass-bin">+</mo> <mn>1</mn><mo 
class="MathClass-rel">|</mo><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>k</mi></mrow></mfenced></mtd><mtd 
class="eqnarray-2">   <mo 
class="MathClass-rel">=</mo></mtd><mtd 
class="eqnarray-3">    <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>3</mn> </mtd><mtd 
class="eqnarray-4"> <mtext class="eqnarray"></mtext></mtd>
</mtr><mtr><mtd 
class="eqnarray-1"> <mi 
>&#x2119;</mi> <mfenced separators="" 
open="["  close="]" ><mrow><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>k</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mn>1</mn><mo 
class="MathClass-rel">|</mo><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>k</mi></mrow></mfenced></mtd><mtd 
class="eqnarray-2">   <mo 
class="MathClass-rel">=</mo></mtd><mtd 
class="eqnarray-3">    <mn>2</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>3</mn><mo 
class="MathClass-punc">.</mo></mtd><mtd 
class="eqnarray-4"> <mtext class="eqnarray"></mtext></mtd>                                            </mtr></mtable>
</math>
      <!--l. 429--><p class="nopar" >
      </p><!--l. 431--><p class="noindent" >We then reflect the upward bias at price levels below $20 by requiring that for
      <!--l. 432--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>k</mi> <mo 
class="MathClass-rel">&#x003C;</mo> <mn>2</mn><mn>0</mn></mrow></math>:
                                                                          

                                                                          
      <!--tex4ht:inline--></p><!--l. 433--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="block" >
<mtable 
class="eqnarray-star" columnalign="right center left" >
<mtr><mtd 
class="eqnarray-1"> <mi 
>&#x2119;</mi> <mfenced separators="" 
open="["  close="]" ><mrow><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>k</mi> <mo 
class="MathClass-bin">+</mo> <mn>1</mn><mo 
class="MathClass-rel">|</mo><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>k</mi></mrow></mfenced></mtd><mtd 
class="eqnarray-2">   <mo 
class="MathClass-rel">=</mo></mtd><mtd 
class="eqnarray-3">    <mn>2</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>3</mn></mtd><mtd 
class="eqnarray-4"> <mtext class="eqnarray"></mtext></mtd>
</mtr><mtr><mtd 
class="eqnarray-1"> <mi 
>&#x2119;</mi> <mfenced separators="" 
open="["  close="]" ><mrow><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi><mo 
class="MathClass-bin">+</mo><mn>1</mn></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>k</mi> <mo 
class="MathClass-bin">&#x2212;</mo> <mn>1</mn><mo 
class="MathClass-rel">|</mo><msub><mrow 
><mi 
>Y</mi> </mrow><mrow 
><mi 
>n</mi></mrow></msub 
> <mo 
class="MathClass-rel">=</mo> <mi 
>k</mi></mrow></mfenced></mtd><mtd 
class="eqnarray-2">   <mo 
class="MathClass-rel">=</mo></mtd><mtd 
class="eqnarray-3">    <mn>1</mn><mo 
class="MathClass-bin">&#x2215;</mo><mn>3</mn></mtd><mtd 
class="eqnarray-4"> <mtext class="eqnarray"></mtext></mtd>                                                     </mtr></mtable>
</math>
      <!--l. 436--><p class="nopar" >
      </p><!--l. 438--><p class="noindent" >Using the methods of &#x201C;single-step analysis&#x201D; calculate the expected time for
      the stock to fall from $25 through the support level all the way down to $18.
      (There is no reasonable way to solve this problem using formulas. Instead
      you will have to go back to basic principles of single-step or first-step
      analysis to solve the problem.)
      </p></li>
      <li 
  class="enumerate" id="x1-15023x5">Perform some simulations of the coin-flipping game, varying
      <!--l. 445--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi></mrow></math>
      and the start value. How does the value of
      <!--l. 446--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi></mrow></math>
      affect the experimental duration of victory and ruin?
      </li>
      <li 
  class="enumerate" id="x1-15025x6">Modify the simulations by changing the value of
      <!--l. 449--><math 
 xmlns="http://www.w3.org/1998/Math/MathML" display="inline" ><mrow 
><mi 
>p</mi></mrow></math>
      and comparing the experimental results for each starting value to the
      theoretical duration function.
      </li>
      <li 
  class="enumerate" id="x1-15027x7">Modify the duration scripts to perform simulations of the duration
                                                                          

                                                                          
      calculations in the table in the section Some Calculations for Illustration
      and compare the results.
      </li></ol>
<!--l. 459--><p class="noindent" >__________________________________________________________________________
</p><!--l. 461--><p class="indent" >   <img 
src="../../../../CommonInformation/Lessons/books.png" alt="Books"  
 />
</p>
   <h3 class="likesectionHead"><a 
 id="x1-16000"></a>Reading Suggestion:</h3>
<!--l. 1--><p class="noindent" >
</p>
   <h3 class="likesectionHead"><a 
 id="x1-17000"></a>References</h3>
<!--l. 1--><p class="noindent" >
   </p><div class="thebibliography">
   <p class="bibitem" ><span class="biblabel">
 [1]<span class="bibsp">&#x00A0;&#x00A0;&#x00A0;</span></span><a 
 id="Xfeller73"></a>William  Feller.    <span 
class="cmti-12">An  Introduction  to  Probability  Theory  and  Its</span>
   <span 
class="cmti-12">Applications, Volume I</span>, volume&#x00A0;I.  John Wiley and Sons, third edition,
   1973. QA 273 F3712.
   </p>
   <p class="bibitem" ><span class="biblabel">
 [2]<span class="bibsp">&#x00A0;&#x00A0;&#x00A0;</span></span><a 
 id="Xsteele01"></a>J.&#x00A0;Michael Steele.  <span 
class="cmti-12">Stochastic Calculus and Financial Applications</span>.
   Springer-Verlag, 2001. QA 274.2 S 74.
</p>
   </div>
<!--l. 481--><p class="noindent" >__________________________________________________________________________
</p><!--l. 483--><p class="indent" >   <img 
src="../../../../CommonInformation/Lessons/chainlink.png" alt="Links"  
 />
                                                                          

                                                                          
</p>
   <h3 class="likesectionHead"><a 
 id="x1-18000"></a>Outside Readings and Links:</h3>
<!--l. 485--><p class="noindent" >
      </p><ol  class="enumerate1" >
      <li 
  class="enumerate" id="x1-18002x1"><a 
href="http://www.math.uah.edu/stat/games/index.html" >Virtual  Labs  in  Probability</a>.  Games  of  Chance.  Scroll  down  and
      select the Red and Black Experiment (marked in red in the Applets
      Section. Read the description since the scenario is slightly different but
      equivalent to the description above.)
      </li>
      <li 
  class="enumerate" id="x1-18004x2"><a 
href="http://math.ucsd.edu/~anistat/gamblers_ruin.html" >University of California, San Diego, Department of Mathematics, A.M.
      Garsia</a>. A java applet that simulates how long it takes for a gambler to
      go broke. You can control how much money you and the casino start
      with, the house odds, and the maximum number of games. Results are
      a graph and a summary table. Submitted by Matt Odell, September 8,
      2003.</li></ol>
<!--l. 502--><p class="noindent" >__________________________________________________________________________
</p><!--l. 3--><p class="indent" >   <span 
class="cmr-10x-x-109">I check all the information on each page for correctness and typographical errors.</span>
<span 
class="cmr-10x-x-109">Nevertheless, some errors may occur and I would be grateful if you would alert me to</span>
<span 
class="cmr-10x-x-109">such errors. I make every reasonable effort to present current and accurate information</span>
<span 
class="cmr-10x-x-109">for public use, however I do not guarantee the accuracy or timeliness of information on</span>
<span 
class="cmr-10x-x-109">this website. Your use of the information from this website is strictly voluntary and at</span>
<span 
class="cmr-10x-x-109">your risk.</span>
</p><!--l. 12--><p class="indent" >   <span 
class="cmr-10x-x-109">I have checked the links to external sites for usefulness. Links to external websites</span>
<span 
class="cmr-10x-x-109">are provided as a convenience. I do not endorse, control, monitor, or guarantee the</span>
<span 
class="cmr-10x-x-109">information contained in any external website. I don&#x2019;t guarantee that the links are</span>
<span 
class="cmr-10x-x-109">active at all times. Use the links here with the same caution as you would all</span>
<span 
class="cmr-10x-x-109">information on the Internet. This website reflects the thoughts, interests and opinions of</span>
<span 
class="cmr-10x-x-109">its author. They do not explicitly represent official positions or policies of my</span>
<span 
class="cmr-10x-x-109">employer.</span>
</p><!--l. 22--><p class="indent" >   <span 
class="cmr-10x-x-109">Information on this website is subject to change without notice.</span>
</p><!--l. 2--><p class="indent" >   Steve Dunbar&#x2019;s Home Page, <span class="obeylines-h"><span class="verb"><span 
class="cmtt-12">http://www.math.unl.edu/~sdunbar1</span></span></span>
</p><!--l. 4--><p class="indent" >   Email to Steve Dunbar, <span class="obeylines-h"><span class="verb"><span 
class="cmtt-12">sdunbar1</span><span 
class="cmtt-12">&#x00A0;at</span><span 
class="cmtt-12">&#x00A0;unl</span><span 
class="cmtt-12">&#x00A0;dot</span><span 
class="cmtt-12">&#x00A0;edu</span></span></span>
</p><!--l. 506--><p class="indent" >   Last modified: Processed from <span class="LATEX">L<span class="A">A</span><span class="TEX">T<span 
class="E">E</span>X</span></span>&#x00A0;source on April 5, 2013
</p>
    
</body> 
</html> 

                                                                          


