SlideShare a Scribd company logo
1 of 1
#by Tianqi
from math import sqrt
from random import gauss
from numpy import ones, random,exp,average,maximum, zeros, array
S=100
K=105
r=0.001
v=0.1
T=0.5
steps=1000
dt=T/steps
u=exp(v*(dt**0.5))
d=1/u
a = exp((r-q)*dt )
p=(a-d)/(u-d)
pricetree=zeros((steps,steps))
pricetree[0,0]=S
for i in range(1,steps):
pricetree[i,i]=pricetree[i-1,i-1]*d
pricetree[0:i,i]=pricetree[0:i,i-1]*u
#print(pricetree)
payofftree=zeros((steps,steps))
for j in range(steps,-1,-1):
payofftree[0:j,j-1]=maximum(pricetree[0:j,j-1]-K,0)
profittree=zeros((steps-1,steps-1))
#print(payofftree)
for x in range(steps-2,-1,-1):
for y in range(0,x+1):
#print(y)
#print(x)
profittree[y,x]=max(payofftree[y,x],(payofftree[y,x+1]*p+payofftree[y+1,x+1]*(
1-p))*exp(-r*dt))
payofftree[y,x]=max(profittree[y,x],payofftree[y,x])
print("AM call Price is")
print(profittree[0,0])

More Related Content

What's hot

Maple Code for Steepest Descent
Maple Code for Steepest DescentMaple Code for Steepest Descent
Maple Code for Steepest Descent
Jeremy Lane
 
Lesson20 Tangent Planes Slides+Notes
Lesson20   Tangent Planes Slides+NotesLesson20   Tangent Planes Slides+Notes
Lesson20 Tangent Planes Slides+Notes
Matthew Leingang
 

What's hot (20)

10CSL67 CG LAB PROGRAM 4
10CSL67 CG LAB PROGRAM 410CSL67 CG LAB PROGRAM 4
10CSL67 CG LAB PROGRAM 4
 
Newton cotes method
Newton cotes methodNewton cotes method
Newton cotes method
 
Faisal
FaisalFaisal
Faisal
 
【AI実装4】TensorFlowのプログラムを読む2 非線形回帰
【AI実装4】TensorFlowのプログラムを読む2 非線形回帰【AI実装4】TensorFlowのプログラムを読む2 非線形回帰
【AI実装4】TensorFlowのプログラムを読む2 非線形回帰
 
PythonArtCode
PythonArtCodePythonArtCode
PythonArtCode
 
Maple Code for Steepest Descent
Maple Code for Steepest DescentMaple Code for Steepest Descent
Maple Code for Steepest Descent
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programs
 
งาน 9
งาน 9งาน 9
งาน 9
 
Matlab code for secant method
Matlab code for secant methodMatlab code for secant method
Matlab code for secant method
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
 
งาน 9
งาน 9งาน 9
งาน 9
 
Advanced
AdvancedAdvanced
Advanced
 
Tangent plane
Tangent planeTangent plane
Tangent plane
 
Programa expresiones regulares
Programa expresiones regularesPrograma expresiones regulares
Programa expresiones regulares
 
Lesson20 Tangent Planes Slides+Notes
Lesson20   Tangent Planes Slides+NotesLesson20   Tangent Planes Slides+Notes
Lesson20 Tangent Planes Slides+Notes
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
Segundo Punto
Segundo PuntoSegundo Punto
Segundo Punto
 
Linked list int_data_fdata
Linked list int_data_fdataLinked list int_data_fdata
Linked list int_data_fdata
 
The Moore-Spiegel Oscillator
The Moore-Spiegel OscillatorThe Moore-Spiegel Oscillator
The Moore-Spiegel Oscillator
 
งาน 9
งาน 9งาน 9
งาน 9
 

Similar to PYTHON. AM CALL Pricing Trees

import turtleimport timeimport randomdef draw_rectangle(length.pdf
import turtleimport timeimport randomdef draw_rectangle(length.pdfimport turtleimport timeimport randomdef draw_rectangle(length.pdf
import turtleimport timeimport randomdef draw_rectangle(length.pdf
rakeshankur
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
Er Ritu Aggarwal
 
I am trying to implement timing on this program and cannot do it. Wh.pdf
I am trying to implement timing on this program and cannot do it. Wh.pdfI am trying to implement timing on this program and cannot do it. Wh.pdf
I am trying to implement timing on this program and cannot do it. Wh.pdf
allystraders
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
kesav24
 

Similar to PYTHON. AM CALL Pricing Trees (20)

import turtleimport timeimport randomdef draw_rectangle(length.pdf
import turtleimport timeimport randomdef draw_rectangle(length.pdfimport turtleimport timeimport randomdef draw_rectangle(length.pdf
import turtleimport timeimport randomdef draw_rectangle(length.pdf
 
Python hmm
Python hmmPython hmm
Python hmm
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Chap09alg
Chap09algChap09alg
Chap09alg
 
Chap09alg
Chap09algChap09alg
Chap09alg
 
C programs
C programsC programs
C programs
 
Matlab assignment
Matlab assignmentMatlab assignment
Matlab assignment
 
Practicle 1.docx
Practicle 1.docxPracticle 1.docx
Practicle 1.docx
 
Data Structure Insertion sort
Data Structure Insertion sort Data Structure Insertion sort
Data Structure Insertion sort
 
chap09alg.ppt for string matching algorithm
chap09alg.ppt for string matching algorithmchap09alg.ppt for string matching algorithm
chap09alg.ppt for string matching algorithm
 
I am trying to implement timing on this program and cannot do it. Wh.pdf
I am trying to implement timing on this program and cannot do it. Wh.pdfI am trying to implement timing on this program and cannot do it. Wh.pdf
I am trying to implement timing on this program and cannot do it. Wh.pdf
 
Engineering ppt by venay magen
Engineering ppt by venay magenEngineering ppt by venay magen
Engineering ppt by venay magen
 
lec2.ppt
lec2.pptlec2.ppt
lec2.ppt
 
lec2.ppt
lec2.pptlec2.ppt
lec2.ppt
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
Algorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileAlgorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical File
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
Simple Neural Network Python Code
Simple Neural Network Python CodeSimple Neural Network Python Code
Simple Neural Network Python Code
 
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestor
 

PYTHON. AM CALL Pricing Trees

  • 1. #by Tianqi from math import sqrt from random import gauss from numpy import ones, random,exp,average,maximum, zeros, array S=100 K=105 r=0.001 v=0.1 T=0.5 steps=1000 dt=T/steps u=exp(v*(dt**0.5)) d=1/u a = exp((r-q)*dt ) p=(a-d)/(u-d) pricetree=zeros((steps,steps)) pricetree[0,0]=S for i in range(1,steps): pricetree[i,i]=pricetree[i-1,i-1]*d pricetree[0:i,i]=pricetree[0:i,i-1]*u #print(pricetree) payofftree=zeros((steps,steps)) for j in range(steps,-1,-1): payofftree[0:j,j-1]=maximum(pricetree[0:j,j-1]-K,0) profittree=zeros((steps-1,steps-1)) #print(payofftree) for x in range(steps-2,-1,-1): for y in range(0,x+1): #print(y) #print(x) profittree[y,x]=max(payofftree[y,x],(payofftree[y,x+1]*p+payofftree[y+1,x+1]*( 1-p))*exp(-r*dt)) payofftree[y,x]=max(profittree[y,x],payofftree[y,x]) print("AM call Price is") print(profittree[0,0])