Home Ask Login Register

Developers Planet

Your answer is one click away!

Inthan February 2016

Show absolute value in binomial graph

Recombining binomial price lattice

binomial price lattice

Hi, I want to show absolute values (numbers) in each node of this graph. I have tried to plot values for each node but there were errors occurred. Can any one help me to tackle this problem. I appreciate any help. I look forward your kind help.

from math import *
import pylab as z;
import numpy as np;

def PriceMovements(S0, down, up, totalsteps, upsteps):
    S = S0*(pow(up, upsteps))*(pow(down, totalsteps-upsteps))
    return S

def binomial(d, u, p):
    g = np.random.binomial(1,p)

    if g == 1:
        return u
        return d

#Use the following numbers to console the setting for binomial graph

nodes = 8 #Nodes
S = 1080.0 #Initial spot price
u = 1.1346 #Up factor
d = 0.8814 #Down factor
p = 0.7844 # Probability
r = 1.08 #1+Interest rate
n = 3 #Steps

numberofpaths = 2**nodes
valuelist = [] #Emptylist
z.figure(0) #Generating the figure
temp = S #Temporary variable

for i in range(0, numberofpaths, 1):
    valuelist =[]
    S = temp;
    for c in range(0, nodes + 1, 1):
        S = S*binomial(d, u, p)
    z.plot(range(0, nodes + 1, 1), valuelist)

z.title("Price movements")


B. M. February 2016

use text :

# after z.plot(range(0, nodes + 1, 1), valuelist)
for i in range(nodes):


enter image description here

just tune the offsets for best apparence.

Post Status

Asked in February 2016
Viewed 3,897 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life