|
COS 323 - Computing for the Physical and Social Sciences
|
Fall 2013
|
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:
- Plan 1: Buy all of your oil now at
10 USD a barrel. Storage fees are negligible. In this case you
will have zero uncertainty about the cost of oil in December.
- Plan 2: Buy all of your oil in December, hoping the price of oil will not rise too much and will be lower in December than it is now (once more, comparing in September dollars). In this case you will have high uncertainty about the cost of oil.
- Plan 3: Purchase a single call option in September to protect yourself in case the price of oil becomes unusually high. You will have to pay for the option, but some of the uncertainty about the cost of the oil will be reduced.
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.
- Write a function gauss_pdf, that will return the pdf of the Gaussian Distribution for a given x value.
You can use the matlab function normpdf to compare your results.
- Write a function gauss_cdf that calculates the
cumulative normal distribution function by integrating the Gaussian Distribution from $-\infty$ to a specified
upper-limit, d:
$$C(d) = \int_{-\infty}^d \frac{1}{\sigma \sqrt{2\pi}}e^{-(x-\mu)^2/2\sigma^2}$$
If you are having difficulty with this, you may use -10 instead
of $-\infty$.
- Calculate this integral for d = -1. Use the matlab normcdf function to
compare the result. For d = 1 compute the integral using error
tolerances $10^{-8}$ and $10^{-10}$ and compare your results with those from
using matlab quad. Create a chart that compares the tolerance, approximate
integral, error, and number of function evaluations. The value for d=1
should be 0.841344746068543 (from using matlab normcdf) and you may use
this value when assessing error.
For the Lognormal Distribution assume $\mu$ is
2.4 and
$\sigma$ is 0.4120840928.
- Write a function, lognormal, that will return L(x).
- Create a function, elogshort, to find the solution of the following closed-form formula for calculating the expected value of the Lognormal Distribution[2]:
$$E(x) = e^{\mu+(\sigma^2/2)}$$
- Calculate the expected value of the Lognormal distribution using
integration (and compare to closed form result). What is the minimum step-size needed?
4. Determining Your Plan
- What is the expected cost of Plan 1 in USD in September?
- Assume that the price of oil, x, in December is lognormally distributed with
$\mu$ equal to
2.4 and $\sigma$ equal to
0.4120840928. What is the expected cost of oil in December in USD in September of Plan 2? Assume r = .05.
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
- Plot the option premiums against the exercise price using functions w, $d_1$, and $d_2$ and the following constants:
s = 10,
r = .05,
T = .25,
v = 0.4120840928.
-
Write a formula relating E(profit) to the following:
total revenue of the contract, TR,
fixed costs of labor and ships, FC,
expected cost of a barrel of oil in December, E(oilcost), and
the premium of an option to buy a barrel of oil, w.
Remember to express everything in September dollars.
- Write a formula for E(oilcost) which is a function of the exercise price, c
- Write a function ecost that returns E(oilcost) for a given exercise price
- Create a function, eprofit, that outputs E(profit) for a given exercise price, and then
plot eprofit against c.
- If you want to maximize your profits, would you buy options and if so at what exercise price? Why compared to Plans 1 and 2?
How would you determine the optimal exercise price?
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:
- Your code well-commented including the following
functions simp_quad, gauss_pdf, gauss_cdf, lognormal
elogshort, ecost, eprofit
and any auxiliary files.
- Submit an assignment writeup in a plain-text or PDF file,
containing:
- A description of your code (minimally: which files contain
solutions and a brief description of how
they work).
- Your responses to bolded questions in all sections.
- Your chart from Section 2.
- Both of your plots for Section 4.
- Any additional notes or comments you feel are necessary for
us to understand your assignment and grade it fairly and
easily.
The Dropbox link to submit your assignment is
here.
Last update
12-Nov-2013 11:52:57
smr at princeton edu