Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Installing package "SpreadOption`"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35699] RE: [mg35673] Installing package "SpreadOption`"
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 26 Jul 2002 04:16:50 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello Matthias,

I downloaded the SpreadOptions package and modified it so that it will work
like a standard package. The package file is attached. (Other readers can
modify the package as I describe below.)

To use it, create a new Finance folder in ExtraPackages. Put the
SpreadOption.m file there. Then you can simply load the package with:

Needs["Finance`SpreadOption`"]

All I did was change the name of the package in the BeginPackage statement
to "Finance`SpreadOption". Anyone can do this by editing the package file.

This, it seems to me, is the method that should be used for third party
packages. If this method is used, the packages behave just like standard
packages. However, probably because it is not clearly presented in the WRI
documentation, very few people use the method. The result is a lot of
confusion in connecting to packages. Also, it seems to me that packages
should be in a standard place and the StandardPackages and ExtraPackges
folders that WRI provides are those places.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: Matthias.Bode at oppenheim.de [mailto:Matthias.Bode at oppenheim.de]
To: mathgroup at smc.vnet.net


Dear Colleagues,

I successfully installed Packages by David Park in the past; now I got the
package SpreadOption from Mathsource. I put SpreadOption.m in a directory
after appending the appropriate path. So it should work. But I get:

 <<...OLE_Obj...>>
 <<...OLE_Obj...>>
What has to be done?

Best regards,
Matthias Bode
Sal. Oppenheim jr. & Cie. KGaA
Koenigsberger Strasse 29
D-60487 Frankfurt am Main
GERMANY
Tel.: +49(0)69 71 34 53 80
Mobile: +49(0)172 6 74 95 77
Fax: +49(0)69 71 34 95 380
E-mail: matthias.bode at oppenheim.de
Internet: http://www.oppenheim.de



	filename="SpreadOption.m"


(* :Title: Spread Option Pricing Model *)

(* :Author: Espen Gaarder Haug *)

(* :Summary:

    Calculates the value
    for European call and put options on the difference between two utures
    contracts, better known as spread options.*)

