Mälardalen University
Akademin för utbildning, kultur och kommunikation
Monday, June 21, 2010
Masters Thesis in Financial Mathematics With Specialization In
Financial Engineering
Examensarbete i
Finansiell Matematik
By
Michail Musatov
Diego R. Calvo
Pricing American Style Asian Options
Using Dynamic Programming
Mälardalen University
Box 883
SE-721 23 Västerås
Sweden
2
Masters Thesis In Financial Mathematics
Date: Monday, June 21, 2010
Project name:
Pricing American Style Asian Options Using Dynamic Programming
Authors:
Diego R. Calvo
Michail Musatov
Supervisor:
Anatoliy Malyarenko
Comprising:
30 ECTS credits
3
Abstract
The objective of this study is to implement a Java applet for calculating
Bermudan/American-Asian call option prices and to obtain their respective optimal exercise strategies.
Additionally, the study presents a computational time analysis and the effect of the variables
on the option price.
4
Table of Contents
1.
Introduction ... 5
1.1
Aim of the Dissertation ... 5
2.
Theoretical Background ... 6
2.1 Basics Definition ... 6
2.2 Mathematical Framework ... 6
Formulation ... 6
Adjustments for Bermudan-Amerasian Contract ... 7
Value function ... 7
v
n-1explicit definition ... 8
v
m/w
mnumerical solution ... 8
Explicit computation ... 10
Choice of Grid and Computation speed ... 11
3. Users Manual ... 13
4. Output Analysis ... 15
4.1 Variable Effect On Premium Prices ... 15
4.3 Accuracy, Computational Time & Convergence ... 20
5. Conclusion ... 21
6. References ... 22
7. Appendix ... 22
Table A... 22
P Tables ... 23
Tables p= 25 – p=125 ... 23
Tables p= 150 – p=250 ... 24
Tables p= 275 – p=350 ... 25
Source Code ... 26
AmerasianDynamic GUI ... 26
Aki Class ... 36
Bki Class ... 37
Cubic Spline Fast Class ... 37
Dki Class ... 40
Erf Class ... 40
ValueFunctionW Class ... 42
5
ap Class ... 45
vBS Class ... 46
1.
Introduction
During the last few years we have seen markets change form bullish to bearish in short
periods of time and volatility spikes not only of stocks but other financial markets like
commodities and forex.
Options are used to hedge investments and, with all that instability, reducing financial risk
with them would become more expensive. A good solution to decrease hedging cost would
be to purchasing less expensive options. Alternatives such as barrier or Asian option would
be feasible because they cost less than their plain vanilla counterpart.
Asian options have been used since 1987
1but up to this day we do not have closed analytical
solution for pricing them. Different methods have been implemented to undertake this task
but the approach we used was originally proposed by Hatem Ben-Ameur, Michèle Breton,
Pierre L’Ecuyer
in their paper A Dynamic Programming Procedure for Pricing
American-Style Asian Options.
Despite using the same pricing approach both studies have several implementation
differences. For example, in the reference study they examines approximations of the type
liner-liner (d=1), linear quadratic (d=2) and also mention linear-cubic (d=3) but it is not
examined as thorough as the other two. It this study d=3 lies at the centre of our study.
1.1
Aim of the Dissertation
In this project we will build an algorithm that prices Bermudan/American-Asian call options.
More specific, the algorithm will calculate the premium prices knowing that:
• The exercise opportunities are at
with
where m* being the first
exercise opportunity,
• The payoff of such option at
is
• The underlying asset satisfies the stochastic differential equation
Since the implementation will be made in Java applet the user will be capable of interacting
with the algorithm and to analyse the optimal exercise strategy in a visual manner.
1
6
2.
Theoretical Background
2.1 Basics Definition
• American Option: They are the type of option contracts that allow the owner to
exercise at any time before expiration.
• European Option: In contrast to the American option, the European option only
allows its owner to exercise at maturity.
• Bermudan Option: A Bermudan has a mix between American and European exercise
rights. Meaning, that they can be exercised at only certain predetermined dates.
• Asian Option: They are path dependent derivatives whose payoff is computed by
taking the average prices of the underlying along the option’s lifespan instead of the
just taking the spot price when exercised. This type of option is commonly used in
commodity and energy markets.
2.2 Mathematical Framework
This section brings up and highlights the essential theoretical points and ideas of the
procedure developed by authors of our reference paper to pricing American style Asian
options.
Formulation
In order to calculate the price of Amerasian option and to find the optimal exercise strategy,
we need to solve a Value Function equation.
The value function, which expresses the value of an Amerasian option, is a function of the
current time, current price, and current average price and satisfies a Dynamic Programming
recurrence. Solving this equation yields both the option value and the optimal exercise
strategy.
The numerical solution approach for the DP Value Function equation will be based on
piecewise polynomial interpolation over rectangular finite elements.
We assume that an underlying asset price process {S(t), t [0,T]} is a GBM. The underlying
asset price S(·) satisfies stochastic differential equation:
dS(t) = rS(t)dt + σS(t)dW(t),
for 0≤t≤T
under risk neutral probability measure, where S(0)>0, r – risk-free rate, σ-volatility, T –
maturity date, and {W(t), t [0,T]} is standard Brownian motion.
The solution of this SDE is
7
where µ = r – σ
2/2
Adjustments for Bermudan-Amerasian Contract
Since the option under consideration is fixed strike, equally weighted, discretely sampled
Asian option based on arithmetic average, for which exercise opportunities are only at the
observations epochs, we need to introduce some relevant notations.
Let 0=t
0<t
1<t
2…<t
n=T
to be observation dates, where T is maturity (time horizon), and let
m*
to be the observation date from which the exercise becomes possible, i.e. the possible
exercise dates are t
m, where m*≤m≤n.
If the option is exercised at time t
m, then the payoff is max(0,
m– K),
where ,
m= (S(t
1)+…S(t
m))/m.
For simplicity we assume that dates are equally spaced meaning that for i=1..n: t
i-t
i-1= h
From the description above it becomes obvious that for n = 1 the option becomes ordinary
European Call Option, and for m*=n>1 the option is Eurasian type.
Value function
We denote the value function of state variables (s, ), and current time t
mas following:
v
m(
) , where m=0...n, s=S(t
m), =
m.For simplicity the state space (domain for v
m) taken for (
)
is [0, ∞)
2even though it is
obvious that at each step only part of it will be achievable.
Since S(·) is always positive, at t
mwe have
>s/m>0 if m>1
=s>0 if m =1
At t
nthe value of the option does not depend on underlying asset price, only on its average
price therefore we get v
n(
)
= v
n( )
. On the other hand, at t
0the price depends only on
underlying asset price and value function is defined by v
0(
)
= v
0(s).
We assume that optimal exercise strategy at all the times is used meaning that at any t
mstarting from m* the option is exercised only if payoff is larger than the value of holding the
option. We define exercise value for m*≤m≤n as
Holding value (the value of an option if it is not exercised) is defined by:
[v
m+1(S(t
m+1), (m +S(t
m+1))/(m+1))] for 0≤m≤n-1, (1)
where = e
-rhis discounted factor over the period [t
m,t
m+1]
8
1. For 0≤m<m* the option cannot be exercised and its value will be solely defined by
.
2. At m=n the only possible action is to exercise it or drop, the value of it is defined by
3. At any other time the value is the maximum of exercise value and hold value.
Therefore the resulting value function is:
v
m(2)
So functions
,
and consequently v
mare defined whole state space and all m using the
recurrence (1)&(2).
And the optimal exercise strategy is defined as follows:
In state (
) at time t
m, for m* ≤ m < n , exercise the option if
>
, and hold it
otherwise.
The value function DP equation (2) should be solved via backward iteration, from known v
nto compute v
n-1, then from the obtained result to calculate v
n-2and so on. The obstacle here is
that in explicit form we can obtain only v
n-1, for m<n-1 some approximation is needed. The
closed form solution for v
n-1and approximation for v
m(m<n-1)
will be presented below.
v
n-1explicit definition
As initial calculation the v
n-1needs to be obtained. The value function at t
n-1can be explicitly
defined by
2:
Where
is Black-Sholes formula defined by
= (Φ(d
1)s-
Φ(d
1- σ
)),
where
d
1=
and
v
m/w
mnumerical solution
In order to obtain further numerical solutions of v
m(for m<n-1), the approximation
technique will be used.
The plane
will be divided into rectangular grid and value function will be approximated
over each rectangle using polynomial function.
2
9
The solution proposed in our reference paper is not to fit approximation to v
mdirectly, but to
change a variable in order to simplify integration when approximation will be fitted to
value function equation. As a result it would be possible to express integral explicitly instead
of computing it numerically.
The mentioned change of variable is performed as follows
’ =
which is basically the value of
m-1.
We set w
m= v
mw
mhas the same properties as v
m, except that w
1does not depend on .
The value function (2) can now be rewritten as
w
m(3)
where
= max(0, -K)
=
[w
m+1(
)]
for 0≤m≤n-1
The next step would be to approximate each w
mby continuous polynomial function of
of degree 1 in s and degree 3 in . Note: After performing some tests and investigation we
came to conclusion that we can use degree 3 which will give us quite accurate results even
though affecting computational time significantly.
First we need to define the areas over which we would approximate the value function. The
selected grid G = {(a
i,b
j), 0 ≤ i ≤ p, 0 ≤ j ≤ p}
divides positive quadrant [0,∞)x[0,∞) into
(p+1)
2rectangles: R
ij={
: a
i≤
s <a
i+1and b
j≤
< b
j+1}
where 0=a
0<a
1<…<a
p<a
p+1=∞
and 0=b
0<b
1<…<b
p<b
p+1=∞.
From here on it is assumed that a
1= b
1and a
p= b
pTo construct necessary polynomials at each observation epoch we first need to calculate
approximation of w
mat each point of G. For this purpose it is necessary to have
approximation (denoted by
m+1) of the function w
m+1After obtaining approximation of w
m(a
i,b
j)
(denoted
m(a
i,b
j))
by at each point of G
m(a)
needs to interpolated with a piecewise polynomial along line s = a
i(0 ≤ i ≤ p)
and then (b)
interpolated linearly in s between lines s = a
iand s=a
i+1(1 ≤ i ≤ p-1).
(a) According to the note above we will use polynomial of degree 3 in for interpolation
therefore it was decided to use cubic spline interpolation in this case.
As a result and as a conclusion of previous paragraphs for 2 ≤ m ≤ n-2 and for each i
(1 i p) we need to find a cubic spline
satisfying
10
(b
j) =
m(a
i,b
j) (0 j p)
=>
( )
=
m(a
i,
)
At t
n-1we already have explicit definition of value function (see previous section), so
no approximation is needed. At t
1and t
0value function depends only on s, so only
linear interpolation in s will be needed.
(b) Then the approximation
mof w
mis defined by linear interpolation:
m
=
m+
mExplicit computation
Explicit computation of
m(a
i,b
j)
using available approximation
m+1could be done easily
due to change of variable
and the fact that
is expressed as an expectation
of a single variable (see (3) ).
After rearranging all terms
3we obtain:
(a
k, b
l) =
for k=0,…,p and l=0,…,q (4)
Where
((m-1)b
l+a
k)/m =
=
= e
rhΦ
– standard normal distribution
[ln( /
) - µh]/(σ
)
Since
= , this gives us an approximation of the value function in each point of the grid
m(a
k,b
l) = max (
(a
k, b
l), (
)
+) (5)
3
11
Interpolation and integration of all
m(a
k,b
l)
yields
m, which is used in the next iteration to
obtain
m-1(a
k,b
l)
and
m-1respectively.
The starting point will be to calculate
n-2(a
k,b
l)
since we have explicitly defined w
n-1(a
k,b
l)
(of course after the change of variable)
The interpolation and integration should be continued until m = 0 in order to obtain the value
function at initial time epoch. However since w
1and w
0depend only on s and only linear
interpolation in s is needed (see v
m/w
mnumerical solution section (a)), at m=1 and m=0 the
instead of (4) we will have
If m = 1
,
(a
k) =
(a
i, a
k)
If m = 0
,
(a
k) =
(a
i)
for k=0,…,p
After we obtained the approximation
0the option price
0(S(0)) can be calculated by
simply interpolating
0 .The values of
,
,
could be calculated before starting the backward iterations of (4)
Choice of Grid and Computation speed
Our reference paper suggests us to use the following grid G for our computations.
a
0= 0
a
1= S(0)exp( t
n-1-6
)
a
p-1= S(0)exp( t
n-1+5
)
a
p= S(0)exp( t
n-1+6
)
for 2 ≤ i ≤ p-2
a
iis a quantile of order (i-1)/(p-2) of the lognormal distribution with parameters t
n-1and
We take p = q and for 0 ≤ i ≤ p we have
b
i= a
iThe authors of reference paper admit that the choice is not optimal however it provides
relatively accurate results.
The paper also presents several proposals how to decrease computational time:
- If at some point m (≥m*)
(a
k, b
l) <
(a
k, b
l),
then for all j≥l
(a
k, b
j)>
(a
k,
bj)
and since optimal exercise strategy is applied, then there is no need in computing
holding value which will save time on integration and interpolation
- In case
m(a
k,b
l)
is less than some fixed threshold (authors in their research set it to
12
It was decided that none of these proposals will be employed in our study due to the fact that
we would like to put accuracy and simplicity of implementation before computational speed.
13
3. Users Manual
This section aims to present and explain the components of our applet. The two figures below
show the entire applet with its functionality.
The graphical user interface has been divided in two distinct parts; the top part contains the
controls that the algorithm need as inputs and the output section where the option price and
the graph will be presented.
Name
Symbol
Input Description
Stock Price
S
Initial price of the underlying stock
Volatility
σ
Annualized stock volatility in percentage terms
Maturity
T
Moment in time when the options expires. In years
n
n
Number of observation applied during the options lifespan
Strike Price
K
Price at which the owner of the options prepared to exercise
Interest Rate
r
Annualised risk free interest rate
m*
m*
Fist opportunity the investor is allowed to exercise the option
14
As seen in the previews figure, the controls have been equipped with tool tip texts that show
the user what values should be inputted and in which form and error handlers that correct
and alert the user on his mistakes.
Once all inputs are accepted the program will present the user with two pieces of information.
The first one is the option price whose meaning is quite self explanatory. The second is a
graph representing the optimal exercise strategy which indicates the observation dates and
whether the investor should hold the contract or exercise it. In the figure below we will see
that there are two distinctive colours red tells the investor to holding his position meanwhile
blue indicated exercising. A real handy feature one can use is the time scroll bar to view the
optimal exercise strategy at any observation time. Figure 3.1 shows the optimal exercise
strategy when n=1 and figure 3.2 when n=13.
Figure 3.1 Figure 3.2
The applet has also been given a section where the user can test the effect each variable has
over its option price. Once a variable is selected from the menu box and a range is entered,
the program will hold all other variables fixed and calculate the 10 option prices that will be
used to form the option price analysis graph.
15
4. Output Analysis
4.1 Variable Effect On Premium Prices
This section is meant to present the tests we put the program through in addition to showing
in a clear context the effects of the variables on the option price.
In order to perform such tests we took each variable assigned it a rage and ran the applet for
each point while keeping the other variables fixed. Below, each table indicates the values
inputted for each variable. The cells with a gray background are fixed meanwhile the white
ones indicate the range use in each simulation.
Since we are dealing with call options, the premium would be low while the initial stock
price (S
0) is under the strike price (K). When S
0is above or closer to K, the premium price
increases considerable because the contract has more chances of generating profit.
Figure 4.1.1
Stock Price
Strike Price
Maturity
Interest Rate
Volatility
n
m*
p
[90,110]
100
0.25
0.05
0.15
13
1
150
Stock Price
Strike Price
Maturity
Interest Rate
Volatility
n
m*
p
16
Changes in the level of K produce an inverse effect to changes in the S
0.Increasing the level
of K would require the stock price to rise significantly in order to be executable.
17
A longer contract would increase the premium drastically because the option would have to
cover the fluctuations of the underlying asset for a longer period of time. On top of that, a
longer time period would mean that the investor has the capability to exercise many more
times than another investor that holds a similar contract with a shorter time period. Hence, the
longer the time period the more expensive the premium will be.
Figure 4.1.3
The explanation of the interest rate effect on premium prices is not as intuitive as in the above
variables. When interest rates increase, an investor instead of buying the stock would choose
to pay higher call option premiums and invest the difference in capital that earns the new and
higher interest.
Figure 4.1.4
Stock Price
Strike Price
Maturity
Interest Rate
Volatility
n
m*
p
100
100
[1,52]
0.05
0.15
13
1
150
Stock Price
Strike Price
Maturity
Interest Rate
Volatility
n
m*
p
18
Volatility is our measure of risk. Higher levels of volatility in our asset imply riskier contacts.
Since the seller of the call option is paid to take the risk of the stock price moving beyond the
strike price; the higher the volatility the more expensive the option premium will become.
Figure 4.1.5
This value indicates the quantity of discrete observation points used during the option’s
lifespan. For instance, if maturity is 0.25 (13 weeks) and n=26 that would imply two
observations per week. Increasing n decreases the value of the option; which is consistent if
we take under consideration that the larger n becomes the more the average will flatten the
prices.
Figure 4.1.6
Stock Price
Strike Price
Maturity
Interest Rate
Volatility
n
m*
p
100
100
0.25
0.05
[0.05-1]
13
1
150
Stock Price
Strike Price
Maturity
Interest Rate
Volatility
n
m*
p
19
The variable m* is the earliest exercise opportunity. Below we notice that, the larger m* is
the less exercise opportunities the owner will have to exercise and as a consequence the
option price will turn out to be cheaper.
Figure 4.1.7
Accuracy in the calculation of the option premiums is what this variable stands for. A higher
p will wind up in better estimate of the option price. It is important to notice that the dramatic
difference in accuracy once we overpass p=100. A more detailed analysis is offered in section
4.3.
Figure 4.1.8
Stock Price
Strike Price
Maturity
Interest Rate
Volatility
n
m*
p
100
100
0.25
0.05
0.15
13
[1,15]
150
Stock Price
Strike Price
Maturity
Interest Rate
Volatility
n
m*
p
20
4.3 Accuracy, Computational Time & Convergence
We begin our accuracy analysis comparing our results to the ones found in the reference
paper. Table 4.3.1 shows the examples and results extracted from it as well as the outputs of
our applet. It is worth mentioning that all option prices are presented in the highest accuracy
recorded from both studies.
S T r σ n m* Time (Sec) Option Price Option Price d=1 Option Price d=2 d=1 d=2
100 0.25 0.05 0.15 13 1 51.624 2.32096 2.32084 2.32084 0.00012 0.00012
100 0.25 0.05 o.25 13 1 51.165 3.65028 3.65006 3.65006 0.00022 0.00022
100 0.5 0.05 o.25 13 1 52.061 5.3323 5.33203 5.33199 0.00027 0.00031
105 0.5 0.05 o.25 13 1 53.084 2.96594 2.96564 2.96563 0.0003 0.00031
Time(sec) Time (Sec)
2917 3075
Reference Paper p=2400 Our Results p=350
Examples Price Difference
Table 4.3.1
It can easily be understood that the last two columns show the difference between our results
and those of the other two approximation schemes, namely d=1 and d=2. Knowing that at
p=2400 the value is very precise and given that our results deviate at most 0.00031 from it,
we can be confident that the applet is outputting values with a high accuracy level.
Precision should always be our objective as long as the benefits of obtaining an accurate
measurement do no outweigh the problem of time consumption. Meanwhile the reference
study presents p=2400 and p=1200 running for more than 48 minutes and 6 minutes
respectively; our applet estimates the same examples in less than 54 seconds with the slight
deviation, in price mention, above.
To illustrate this further, we direct our attention to figure 4.3.2 which was plotted using table
A (see appendix). Here it can be observed that for p>100, accuracy becomes in the order of
three or more decimal places and for p<100 computational time remains under half a second.
As our plot exemplifies p=100 is the closest to the intersection between the time and
convergence curves.
21
5. Conclusion
Both of the objectives we set out to accomplish have been successfully fulfilled. Namely, the
applet turned out very clean and intuitive and it provides the user with the possibility to
choose either speed or accuracy. The optimal exercise strategy as well as the effect of the
change in variables can be seen graphically and our tests indicate they function properly.
While testing the program it was found that depending the level of accuracy selected our
program would generate results with negligible differences in accuracy for a fraction of the
time presented in the reference paper.
Also, we determined that when is p>100 the program delivers high accurate results mean
while p<100 gives results is less than half a second. So, for p slightly over 100 we receive the
most time-accuracy efficient combination.
22
6. References
Hatem Ben-Ameur., Michèle Breton., Pierre L’Ecuyer., A Dynamic Programming Procedure
for Pricing American-Style Asian Options
. Management Science 2002 INFORMS Vol. 48,
No. 5, May 2002 pages. 625–643.
Hull C. John. 2002. Option Futures and other Derivatives. Prentice Hall College Div. 5
thEdition. Pages .-443, 461, 700.
7. Appendix
Table A
350 50.851 2.320964 % Time increase respect Accuracy difference % Convergence increase p Time (sec) Option Price time at p=350 from p=350 per increase in p
25 0.023 2.349093 0.045 0.028129 22.879 50 0.144 2.327399 0.283 0.006435 9.732 75 0.468 2.323701 0.920 0.002737 5.230 100 1.095 2.322435 2.153 0.001471 3.201 125 2.158 2.321864 4.244 0.000900 2.060 150 3.725 2.321543 7.325 0.000579 1.390 175 6.013 2.321355 11.825 0.000391 0.937 200 8.996 2.321227 17.691 0.000263 0.654 225 13.072 2.321148 25.706 0.000184 0.437 250 18.387 2.321087 36.159 0.000123 0.275 275 24.183 2.321041 47.557 0.000077 0.166 300 32.653 2.321011 64.213 0.000047 0.070 325 41.562 2.320984 81.733 0.000020 0.001
23
P Tables
Tables p= 25 – p=125
n Time Option Price Time Option Price Time Option Price Time Option Price Time Option Price 2 27 2.43782733 23 2.435567567 37 2.435186942 63 2.435192495 88 2.435033281 3 5 2.623239215 13 2.619340453 25 2.618669759 44 2.618441125 62 2.618336986 4 13 2.519788986 24 2.51379029 73 2.51280069 148 2.51245319 260 2.512296829 5 10 2.461866315 34 2.453871225 105 2.452572767 245 2.452114795 457 2.451911622 6 11 2.425440351 49 2.416029338 166 2.414380791 350 2.413811841 666 2.413548825 7 11 2.400865172 62 2.390132078 195 2.388265872 455 2.387634138 871 2.387333842 8 14 2.384220552 83 2.371800883 241 2.369595543 570 2.36881691 1076 2.368463952 9 15 2.372514911 89 2.358185062 287 2.355552835 665 2.354687599 1319 2.354307126 10 17 2.363815633 103 2.347673096 335 2.344757552 765 2.343800232 1491 2.343357979 11 20 2.357430403 116 2.339343673 374 2.336251734 903 2.33516609 1727 2.334670327 12 21 2.35269572 129 2.332694075 422 2.329341762 978 2.328171111 1951 2.327643736 13 23 2.349092893 144 2.327399494 468 2.323701383 1095 2.322435268 2158 2.321864296 14 25 2.346475041 154 2.322960758 508 2.31901795 1223 2.317646229 2319 2.31701155 15 33 2.344573414 170 2.319345002 556 2.315051747 1289 2.313580644 2566 2.31289836 16 35 2.343304312 180 2.316282037 597 2.311701211 1433 2.310134588 2845 2.30940649 17 34 2.342539519 197 2.31369382 642 2.308829815 1543 2.307140326 2994 2.306381506 18 35 2.342107387 208 2.311517425 686 2.306346951 1627 2.304545889 3151 2.303753676 19 35 2.341938797 223 2.309650764 803 2.304184128 1748 2.302294893 3404 2.301432952 20 37 2.342106012 234 2.3080539 776 2.302286547 1822 2.300303076 3610 2.299390337 21 43 2.342460065 249 2.30668461 856 2.300620261 1959 2.298534783 3766 2.297581597 22 43 2.343072414 267 2.305523108 874 2.299151458 2095 2.296957597 4157 2.295958593 23 45 2.343848357 271 2.30452674 1018 2.297842043 2189 2.295557966 4178 2.294501597 24 45 2.344765903 294 2.303697079 976 2.296681962 3288 2.294300514 4442 2.29319672 25 46 2.345797037 397 2.3029651 1088 2.295647022 3356 2.293168147 4655 2.29201997 26 51 2.346987594 312 2.30235073 1067 2.294733277 3309 2.292135365 5015 2.290947451 27 50 2.348246475 326 2.301817299 1140 2.293909583 3000 2.291205078 5131 2.289968109 28 54 2.349588845 384 2.30137567 1199 2.293164783 2674 2.290364138 5235 2.289079678 29 55 2.351016435 366 2.301024928 1182 2.292494721 2965 2.289590017 5485 2.288264642 30 60 2.352506322 376 2.300729359 1264 2.291903298 3087 2.288888106 5717 2.287519627 31 59 2.354063994 383 2.300481875 1270 2.291368332 3643 2.288252302 5900 2.286832599 32 62 2.355702061 393 2.300301236 1361 2.290882865 3238 2.287662834 6124 2.286194155 33 64 2.357402769 440 2.300165802 1364 2.290450912 3256 2.287128542 6259 2.285609226 34 67 2.359121618 418 2.300076908 1448 2.290064066 3368 2.286633262 6541 2.285068034 35 65 2.360882478 431 2.300028722 1489 2.289715898 3440 2.286179599 6681 2.284567793 36 70 2.362682435 482 2.300008444 1579 2.289403364 3559 2.285760102 6937 2.284103198 37 75 2.364510355 457 2.300022405 1538 2.28912169 3693 2.285369995 7198 2.283672405 38 72 2.366380364 470 2.30006352 1618 2.288871154 3745 2.285016662 7380 2.283267604 39 74 2.368276871 483 2.300126006 1640 2.28864756 3879 2.284689088 7580 2.28289569 40 77 2.370197321 615 2.300217779 1713 2.288450289 4123 2.284387397 7703 2.282546799 41 76 2.372152481 514 2.300337049 1759 2.288280182 4107 2.284109825 7961 2.282220232 42 81 2.374123343 561 2.300485558 1774 2.288127151 4226 2.283853676 8144 2.281916653 43 84 2.376110577 539 2.300651202 1852 2.287996354 4269 2.283616724 8380 2.28163409 44 82 2.378123983 550 2.300827634 1904 2.287887291 4421 2.283400968 8736 2.281366597 p=25 p=50 p=75 p=100 p=125
24
Tables p= 150 – p=250
n Time Option Price Time Option Price Time Option Price Time Option Price Time Option Price
2 107 2.435094547 133 2.43505896 163 2.435050359 199 2.435054433 222 2.435025343 3 87 2.618280519 109 2.618246906 131 2.618224838 161 2.618210009 190 2.618199238 4 426 2.512211719 682 2.512162432 1022 2.512130201 1440 2.512107914 1983 2.512091678 5 788 2.451801742 1277 2.451733187 1903 2.451690062 3305 2.451659374 3790 2.451639046 6 1698 2.413414476 1930 2.413334507 2824 2.413280341 4075 2.413242406 5612 2.413216873 7 1546 2.387176923 2544 2.387079729 3673 2.387015412 5342 2.386972962 7403 2.38694193 8 1915 2.368273184 3611 2.368157029 4577 2.36808449 6581 2.368033476 9223 2.367999618 9 2247 2.354088874 3732 2.353966261 5465 2.353881684 7929 2.353824267 11080 2.353785551 10 2628 2.343121624 4306 2.342980983 6381 2.342884444 9274 2.342821491 12907 2.34277627 11 2992 2.33441038 5073 2.334250374 7199 2.334154157 10500 2.334083077 14531 2.334033068 12 3410 2.32735005 5499 2.32718194 8259 2.327070165 11796 2.326993603 16473 2.326940023 13 3725 2.321543459 6013 2.32135502 8996 2.321227442 13072 2.321147971 18387 2.321086918 14 4105 2.316670798 6782 2.316467679 10069 2.316339407 14416 2.316247479 20074 2.316184635 15 4456 2.312544725 7270 2.312331803 10749 2.312185849 15615 2.312094672 21715 2.312026907 16 4854 2.309027366 7882 2.30878879 11803 2.30864076 16976 2.308531515 23438 2.308456875 17 5310 2.305964679 8738 2.305721255 12511 2.305562677 18491 2.305451954 25326 2.305373043 18 5578 2.303314897 9081 2.303043141 13551 2.302870515 19615 2.302757252 27211 2.302674928 19 5945 2.300967042 9673 2.300688236 14539 2.300511885 20790 2.300385917 28885 2.300299059 20 6297 2.298902337 10264 2.298611225 15234 2.298416156 22150 2.298293531 30662 2.298197271 21 6701 2.297064477 10995 2.296760048 16258 2.296559945 23514 2.296422156 32467 2.29632503 22 7037 2.295418442 11424 2.295098437 16985 2.294887661 24972 2.29474588 34363 2.29464556 23 7424 2.293950119 12199 2.293610949 17930 2.293390136 25975 2.293238021 36192 2.293131458 24 7762 2.29261436 12821 2.292258436 18866 2.292030337 27605 2.291875829 38031 2.29176412 25 8061 2.291404871 13335 2.291037374 19624 2.290800491 28734 2.290635742 39907 2.290520018 26 8502 2.290306881 14017 2.289929155 20651 2.289678578 30292 2.289509898 41414 2.28938888 27 8839 2.289310919 14560 2.28890867 21486 2.288650313 31416 2.288475217 43219 2.288350268 28 9198 2.288391465 15055 2.28797794 22300 2.287713642 32607 2.28753125 44989 2.287399153 29 9575 2.287549971 15867 2.287124614 23277 2.286847789 33943 2.286656569 47157 2.286522209 30 9971 2.286774037 16451 2.286336818 24138 2.286047673 35246 2.285850987 49206 2.285711462 31 10251 2.286065818 16977 2.285605497 25001 2.285310894 36393 2.285109005 50876 2.284963706 32 10709 2.285405462 17648 2.284932597 26000 2.284628582 37761 2.284416669 52166 2.284266619 33 11104 2.284791968 18095 2.284307389 26803 2.283990528 39209 2.283773056 54225 2.28361971 34 11390 2.284226283 18788 2.283724611 27646 2.283399243 40568 2.283177004 55632 2.283018403 35 11772 2.283697852 19212 2.28318172 28572 2.282849268 41901 2.282618759 57727 2.282454353 36 12180 2.28320998 19859 2.282674986 29555 2.282334092 43347 2.282095733 59628 2.281926456 37 12578 2.282753733 20514 2.282203862 30431 2.2818504 44457 2.281607133 61515 2.281434621 38 12812 2.282325463 21164 2.281761618 31300 2.281397869 45816 2.281149146 62976 2.280970121 39 13320 2.281926323 21529 2.281344716 32124 2.280975823 47139 2.280717023 64908 2.280533186 40 13558 2.281551726 22245 2.28095524 33157 2.280576304 48399 2.28031145 66650 2.280123606 41 13992 2.281199708 22854 2.280587608 34125 2.28020027 49989 2.279929852 68831 2.279736208 42 14362 2.280872414 23499 2.280243727 34970 2.279845053 53082 2.279569572 70568 2.27936985 43 14646 2.280565166 24390 2.27992014 35849 2.279511047 52453 2.279227805 72678 2.279024277 44 15065 2.280273907 24676 2.279612997 36742 2.279197076 53571 2.278904756 74302 2.278697812 p=175 p=200 p=225 p=250 p=150
25
Tables p= 275 – p=350
n
Time
Option Price
Time Option Price
Time
Option Price
Time
Option Price
2
258
2.435044685
300
2.4350327
345
2.43503484
402
2.435035073
3
230
2.61819129
274
2.61818534
358
2.618180657
392
2.618176948
4
2662
2.512079731
3539
2.5120707
4737
2.512063615
5298
2.512058274
5
5112
2.451623127
7053
2.45161121
8478
2.451601463
10672
2.451594246
6
7547
2.4131978
10130
2.4131834
12460
2.413171793
15419
2.413162501
7
10067
2.38691835
14166
2.38690206
16442
2.386888487
20560
2.386877729
8
12448
2.367973249
16787
2.36795373
20522
2.367937464
25588
2.367925959
9
14882
2.353755228
20015
2.3537309
24441
2.353714406
30583
2.353700441
10
16938
2.342742721
23465
2.34271738
28555
2.342697777
35823
2.342682383
11
19501
2.33399347
26237
2.33396726
33612
2.333945175
40826
2.33392745
12
21788
2.326900697
29362
2.32686747
37704
2.326845754
45698
2.326825853
13
24183
2.32104123
32653
2.32101065
41562
2.320983747
50851
2.320964012
14
26693
2.316139676
35895
2.31610302
44789
2.316075695
55741
2.316052829
15
28896
2.311974627
39342
2.31193713
48645
2.311906396
61137
2.311882302
16
31177
2.308407962
42483
2.30836423
52909
2.308332595
66299
2.308307001
17
33600
2.305313044
45790
2.30527081
56902
2.305234966
70935
2.305207671
18
36112
2.30261253
48825
2.30256681
61407
2.302529515
76373
2.30250141
19
38467
2.30023557
52179
2.30018761
65418
2.300148676
81623
2.300116441
20
40783
2.298128495
55371
2.29807612
69651
2.298037281
86747
2.298005127
21
43139
2.296253427
58725
2.29619666
73733
2.296153951
91733
2.296120487
22
45681
2.294568452
62001
2.2945136
78002
2.294467318
96965
2.294431413
23
48010
2.29305288
65212
2.29299283
81852
2.292947603 102161
2.292910222
24
50469
2.291680194
68706
2.29161747
85915
2.291570468 107027
2.291531711
25
52910
2.290435388
71706
2.29037049
89418
2.290317721 112819
2.290279355
26
55407
2.28929802
74777
2.28922934
93950
2.289178411 117111
2.289134866
27
58040
2.288258692
78219
2.28818803
98101
2.288131167 122731
2.288089412
28
60519
2.287302011
81365
2.28722827
102401
2.287172797 126913
2.287126212
29
62737
2.286422298
84586
2.28634611
106612
2.286286153 131842
2.286240936
30
65373
2.285608168
88380
2.28553042
110334
2.285470115 137195
2.285420093
31
67544
2.284856701
91298
2.28477437
114226
2.284710664 141952
2.284662085
32
69831
2.284157046
94353
2.2840735
118756
2.284008322 148305
2.283955523
33
72672
2.283506327
97560
2.28341993
122568
2.283352834 152978
2.283300331
34
75278
2.282901149 100878 2.28281179
126394
2.282741546 158501
2.282686182
35
77414
2.282333912 104201
2.2822422
130691
2.282171189 163256
2.282114512
36
79496
2.281803518 107580 2.28170862
134169
2.281634854 168350
2.281577286
37
82621
2.281307579 111157 2.28121011
138619
2.281134302 173388
2.281073526
38
84604
2.280839323 113912 2.28073895
141941
2.280661883 178189
2.280600721
39
86496
2.280399531 117270 2.28029718
146708
2.280217249 182450
2.280154201
40
88557
2.279986648 120425 2.27988123
150539
2.279799276 187766
2.279734474
41
91235
2.279595694 123455 2.27948721
154836
2.279403327 192404
2.279337248
42
93412
2.279226052 127550 2.27911544
158576
2.279029198 197795
2.278961477
43
95753
2.278877684 130160 2.27876427
163124
2.278676523 203225
2.278606774
44
98244
2.278546971 133436 2.27843058
166593
2.278340425 208334
2.278269484
p=275
p=300
P=325
p=350
26
Source Code
AmerasianDynamic GUI
import java.awt.*; import javax.swing.*; import javax.swing.border.*; import java.awt.event.*; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Locale; import javax.swing.event.*; import org.jfree.chart.*; import org.jfree.chart.axis.*; import org.jfree.chart.plot.*; import org.jfree.data.xy.*; import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.renderer.xy.XYStepAreaRenderer;publicclass AmerasianDynamic extends JApplet implements ActionListener, FocusListener, ChangeListener{
//---Panels
private JPanel mainPanel = null; private JPanel inputPanel = null; private JPanel basicInputPanel = null; private JPanel controlsPanel = null; private JPanel outputPanel = null; private JPanel graphPanel = null;
private JPanel optimalExercisePanel = null; private JPanel buttonsPanel = null;
private JPanel intervalVariablePanel = null;
//---Tabs
private JTabbedPane tabbedPane;
//---Graph
private ChartPanel graphOuput = null;
private ChartPanel optimalExerciseGraph = null;
//--PrograssBar
private JProgressBar progressBar = null; private JProgressBar dummyBar = null; private JCheckBox showExerciseStrategy = null;
//---GUI Interval On Varible Panel
private JComboBox dimension = null;
//---GUI---Buttons
private JButton calculateButton = null; private JButton resetButton = null; private JButton drawGraphButton = null;
//---GUI---Text fields
private JTextField strikePriceField = null; private JTextField stockPriceField = null; private JTextField interestRateField = null; private JTextField volatilityField = null; private JTextField maturityField = null; private JTextField mStarField = null; private JTextField nField = null;
private JTextField OptionPriceField = null; private JTextField minField = null; private JTextField maxField = null;
//---GUI---Text Slider
private JSlider pSlider = null; private JSlider mSlider = null;
//---GUI---Default Values
final String defaultStockPrice = "100.0"; final String defaultStrikePrice = "100.0"; final String defaultInterestRate = "0.05"; final String defaultVolatility = "0.15";
27
final String defaultMaturity = "0.25"; final String default_mStar = "1"; final String default_n= "13";
final String default_intervalMaxInput = "110"; final String default_intervalMinInput = "90"; finalint default_p = 150;
privatefinal String exerciseStrategy = "Show exercise strategy";
privatefinal String[] possibleDimensions = {"Stock Price","Strike Price","Volatility","Interest Rate", "Maturity"};
//---Program Variables
double stockPrice, strikePrice, interestRate, volatility, maturity, h; int n,p, mStar;
double minDimension, maxDimension;
privatefinalint NUM_POINTS = 10; //Number of points for building a graph
privatefinaldouble percentageForGraph = 0.1; // plus minus 10% of dependend variable
privatedouble step = 0;
ValueFunctionW W = null;
publicvoid init () {
Container contentPane = getContentPane(); //---Create Main
mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel,BoxLayout.Y_AXIS)); contentPane.add(mainPanel);
//---Create input
inputPanel = new JPanel();
inputPanel.setLayout(new BoxLayout(inputPanel,BoxLayout.Y_AXIS)); mainPanel.add(inputPanel);
//---Create Basic Input
basicInputPanel = new JPanel (new GridLayout(0,4, 10,3)); basicInputPanel.setBorder(new TitledBorder("Input")); inputPanel.add(basicInputPanel);
//---Fill The Labels and Data Panels with Respective Objects
JLabel label = new JLabel("Stock price"); basicInputPanel.add(label);
stockPriceField = new JTextField(defaultStockPrice);
stockPriceField.setToolTipText("Stock Price: Initial price of the underlying stock"); stockPriceField.addFocusListener(this);
basicInputPanel.add(stockPriceField); label = new JLabel("Strike price"); basicInputPanel.add(label);
strikePriceField = new JTextField(defaultStrikePrice);
strikePriceField.setToolTipText("Strike Price: Price at which the owner of the options prepared to exercise"); strikePriceField.addFocusListener(this);
basicInputPanel.add(strikePriceField); label = new JLabel("Volatility"); basicInputPanel.add(label);
volatilityField = new JTextField(defaultVolatility);
volatilityField.setToolTipText("Volatility: Annualized stock volatility in percentage terms"); volatilityField.addFocusListener(this);
basicInputPanel.add(volatilityField); label = new JLabel("Interest Rate"); basicInputPanel.add(label);
interestRateField = new JTextField(defaultInterestRate);
interestRateField.setToolTipText("Interest Rate: Annualised risk free interest rate"); interestRateField.addFocusListener(this);
basicInputPanel.add(interestRateField); label = new JLabel("Maturity"); basicInputPanel.add(label);
28
maturityField.setToolTipText("Maturity: Moment in time when the options expires. In years"); maturityField.addFocusListener(this);
basicInputPanel.add(maturityField); label = new JLabel("m*");
basicInputPanel.add(label);
mStarField = new JTextField(default_mStar);
mStarField.setToolTipText("m*: Fist opportunity the investor is allowed to exercise the option"); mStarField.addFocusListener(this);
basicInputPanel.add(mStarField); label = new JLabel("n"); basicInputPanel.add(label); nField = new JTextField(default_n);
nField.setToolTipText("n: Number of observation applied during the options lifespan"); nField.addFocusListener(this);
basicInputPanel.add(nField); controlsPanel = new JPanel();
controlsPanel.setLayout(new GridLayout(1,2, 50,0)); controlsPanel.setBorder(new TitledBorder("")); inputPanel.add(controlsPanel);
//---Slider for choosong accuracy
pSlider = new JSlider(JSlider.HORIZONTAL, 50, 350, default_p); pSlider.setMajorTickSpacing(100); pSlider.setMinorTickSpacing(50); pSlider.setPaintTicks(true); pSlider.setPaintLabels(true); pSlider.setSnapToTicks(true); pSlider.setBorder(BorderFactory.createTitledBorder("Accuracy (p)")); Font font = new Font("Arial", Font.PLAIN, 12);
pSlider.setFont(font); controlsPanel.add(pSlider);
//---CheckBox for Optimal Exercise Strategy
showExerciseStrategy = new JCheckBox(exerciseStrategy, true); controlsPanel.add(showExerciseStrategy);
//---Create Buttons
buttonsPanel = new JPanel();
buttonsPanel.setLayout(new GridLayout(1,2,10,0)); inputPanel.add(buttonsPanel);
calculateButton = new JButton("Calculate"); buttonsPanel.add(calculateButton);
calculateButton.addActionListener(this); resetButton = new JButton("Reset"); buttonsPanel.add(resetButton); resetButton.addActionListener(this); //---Create progress bar
GridBagConstraints c = new GridBagConstraints(); progressBar = new JProgressBar();
progressBar.setBorder(BorderFactory.createLoweredBevelBorder()); progressBar.setStringPainted(true); progressBar.setValue(0); progressBar.setIndeterminate(false); c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 3; mainPanel.add(progressBar,c);
//---Create Ouput panel
29
outputPanel.setLayout(new BoxLayout(outputPanel,BoxLayout.Y_AXIS)); outputPanel.setBorder(new TitledBorder(""));
mainPanel.add(outputPanel);
//---Fill The Output Panels with Respective Objects
label = new JLabel("Option Price", JLabel.CENTER); label.setFont(new Font("Arial", Font.BOLD, 16)); outputPanel.add(label);
OptionPriceField = new JTextField("");
OptionPriceField.setHorizontalAlignment(JTextField.CENTER); OptionPriceField.setFont(new Font("Arial", Font.BOLD, 16)); OptionPriceField.setEnabled(false);
outputPanel.add(OptionPriceField);
OptionPriceField.setDisabledTextColor(Color.BLACK);
//---Create The Tabs
JTabbedPane tabbedPane = new JTabbedPane();
JPanel card1 = new JPanel();
card1.setLayout(new BoxLayout(card1,BoxLayout.Y_AXIS)); tabbedPane.addTab("Optimal Exercise Strategy", card1);
JPanel card2 = new JPanel();
card2.setLayout(new BoxLayout(card2,BoxLayout.Y_AXIS)); tabbedPane.addTab("Option Price", card2);
mainPanel.add(tabbedPane); optimalExercisePanel = new JPanel();
optimalExercisePanel.setLayout(new BoxLayout(optimalExercisePanel,BoxLayout.Y_AXIS)); card1.add(optimalExercisePanel);
optimalExerciseGraph = new ChartPanel(null); optimalExercisePanel.add(optimalExerciseGraph);
graphPanel = new JPanel();
graphPanel.setBorder(new TitledBorder(""));
graphPanel.setLayout(new BoxLayout(graphPanel,BoxLayout.Y_AXIS)); card2.add(graphPanel);
intervalVariablePanel = new JPanel(); graphPanel.add(intervalVariablePanel);
drawGraphButton = new JButton("Draw Graph"); intervalVariablePanel.add(drawGraphButton); drawGraphButton.addActionListener(this);
label = new JLabel(" "); intervalVariablePanel.add(label);
dimension = new JComboBox(possibleDimensions); dimension.setSelectedIndex(0);
intervalVariablePanel.add(dimension); dimension.addActionListener(this);
label = new JLabel("Min Value "); intervalVariablePanel.add(label);
minField = new JTextField(default_intervalMinInput,5); minField.setToolTipText("Interval Min Input*:..."); minField.addFocusListener(this);
intervalVariablePanel.add(minField); label = new JLabel("Max Value "); intervalVariablePanel.add(label);
30
maxField.setToolTipText("Interval Max Input*:..."); maxField.addFocusListener(this);
intervalVariablePanel.add(maxField); graphOuput = new ChartPanel(null); graphPanel.add(graphOuput); stockPrice = Double.parseDouble(stockPriceField.getText()); strikePrice = Double.parseDouble(strikePriceField.getText()); maturity = Double.parseDouble(maturityField.getText()); interestRate = Double.parseDouble(interestRateField.getText()); volatility = Double.parseDouble(volatilityField.getText()); n = Integer.parseInt(nField.getText()); mStar = Integer.parseInt(mStarField.getText()); minDimension = Double.parseDouble(minField.getText()); maxDimension = Double.parseDouble(maxField.getText()); mSlider = new JSlider();
}
publicvoid actionPerformed(ActionEvent e){ Object src=e.getSource(); if (src == calculateButton){ stockPrice = Double.parseDouble(stockPriceField.getText()); strikePrice =Double.parseDouble(strikePriceField.getText()); maturity=Double.parseDouble(maturityField.getText()); interestRate=Double.parseDouble(interestRateField.getText()); volatility=Double.parseDouble(volatilityField.getText()); p=pSlider.getValue(); n =Integer.parseInt(nField.getText()); mStar=Integer.parseInt(mStarField.getText()); h = maturity/n;
W = new ValueFunctionW(stockPrice,strikePrice,maturity,interestRate,volatility, n, h, mStar, p, progressBar);
DecimalFormat myFormat = new DecimalFormat("###,###.#####"); OptionPriceField.setText(myFormat.format(W.result)); if (showExerciseStrategy.isSelected()){ mSlider.setOrientation(JSlider.HORIZONTAL); mSlider.setMaximum(n-1); mSlider.setMinimum(mStar); mSlider.setValue(mStar); mSlider.setPaintLabels(true); mSlider.setMajorTickSpacing(1); mSlider.setPaintTicks(true); mSlider.setSnapToTicks(true); mSlider.setBorder(BorderFactory.createTitledBorder("Time")); mSlider.setFont(new Font("Arial", Font.PLAIN, 10));
optimalExercisePanel.add(mSlider); mSlider.setVisible(true);
optimalExercisePanel.validate(); optimalExercisePanel.repaint();
31
mSlider.addChangeListener(this); optimalExerciseGraph.setChart(drawOptimalExercise(mSlider.getValue())); optimalExerciseGraph.setVisible(true); } } if (src == resetButton) { stockPriceField.setText(defaultStockPrice); strikePriceField.setText(defaultStrikePrice); maturityField.setText(defaultMaturity); interestRateField.setText(defaultInterestRate); volatilityField.setText(defaultVolatility); pSlider.setValue(default_p); nField.setText(default_n); mStarField.setText(default_mStar); OptionPriceField.setText(""); graphOuput.setChart(null); dimension.setSelectedIndex(0); optimalExerciseGraph.setVisible(false); mSlider.setVisible(false); } if (src == drawGraphButton) {String selection = (String)dimension.getSelectedItem() ; stockPrice = Double.parseDouble(stockPriceField.getText()); strikePrice =Double.parseDouble(strikePriceField.getText()); maturity=Double.parseDouble(maturityField.getText()); interestRate=Double.parseDouble(interestRateField.getText()); volatility=Double.parseDouble(volatilityField.getText()); p=pSlider.getValue(); n =Integer.parseInt(nField.getText()); mStar=Integer.parseInt(mStarField.getText()); h = maturity/n; minDimension = Double.parseDouble(minField.getText()); maxDimension = Double.parseDouble(maxField.getText());
XYSeries series = new XYSeries("Option Price");
double x=minDimension;
step = (maxDimension-minDimension)/(NUM_POINTS-1); double minResult = Double.POSITIVE_INFINITY; double maxResult = Double.NEGATIVE_INFINITY; dummyBar = new JProgressBar();
progressBar.setMinimum(0); progressBar.setMaximum(NUM_POINTS); progressBar.setIndeterminate(false); progressBar.setValue(0);
for (int i=0;i<NUM_POINTS;i++){
double y = 0;
if (selection == "Stock Price")
32
if (selection == "Strike Price")
{y = new ValueFunctionW(stockPrice,x,maturity,interestRate,volatility, n, h, mStar, p, dummyBar).result;} if (selection == "Maturity")
{y = new ValueFunctionW(stockPrice,strikePrice,x,interestRate,volatility, n, /*!!!*/x/n, mStar, p, dummyBar).result;}
if (selection == "Interest Rate")
{y = new ValueFunctionW(stockPrice,strikePrice,maturity,x,volatility, n, h, mStar, p, dummyBar).result;} if (selection == "Volatility")
{y = new ValueFunctionW(stockPrice,strikePrice,maturity,interestRate,x, n, h, mStar, p, dummyBar).result;}
if (y < minResult) {minResult = y;} if (y > maxResult) {maxResult = y;} x=x+step; series.add(x,y); int v = progressBar.getValue(); progressBar.setValue(v+1); progressBar.paint(progressBar.getGraphics()); }
XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series);
JFreeChart chart = ChartFactory.createXYLineChart( "Option Price Analysis", // Title
selection, // x-axis Label
"Option Price", // y-axis Label
dataset, // Dataset
PlotOrientation.VERTICAL, // Plot Orientation
true, // Show Legend
true, // Use tooltips
false// Configure chart to generate URLs?
);
XYPlot plot = chart.getXYPlot();
ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(minResult, maxResult); graphOuput.setChart(chart); graphOuput.setVisible(true); } if (src == dimension) {
String selection = (String)dimension.getSelectedItem() ;
if (selection == "Stock Price")
{ minDimension = stockPrice*(1-percentageForGraph); maxDimension = stockPrice*(1+percentageForGraph);
minField.setText(doubleToString(minDimension)); maxField.setText(doubleToString(maxDimension));}
if (selection == "Strike Price") {
minDimension = strikePrice*(1-percentageForGraph); maxDimension = strikePrice*(1+percentageForGraph);
minField.setText(doubleToString(minDimension)); maxField.setText(doubleToString(maxDimension));}
33
{ minDimension = volatility*(1-percentageForGraph); maxDimension = volatility*(1+percentageForGraph);
minField.setText(doubleToString(minDimension)); maxField.setText(doubleToString(maxDimension));}
if (selection == "Maturity")
{ minDimension = maturity*(1-percentageForGraph); maxDimension = maturity*(1+percentageForGraph);
minField.setText(doubleToString(minDimension)); maxField.setText(doubleToString(maxDimension));}
if (selection == "Interest Rate") {
minDimension = interestRate*(1-percentageForGraph); maxDimension = interestRate*(1+percentageForGraph); minField.setText(doubleToString(minDimension)); maxField.setText(doubleToString(maxDimension));} } }
publicvoid stateChanged(ChangeEvent e){ Object src = e.getSource(); if (src == mSlider){ optimalExerciseGraph.setChart(drawOptimalExercise(mSlider.getValue()) ); optimalExerciseGraph.setVisible(true); } }
JFreeChart drawOptimalExercise (int stateM) {
XYSeries series1 = new XYSeries("Exercise"); XYSeries series2 = new XYSeries("Hold"); for (int i = 2; i<=p-2; i++)
{ for (int j = 2; j<=p-2; j++){ if (W.optimalExerciseStrategy[stateM][i][j] == 0) {series1.add(W.a.Values[i],W.b.Values[j]);} if (W.optimalExerciseStrategy[stateM][i][j] == 1) {series2.add(W.a.Values[i],W.b.Values[j]);} } }
XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series2); dataset.addSeries(series1);
JFreeChart chart = ChartFactory.createXYLineChart( "Optimal Exercise Strategy",
"Stock Price", "Average Stock Price", dataset, PlotOrientation.VERTICAL, true, true, false );
34
XYPlot plot = (XYPlot) chart.getPlot();
XYStepAreaRenderer renderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
renderer.setDefaultEntityRadius(1);
ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setRange(W.b.Values[2], W.b.Values[p-2]); plot.setRenderer(renderer); return chart; }//End of drawOptimalExercise publicvoid focusGained(FocusEvent e) { Object src = e.getSource();
}
publicvoid focusLost(FocusEvent e) { Object src = e.getSource();
String selection = (String)dimension.getSelectedItem() ;
if (src == stockPriceField) {
stockPrice = readPositive(stockPriceField, stockPrice, stockPriceField.getToolTipText());
if (selection == "Stock Price") {
minDimension = stockPrice*(1-percentageForGraph); maxDimension = stockPrice*(1+percentageForGraph); minField.setText(doubleToString(minDimension)); maxField.setText(doubleToString(maxDimension)); }
return; }
if (src == strikePriceField) {
strikePrice = readPositive(strikePriceField, strikePrice, strikePriceField.getToolTipText());
if (selection == "Strike price") {
minDimension = strikePrice*(1-percentageForGraph); maxDimension = strikePrice*(1+percentageForGraph); minField.setText(doubleToString(minDimension)); maxField.setText(doubleToString(maxDimension)); }
return; }
if (src == maturityField) {
maturity = readPositive(maturityField, maturity, maturityField.getToolTipText());
if (selection == "Maturity") {
minDimension = maturity*(1-percentageForGraph); maxDimension = maturity*(1+percentageForGraph); minField.setText(doubleToString(minDimension)); maxField.setText(doubleToString(maxDimension)); }
return; }
if (src == volatilityField) {
volatility = readPositive(volatilityField, volatility, volatilityField.getToolTipText());
if (selection == "Volatility") {
minDimension = volatility*(1-percentageForGraph); maxDimension = volatility*(1+percentageForGraph); minField.setText(doubleToString(minDimension)); maxField.setText(doubleToString(maxDimension)); } return; } if (src == interestRateField) {
interestRate = readPositive(interestRateField , interestRate, interestRateField.getToolTipText());