Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import exp, sqrt
- def replicate(stockPrice, strikePrice, optionType, optionMaturity, stockVolatility, interestRate):
- # Valuate an option by making a replicating portfolio of a certain option.
- # Stock price is the current stock price.
- # Strike price is the strike price of the option.
- # Option type determines whether it is a call or put option.
- # Option maturity gives us the period in which the option matures.
- # Stock volatility gives us the standard deviation of the stock.
- # Interest rate is the used rate of return on the stock lend.
- # Determine the up and down side changes in a certain maturity period.
- upsideChange = exp(stockVolatility * sqrt(optionMaturity))
- downsideChange = 1/upsideChange
- # Determine the corresponding stock prices.
- upsidePrice = stockPrice * upsideChange
- downsidePrice = stockPrice * downsideChange
- # Set up the payoff scheme.
- payoffLeft = 0
- payoffRight = 0
- if downsidePrice <= strikePrice:
- payoffLeft = 0
- else:
- payoffLeft = downsidePrice - strikePrice
- if upsidePrice <= strikePrice:
- payoffRight = 0
- else:
- payoffRight = upsidePrice - strikePrice
- # Calculate the option delta
- if optionType == "call":
- optionDelta = (payoffRight - payoffLeft) / (upsidePrice - downsidePrice)
- else:
- optionDelta = (payoffLeft - payoffRight) / (upsidePrice - downsidePrice)
- # Replicate the payoffs by determining the buy/sell of shares and borrow/lend of money.
- if optionType == "call":
- buySharePrice = optionDelta * downsidePrice
- borrowPrice = buySharePrice / ((1 + interestRate) ** optionMaturity)
- else:
- sellSharePrice = optionDelta * upsidePrice
- lendPrice = sellSharePrice / ((1 + interestRate) ** optionMaturity)
- # Calculate the value of the option
- if optionType == "call":
- optionValue = (optionDelta * stockPrice) - borrowPrice
- else:
- optionValue = (optionDelta * stockPrice) + lendPrice
- return optionValue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement