Skip to content

Instantly share code, notes, and snippets.

@paultsw
Created July 13, 2016 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paultsw/55e7c7d5cac04e33526f98e36988a3a3 to your computer and use it in GitHub Desktop.
Save paultsw/55e7c7d5cac04e33526f98e36988a3a3 to your computer and use it in GitHub Desktop.
"""
Binomial asset price dynamics model class definiton.
"""
class BinomialModel:
"""
Initialize with the following parameters:
R <- interest rate on cash account investment;
u <- up movement percentage (d := 1/u);
p <- real number btwn. 0 & 1 inclusive representing prob of up move;
N <- number of periods in the model
S <- price of asset at time t = 0.
"""
def __init__(self,R=1.0,N=1,u=1.00,p=1.0,S=100):
self.rate = R
self.up = u
self.down = 1 / u
self.p_up = p
self.p_dn = 1 - p
self.pds = N
self.init_price = S
def get_prices_at(self,pd):
"""
Get the possible prices of the asset at t=pd in
the form of a list.
Since multiplication is commutative, just need
to generate t = pd number of elements.
"""
multipliers = [((self.up ** k) * (self.down ** (pd-k))) \
for k in range(0,pd)]
return [self.init_price * m for m in multipliers]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment