# Developers Planet

Inthan February 2016

### Show absolute value in binomial graph

Recombining 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
else:
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):
valuelist.append(S)
S = S*binomial(d, u, p)
z.plot(range(0, nodes + 1, 1), valuelist)

z.title("Price movements")
z.xlabel("Nodes")
z.ylabel("S(n)")
z.show()
``````

B. M. February 2016

use `text` :

``````# after z.plot(range(0, nodes + 1, 1), valuelist)
for i in range(nodes):
z.text(i+.2,valuelist[i]-25,'{:4.1f}'.format(valuelist[i]))
``````

for

just tune the offsets for best apparence.