COS 323 - Computing for the Physical and Social Sciences

Fall 2013

Course home Outline and lecture notes Assignments


Assignment 3: Integration and Options

Due Tuesday, Nov. 19

In this assignment, you will implement adaptive Simpson quadrature for integration. You will be applying your implementation in order to compute cumulative distribution functions for measuring the uncertainty of the price of oil. You will use your implementation in order to decide whether to use a plan to buy options for oil prices to maximize profits for an order for your business.

By Hide Oki and Roger Ahn
edited by Ken Steiglitz October 4, 2007 and Sandra Batista, November 7, 2013

1. Motivation: Options

It is now September. You are the head of Okiahn, a major shipping company, and you have just been contracted to ship a freight-load of Christmas trees from Seattle to Hong Kong in December (3 months in the future) for 2,000,000 USD.1 Most of your costs such as labor and the costs of the ship are fixed at 1,500,000 USD (remember, in September dollars), since they have been already set by contract or purchased. The cost of 20,000 barrels of oil that you need to fuel your ship, however, is variable, since you have not purchased it yet. You can either follow: A call option for oil is the right to purchase from the seller of the option a barrel of oil at an agreed-upon price (called the exercise price) at a given date in the future (called the maturity date). The buyer of the call option pays a fee called the option premium for the option. If the spot price of oil (the market price of the good at a given time) is above the exercise price at the maturity date, it is in the option-holder's favor to exercise the option, because she can then buy the oil at a price lower than is available on the market [1].

For example, you could buy a December oil call option for a premium of 2 USD, which has an exercise price of 11 USD. The spot price of oil is 10 USD in September when you buy the option, but suppose that the spot price drastically increases to 15 USD in December. In this case, you would exercise the option and buy the barrel of oil at the exercise price of 11 USD, thus saving yourself 4 USD. If the price of oil falls to 6 USD instead, you will buy it at the spot price. By spending 2 USD in September on the option premium, you have insured yourself against drastic increases in the price of oil, thus reducing some of your uncertainty about its price.

One detail to remember about the price of oil in December, or any other price dictated in dollars in December, is that a dollar in September is worth more than in December. All dollar amounts in this assignment are in dollars in September unless otherwise noted. 1 USD can be placed into a riskless investment today and left to collect interest at the riskless interest rate until December. Suppose as an example that the quarterly riskless interest rate between today and December is incredibly high, so your 1 USD invested today will be 2 USD in December. Then having 2 USD in December is equivalent to having 1 USD now.

The following formula is used to discount future quantities of money into their present equivalents, so that they can be compared to other quantities denominated in present dollars: $$ V_p = V_f/e^{rT}$$ where $V_p$ is the present value, $V_f$ is future value, $r$ is the annual riskless rate of interest, and $T$ is the amount of time between now and the future point in question, expressed as a fraction of the year.

In the remainder of this assignment you will determine how to minimize your expenditure on oil for this contract by choosing Plan 1, 2, or 3. Buying options under Plan 3 can protect your company from a drastic rise in oil prices and reduce your risk, but the option premium will cut into your profits. You must find a balance point between protecting yourself and the option premium you pay for that protection. If you decide to buy options, you will ultimately have to decide which exercise price will put you at that balance point.

2. Integration

Write a matlab function that is your own version of the matlab quad function to evaluate integrals using adaptive Simpson quadrature. Your function will be in the file simp_quad.m and have the following declaration:
[q, fcnt] = simp_quad(fun,a,b,tol)
where q is the approximate value of the integral, fcnt is the number of function evaluations, fun is a handle to the integrand function, tol is the error tolerance, and a and b define the interval for integration.

You may have additional output and inputs for your function, but the output and input in the declaration above are minimum. You can test your implementation by comparing it to the matlab quad function that is declared the same way. For example to integrate the sine function between $0$ and $\pi$, you would use the following in matlab: quad(@sin,0,pi). Try the matlab quad and your simp_quad on various functions with various error tolerances to test your implementation. Be careful to examine the efficiency of your implementation in order to minimize the number of function evaluations.

3. Probability Distributions for Oil Price

To measure the uncertainty of the price of oil, we will use a probability density function (PDF), p(x), that measures for a given x the probability density or the likelihood of x (in this case an oil price) occurring. For continuous p, the likelihood of an x is infinitesimally small. However, we can use p to yield the probability that x occurs within a specified range of x when p integrated over that range.

The mean of a PDF p(x) is the expected value of x, E(x). This is the integral (or sum if discrete) of x with respect to its probability measure. In terms of a continuous PDF it is the integral over all possible values of x of x times the PDF, p(x),i.e., $$E(x) = \int_{-\infty}^{\infty}xp(x)dx$$ The standard deviation $\sigma$ is defined to be the square root of the variance V (x): $V (x) = E(x^2) -[E(x)]^2 $.

For this assignment we will use the Gaussian or Normal distribution and the Lognormal distribution in assessing oil prices. The normal distribution function, N(x), also known as the Gaussian or Normal distribution function has the following PDF: $$N(x) = \frac{1}{\sigma \sqrt{2\pi}}e^{-(x-\mu)^2/2\sigma^2}$$ The Lognormal distribution function, L(x), called such because $\ln x$ is normally distributed has the following PDF: $$L(x) = \frac{1}{x\sigma \sqrt{2\pi}}e^{-(\ln x-\mu)^2/2\sigma^2}$$ In the Gaussian distribution x is centered around $\mu$ with standard deviation $\sigma$ whereas in the lognormal distribution $\ln x$ is.

For the Gaussian distribution, assume $\mu$ is zero and $\sigma$ is 1.

For the Lognormal Distribution assume $\mu$ is 2.4 and $\sigma$ is 0.4120840928.

4. Determining Your Plan

In order to price your options you will use the Black-Scholes Model[3]. Their formula for pricing the option premiums is as follows: $$w = sC(d_1)-ce^{-rT}C(d_2)$$ $$d_1=\frac{\ln \frac{s}{c} +(r+ \frac{v^2}{2})T}{v\sqrt T}$$ $$d_2 = d_1 - v \sqrt T$$ where s is the spot price of oil, C(d) is the Cumulative Normal distribution, r is the annual risk-free interest rate, T is the length of time until maturity in fraction of a year, c is the exercise price of the option, and v is the volatility or standard deviation of the December price of oil

5. Bibliography

[1] M. D. Fitzgerald. Financial Options. Euromoney Publications, London, 1987.
[2] Jay L. Devore. Probability and Statistics for Engineering and the Sciences. Brooks/Cole Publishing Co., Pacific Grove, Ca., third edition, 1991.
[3] F. Black and M. Scholes. The pricing of options and corporate liabilities. J. Political Economy, 81:637-654, May-June 1973.

6. Submitting

This assignment is due Tuesday, November 19, 2013 at 11:59 PM. Please see the course policies regarding assignment submission, late assignments, and collaboration.

Please submit:

The Dropbox link to submit your assignment is here.


Last update 12-Nov-2013 11:52:57
smr at princeton edu