Advertisement
chrisversloot

Py-based onestage tree model valuation of call & put options

Sep 22nd, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. from math import exp, sqrt
  2.  
  3. def replicate(stockPrice, strikePrice, optionType, optionMaturity, stockVolatility, interestRate):
  4.     # Valuate an option by making a replicating portfolio of a certain option.
  5.     # Stock price is the current stock price.
  6.     # Strike price is the strike price of the option.
  7.     # Option type determines whether it is a call or put option.
  8.     # Option maturity gives us the period in which the option matures.
  9.     # Stock volatility gives us the standard deviation of the stock.
  10.     # Interest rate is the used rate of return on the stock lend.
  11.  
  12.     # Determine the up and down side changes in a certain maturity period.
  13.     upsideChange    = exp(stockVolatility * sqrt(optionMaturity))
  14.     downsideChange  = 1/upsideChange
  15.  
  16.     # Determine the corresponding stock prices.
  17.     upsidePrice     = stockPrice * upsideChange
  18.     downsidePrice   = stockPrice * downsideChange
  19.  
  20.     # Set up the payoff scheme.
  21.     payoffLeft      = 0
  22.     payoffRight     = 0
  23.  
  24.     if downsidePrice <= strikePrice:
  25.         payoffLeft = 0
  26.     else:
  27.         payoffLeft = downsidePrice - strikePrice
  28.  
  29.     if upsidePrice <= strikePrice:
  30.         payoffRight = 0
  31.     else:
  32.         payoffRight = upsidePrice - strikePrice
  33.  
  34.     # Calculate the option delta
  35.     if optionType == "call":
  36.         optionDelta = (payoffRight - payoffLeft) / (upsidePrice - downsidePrice)
  37.     else:
  38.         optionDelta = (payoffLeft - payoffRight) / (upsidePrice - downsidePrice)
  39.  
  40.     # Replicate the payoffs by determining the buy/sell of shares and borrow/lend of money.
  41.     if optionType == "call":
  42.         buySharePrice   = optionDelta * downsidePrice
  43.         borrowPrice     = buySharePrice / ((1 + interestRate) ** optionMaturity)
  44.     else:
  45.         sellSharePrice  = optionDelta * upsidePrice
  46.         lendPrice       = sellSharePrice / ((1 + interestRate) ** optionMaturity)
  47.  
  48.     # Calculate the value of the option
  49.     if optionType == "call":
  50.         optionValue = (optionDelta * stockPrice) - borrowPrice
  51.     else:
  52.         optionValue = (optionDelta * stockPrice) + lendPrice
  53.  
  54.     return optionValue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement