Option Pricing Module - Some Tests


In [1]:
#!wget https://raw.githubusercontent.com/oditorium/blog/master/Modules/OptionPricing.py -O OptionPricing.py

In [2]:
import OptionPricing as op

In [3]:
#help(op)

In [4]:
c = op.BSCall(mat=1, strike=100, spot=100, sig=0.2, rate=0.05, yld=0.)
p = op.BSPut(mat=1, strike=100, spot=100, sig=0.2, rate=0.05, yld=0.)
dc = op.BSDCall(mat=1, strike=100, spot=100, sig=0.2, rate=0.05, yld=0.)
dp = op.BSDPut(mat=1, strike=100, spot=100, sig=0.2, rate=0.05, yld=0.)
o = p
spot = range(60,140)

Present Value


In [5]:
plot(spot, list((o.PV(spot=s),o.PV(spot=s, sig=0.05)) for s in spot))


Out[5]:
[<matplotlib.lines.Line2D at 0x7f8a50eadcc0>,
 <matplotlib.lines.Line2D at 0x7f8a50eb4080>]

Delta and Cash Delta


In [6]:
plot(spot, list((o.Delta(spot=s),o.Delta(spot=s, sig=0.1)) for s in spot))


Out[6]:
[<matplotlib.lines.Line2D at 0x7f8a50d19518>,
 <matplotlib.lines.Line2D at 0x7f8a50d19898>]

In [7]:
plot(spot, list((100.*o.Delta(spot=s),o.DeltaCash(spot=s)) for s in spot))


Out[7]:
[<matplotlib.lines.Line2D at 0x7f8a50cfba58>,
 <matplotlib.lines.Line2D at 0x7f8a50cfbdd8>]

In [8]:
plot(spot, list((o.Delta(spot=s),o.DeltaFwd(fwd=s)) for s in spot))


Out[8]:
[<matplotlib.lines.Line2D at 0x7f8a50c5d630>,
 <matplotlib.lines.Line2D at 0x7f8a50c5d9b0>]

In [9]:
plot(spot, list((o.DeltaCash(spot=s),o.DeltaFwdCash(fwd=s)) for s in spot))


Out[9]:
[<matplotlib.lines.Line2D at 0x7f8a50c3d320>,
 <matplotlib.lines.Line2D at 0x7f8a50c3d6a0>]

Gamma and Cash Gamma


In [10]:
plot(spot, list((o.Gamma(spot=s),o.Gamma(spot=s, sig=0.1)) for s in spot))


Out[10]:
[<matplotlib.lines.Line2D at 0x7f8a50ba10b8>,
 <matplotlib.lines.Line2D at 0x7f8a50ba1438>]

In [11]:
plot(spot, list((10000*o.Gamma(spot=s),o.GammaCash(spot=s)) for s in spot))


Out[11]:
[<matplotlib.lines.Line2D at 0x7f8a50b09278>,
 <matplotlib.lines.Line2D at 0x7f8a50b095f8>]

Theta (and Gamma)


In [12]:
plot(spot, list((o.Theta(spot=s),o.Gamma(spot=s)) for s in spot))


Out[12]:
[<matplotlib.lines.Line2D at 0x7f8a50ae4eb8>,
 <matplotlib.lines.Line2D at 0x7f8a50aea278>]

Vega, Volga, Vanna


In [13]:
plot(spot, list((o.Vega(spot=s),o.Gamma(spot=s, sig=0.1)) for s in spot))


Out[13]:
[<matplotlib.lines.Line2D at 0x7f8a50a4c390>,
 <matplotlib.lines.Line2D at 0x7f8a50a4c710>]

In [14]:
plot(spot, list((o.Vanna(spot=s),o.Vanna(spot=s, sig=0.1)) for s in spot))


Out[14]:
[<matplotlib.lines.Line2D at 0x7f8a50a340f0>,
 <matplotlib.lines.Line2D at 0x7f8a50a34470>]

In [15]:
plot(spot, list((o.Volga(spot=s),o.Volga(spot=s, sig=0.1)) for s in spot))


Out[15]:
[<matplotlib.lines.Line2D at 0x7f8a509953c8>,
 <matplotlib.lines.Line2D at 0x7f8a50995748>]

Rho and RhoYld


In [16]:
plot(spot, list((o.Rho(spot=s),o.RhoYld(spot=s)) for s in spot))


Out[16]:
[<matplotlib.lines.Line2D at 0x7f8a50978908>,
 <matplotlib.lines.Line2D at 0x7f8a50978c88>]