(* :Context: SpreadOption` *)

(* :Package Version: 1.0, Last modified June 6, 1999 *)

(* :Copyright: Copyright (c) 1999 Espen Gaarder Haug *)

(* :Keywords:
option pricing, spread option, financial derivatives, crack spread options,
spark spread options.
*)

(* :Mathematica Versions 3.0  *)

BeginPackage["Finance`SpreadOption`"]

(* Usage Statments and Description *)

SpreadOption::usage =
"The SpreadOption package implemented by Espen Gaarder Haug
(the author of 'The  Complete Guide to Option Pricing Formulas') can be
used for valuation and sensitivity  analysis of European spread options
on futures and forward contracts.

Functions included are:
SpreadOption calculates the spread option value, SpreadOptionDelta1 and
SpreadOptionDelta2 calculates the Delta values, SpreadOptionGamma1 and
SpreadOptionGamma2 calculates the Gamma values, SpreadOptionVega1 and
SpreadOptionVega2 calculates the Vega values, SpreadOptionTheta
calculates the Theta value, SpreadOptionRho calculates the Rho values, and
SpreadOptionCor calculates the sensitivity for changes in the
correaltion coeficient,

A call spread option on two futures contracts will at maturity pay
Max[F1-F2-X,0], where F1 is the price of future one at maturity,
and F2 is  the price of future two at maturity, X is the strike price.
Similarly the payoff from a put spread option is Max[X-F1+F2,0].
Spread options are popular in many markets, and especially in the
energy markets. At New York Mercantile Exchange spread options are
traded on the spread/difference between heating oil and crude oil, as well
as between gasoline and crude oil. These are better known as crack spread options.
With the deregulation of the electricity/power markets around the world,
hedgers and risk takers are now also doing options on the price difference
between oil and electricity. In the energy market such options
are known as spark spread options.

The valuation formula here assumes a Black-Scholes world, that is the future
price follows a geometric Brownian motion (the future prices are
Log-normal distributed etc.). Since the option is on two future contracts,
that means two correlated geometric Brownian motions.

The implementation is based on the formula published by: Kirk, E. 1995:
'Correlation in the Energy  Markets,' in Managing Energy Price Risk. London:
Risk Publications and Enron, 71-78. This is actually an approximation, but
it is very accurate with respect to all practical purposes. More information
on valuation of both European and American style spread options can be found
in: Haug, E. G. 1997: 'The Complete Guide To Option Pricing  Formulas,'
McGraw-Hill, New York. "


SpreadOptionDelta1::usage =
"SpreadOptionDelta1[CPFlag, F1, F2, X, T, r, v1, v2, rho] calculates the 
delta-one for a European spread option. That is the the change in option 
\
value for
a small change in future contract one (F1).
CPFLag=1 for call option, -1 for put option.
A call spread option on two futures contracts will at maturity pay
Max[F1-F2-X,0], where F1 is the price of future one at maturity, and F2 is
the price of future two at maturity, X is the strike price. Similarly the \
payoff from a put spread option is Max[X-F1+F2,0]. T=time to maturity in years,
r=risk-free interest rate, v1=volatility of future contract one,
v2=volatility of future contract two, rho=correlation between the
return of the two futures contracts"

SpreadOptionDelta2::usage =
"SpreadOptionDelta2[CPFlag, F1, F2, X, T, r, v1, v2, rho] calculates the 
delta-two for a European spread option. That is the change in option value \
for a small change in future contract two (F2).
CPFLag=1 for call option, -1 for put option.
A call spread option on two futures contracts will at maturity pay
Max[F1-F2-X,0], where F1 is the price of future one at maturity, and F2 is
the price of future two at maturity, X is the strike price. Similarly the \
payoff from a put spread option is Max[X-F1+F2,0]. T=time to maturity in  years,
r=risk-free interest rate, v1=volatility of future contract one,
v2=volatility of future contract two, rho=correlation between the
return of the two futures contracts"

SpreadOptionGamma1::usage =
"SpreadOptionGamma1[ F1, F2, X, T, r, v1, v2, rho] calculates the
Gamma-one for a European spread option. That is the second derivatives of the
option value with respect to future contract one (F1).
Same for call and put.
A call spread option on two futures contracts will at maturity pay
Max[F1-F2-X,0], where F1 is the price of future one at maturity, and F2 is
the price of future two at maturity, X is the strike price. Similarly the \
payoff from a put spread option is Max[X-F1+F2,0]. T=time to maturity in 
years,
r=risk-free interest rate, v1=volatility of future contract one,
v2=volatility of future contract two, rho=correlation between the
return of the two futures contracts"

SpreadOptionGamma2::usage =
"SpreadOptionGamma2[ F1, F2, X, T, r, v1, v2, rho] calculates the
Gamma-two for a European spread option. That is the second derivatives of the
option value with respect to future contract two (F2).
Same for call and put.
A call spread option on two futures contracts will at maturity pay
Max[F1-F2-X,0], where F1 is the price of future one at maturity, and F2 is
the price of future two at maturity, X is the strike price. Similarly the \
payoff from a put spread option is Max[X-F1+F2,0]. T=time to maturity in years,
r=risk-free interest rate, v1=volatility of future contract one,
v2=volatility of future contract two, rho=correlation between the
return of the two futures contracts"

SpreadOptionVega1::usage =
"SpreadOptionVega1[ F1, F2, X, T, r, v1, v2, rho] calculates the
Vega-one for a European spread option. That is the first derivatives of the
option value with respect to the volatility of futures contract one (v1).
The Vega number have been divided by 100 to get it for percent point 
changes
(the practical market 'standard').
Same for call and put.
A call spread option on two futures contracts will at maturity pay
Max[F1-F2-X,0], where F1 is the price of future one at maturity, and F2 is
the price of future two at maturity, X is the strike price. Similarly the \
payoff from a put spread option is Max[X-F1+F2,0]. T=time to maturity in 
years,
r=risk-free interest rate, v1=volatility of future contract one,
v2=volatility of future contract two, rho=correlation between the
return of the two futures contracts"

SpreadOptionVega2::usage =
"SpreadOptionVega2[ F1, F2, X, T, r, v1, v2, rho] calculates the
Vega-two for a European spread option. That is the first derivatives of the
option value with respect to the volatility of futures contract two (v2).
The Vega number have been divided by 100 to get it for percent point changes
(the practical market 'standard').
Same for call and put.
A call spread option on two futures contracts will at maturity pay
Max[F1-F2-X,0], where F1 is the price of future one at maturity, and F2 is
the price of future two at maturity, X is the strike price. Similarly the \
payoff from a put spread option is Max[X-F1+F2,0]. T=time to maturity in years,
r=risk-free interest rate, v1=volatility of future contract one,
v2=volatility of future contract two, rho=correlation between the
return of the two futures contracts"

SpreadOptionTheta::usage =
"SpreadOptionTheta[CPFlag, F1, F2, X, T, r, v1, v2, rho] calculates the
Theta value for a European spread option. That is partial derivatives of 
the \
option value
with respect to time to expiration (T).
The Theta number have been divided by 365 to get it on a daily basis. I have \
also taken the minus value of the partial derivatives. This because we always get \
closer to expiration, time moves in one direction. That is the theta value that comes \
out is a approximation for what will happen with the option value as you get one day \
closer to maturity (the market 'standard').
CPFLag=1 for call option, -1 for put option.
A call spread option on two futures contracts will at maturity pay
Max[F1-F2-X,0], where F1 is the price of future one at maturity, and F2 is
the price of future two at maturity, X is the strike price. Similarly the \
payoff from a put spread option is Max[X-F1+F2,0]. T=time to maturity in years,
r=risk-free interest rate, v1=volatility of future contract one,
v2=volatility of future contract two, rho=correlation between the
return of the two futures contracts"


SpreadOptionRho::usage =
"SpreadOptionRho[CPFlag, F1, F2, X, T, r, v1, v2, rho] calculates the
Rho value for a European spread option. That is partial derivatives of the \
option value
with respect to the risk-free interest rate (r).
The Rho number have been divided by 100 to get it for percent point changes
(the market standard).
CPFLag=1 for call option, -1 for put option.
A call spread option on two futures contracts will at maturity pay off
Max[F1-F2-X,0], where F1 is the price of future one at maturity, and F2 is
the price of future two at maturity, X is the strike price. Similarly the \
payoff from a put spread option is Max[X-F1+F2,0]. T=time to maturity in years,
r=risk-free interest rate, v1=volatility of future contract one,
v2=volatility of future contract two, rho=correlation between the
return of the two futures contracts"


SpreadOptionCor::usage =
"SpreadOptionCor[F1, F2, X, T, r, v1, v2, rho] calculates the
the first derivatives of the option value with respect to the correaltion
coefficient (Rho). The partial derivatives have then been divided by 10 to
get it for a 0.1 change in correlation.
Same for call and put.
A call spread option on two futures contracts will at maturity pay off
Max[F1-F2-X,0], where F1 is the price of future one at maturity, and F2 is
the price of future two at maturity, X is the strike price. Similarly the \
payoff from a put spread option is Max[X-F1+F2,0]. T=time to maturity in years,
r=risk-free interest rate, v1=volatility of future contract one,
v2=volatility of future contract two, rho=correlation between the
return of the two futures contracts"


Begin["`Private`"]

cnd[z_] := (1 + Erf[z / Sqrt[2]]) / 2;

vv[F1_,F2_,X_,v1_,v2_,rho_]:=Sqrt[v1^2+(v2*F2/(F2+X))^2-2*rho*v1*v2*F2/
(F2+X)];

d1[F_,T_,r_,vv_]:=(Log[F]+vv^2/2*T)/(vv*Sqrt[T]);

d2[F_,T_,r_,vv_]:= (Log[F]-vv^2/2*T)/(vv*Sqrt[T]);

SpreadOption[CPFlag_,F1_,F2_,X_,T_,r_,v1_,v2_,rho_]:=
  CPFlag*(F2+X)* \
Exp[-r*T]*(F1/(F2+X)*cnd[CPFlag*d1[F1/(F2+X),T,r,vv[F1,F2,X,v1,v2,rho]]]-

        cnd[CPFlag*d2[F1/(F2+X),T,r,vv[F1,F2,X,v1,v2,rho]]]);

SpreadOptionDelta1[CPFlag_,F1_,F2_,X_,T_,r_,v1_,v2_,rho_]=
Evaluate[D[SpreadOption[CPFlag,F1,F2,X,T,r,v1,v2,rho], F1]];

SpreadOptionDelta2[CPFlag_,F1_,F2_,X_,T_,r_,v1_,v2_,rho_]=
Evaluate[D[SpreadOption[CPFlag,F1,F2,X,T,r,v1,v2,rho], F2]];

SpreadOptionGamma1[F1_,F2_,X_,T_,r_,v1_,v2_,rho_]=
Evaluate[D[SpreadOption[1,F1,F2,X,T,r,v1,v2,rho], {F1,2}]];

SpreadOptionGamma2[F1_,F2_,X_,T_,r_,v1_,v2_,rho_]=
Evaluate[D[SpreadOption[1,F1,F2,X,T,r,v1,v2,rho], {F2,2}]];

SpreadOptionVega1[F1_,F2_,X_,T_,r_,v1_,v2_,rho_]=
Evaluate[D[SpreadOption[1,F1,F2,X,T,r,v1,v2,rho], v1]/100];

SpreadOptionVega2[F1_,F2_,X_,T_,r_,v1_,v2_,rho_]=
Evaluate[D[SpreadOption[1,F1,F2,X,T,r,v1,v2,rho], v2]/100];

SpreadOptionTheta[CPFlag_,F1_,F2_,X_,T_,r_,v1_,v2_,rho_]=Evaluate[
-D[SpreadOption[CPFlag,F1,F2,X,T,r,v1,v2,rho], T]/365];

SpreadOptionRho[CPFlag_,F1_,F2_,X_,T_,r_,v1_,v2_,rho_]=
Evaluate[D[SpreadOption[CPFlag,F1,F2,X,T,r,v1,v2,rho], r]/100];

SpreadOptionCor[F1_,F2_,X_,T_,r_,v1_,v2_,rho_]=
Evaluate[D[SpreadOption[1,F1,F2,X,T,r,v1,v2,rho], rho]/100];


End[]

EndPackage[]


  • Prev by Date: RE: Re: Substitution!!!
  • Next by Date: Is there some free package for control system in mathematica
  • Previous by thread: Installing package "SpreadOption`"
  • Next by thread: Removing the Context