Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note: Needs to do with Python Below is Python code: import numpy as np strike_price = 110 class Node: def __init__(self, P, S): self.P =

image text in transcribed

Note: Needs to do with Python

Below is Python code:

import numpy as np

strike_price = 110

class Node: def __init__(self, P, S): self.P = P self.S = S

def SetP(self, P): self.P = P

def SetS(self, S): self.S = S

def GetP(self): return self.P

def GetS(self): return self.S

def Print(self): return (self.GetP(), self.GetS())

class BinomialModel: def __init__(self, initial_risk, r, N, period, D, U): self.initial_risk = initial_risk self.r = r self.N = N self.period = period self.D = D self.U = U self.q = 0 self.nodes = []

def GetPrice(self, n, k): return round(self.nodes[n][k].GetP(), 2)

def GetRisk(self, n, k): return round(self.nodes[n][k].GetS(), 2)

def GetQuantities(self, n, k): return ( round(self.ComputeRiskFreeAssetQuantity(n, k), 2), round(self.ComputeRiskyAssetQuantity(n, k), 2), )

def Solve(self, func): # N columns and N + 1 rows for _ in range(self.N + 1): self.nodes.append([])

self.Initialize(func)

# compute P_n(k) for n in range(self.N - 1, -1, -1): for k in range(n + 1): self.nodes[n].append( Node( self.ComputeInitialPrice(n, k), self.initial_risk * self.U**k * self.D ** (n - k), ) ) """ print( f"node {n}|{k}: (P,S) = {(self.GetPrice(n,k),self.GetRisk(n,k))} with (a,b) = {self.GetQuantities(n,k)}" ) """

def Initialize(self, func): self.q = (self.r - self.D) / (self.U - self.D)

# initial outer nodes P_N(k) for k in range(self.N + 1): if func == "put": # (strike price - initial risk)^+ S = self.initial_risk * self.U**k * self.D ** (self.N - k) self.nodes[-1].append(Node(max(0, strike_price - S), S)) elif func == "call": # (initial risk - strike price)^+ S = self.initial_risk * self.U**k * self.D ** (self.N - k) self.nodes[-1].append(Node(max(0, S - strike_price), S)) elif func == "forward": # call - put S = self.initial_risk * self.U**k * self.D ** (self.N - k) self.nodes[-1].append(Node(max(0, S - strike_price), S)) - self.nodes[ -1 ].append(Node(max(0, strike_price - S), S))

def ComputeInitialPrice(self, n, k): # compute P_n(k) return ( self.q * self.nodes[n + 1][k + 1].GetP() + (1 - self.q) * self.nodes[n + 1][k].GetP() ) / self.r

def ComputeRiskyAssetQuantity(self, n, k): # compute b return (self.nodes[n + 1][k + 1].GetP() - self.nodes[n + 1][k].GetP()) / ( self.nodes[n + 1][k + 1].GetS() - self.nodes[n + 1][k].GetS() )

def ComputeRiskFreeAssetQuantity(self, n, k): # compute a return ( self.U * self.nodes[n + 1][k].GetP() - self.D * self.nodes[n + 1][k + 1].GetP() ) / (self.r * (self.U - self.D))

def main(): NotCorrect = True while NotCorrect: try: # risk free rate is assumed to be of the form exp(r * length period) print( "Set variables as: initial_risk riskfree_rate number_periods length_period down_period up_period payoff_func" ) initial_risk, r, N, period, D, U, func = input().split() model = BinomialModel( float(initial_risk), float(r), int(N), int(period), float(D), float(U) ) str(func) NotCorrect = False except: print("Invalid inputs")

model.Solve(func)

print( f"Initial Price is {model.GetPrice(0,0)} with (a,b) = {model.GetQuantities(0,0)}" )

if __name__ == "__main__": main()

4. Consider a European put option with strike k=30 and maturity 15 days on one share of Plum stock. To investigate the influence of the number of periods consider a sequence of models indexed by N1. The N th model comprises N periods of length N=N1(36015) and has the following characteristics: - The initial share price of Plum is S0=30 - The continuously compounded riskfree rate is r=0.0125 - The one period up and down factors are given by UN=1/DN=e0.18N Verify that the N th Binomial model is arbitrage free for all N1 and use the code you wrote in Question 1. to compute the initial call prices (C0N)N=1100 as well as the initial replicating portfolios ((a0N,b0N))N=1100 implied by the first hundred binomial models. Plot the results and describe what you observe

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe the new structures for the HRM function. page 676

Answered: 1 week ago