COS 126

A Pseudo-Random Walk on Wall Street
Programming Assignment 5

Due: Wednesday, 11:59pm


The goal of this assignment is to help you understand how TOY works, and to illustrate that relatively simple computational models can handle useful and nontrivial calculations. You will write a TOY program to estimate the expected value of a certain stock option.

Overview. Consider a stock option for a fictitious company COS126 Corporation. The strike price is $133 and the expiration date is in 30 days. This means that you have the option to purchase one share of COS126 Corp for $133 in exactly 30 days. If the price of COS126 Corp exceeds $133 in exactly 30 days, the option is in the money since you could exercise your option and purchase 1 share for $133, then immediately sell it for a profit. You are not required to exercise your option, so if the stock price does not exceed $133, you will just throw it away. Note that you are only permitted to exercise the option on the expiration date. In finance lingo, this option is called a European call.

The current price of COS126 Corp. is $128/share. Suppose the price of the stock could be accurately modeled by the following random process. Each day, with equal likelihood and independently, the stock price either increases by $1 or decreases by $1. Your assignment is to write a TOY program to compute the expected value of the option after 30 days. If the stock price is $133 or less after 30 days, then the option is worthless. Otherwise, its value is the difference between the ending price and $133.

Some perspective. This famous and well-studied process is called a random walk. Many natural phenomenon (including the gamblers ruin problem from Lecture 2) have been modeled using this same process or variants. The random walk only allows discrete movements ($1 at a time). A continuous version of this process called Brownian motion is used in the Nobel prize-winning Black-Scholes model to price options. Brownian motion is also widely used to model the dispersion of ink flowing in water, and the behavior of atomic particles predicted by quantum physics.

The basic simulation. To estimate how valuable your option is after 30 days, consider the following simulation:

  • repeat 30 times
  • read a pseudo-random bit from standard input
  • increase the stock price by 1 if the bit is 1; otherwise decrease it by 1
  • if the final price is $133 or less, the profit is 0; otherwise the profit is the difference between the final price and $133.
  • To get a good statistical estimate of the expected value of your option, perform this simulation 100 times. Count up the total value V of the option over the 100 simulations, and print out this cumulative running total after each of the 100 simulations. Then, compute V/100 by hand: this estimates the expected value of the option.

    TOY simulator. To write and debug your TOY programs, use either the C TOY simulator or the Visual X-TOY simulator in Java.

    Pseudo-random bits. We provide a C program bits.c to generate pseduo-random bits. You will use TOY standard input to read these bits into your program.

    What to submit. Name your TOY program option.toy, and submit it along with a readme file. Your TOY program should be amply commented. Your readme file should contain a description of your code and a table of what each register is used for. Also, calculate an estimate of the value of 1 option in dollars and cents, i.e., V / 100.



    This assignment was developed by Robert Sedgewick and Kevin Wayne
    Copyright © 2001 Robert Sedgewick