I have been working on the following code but i am repeatedly getting the error 'can't multiply sequence by non-int of type 'numpy.float64'. I cannot understand where the problem arises and how to rectify it. Any help is highly appreciated.
import random
import numpy as np
import scipy.stats as si
import sympy as sy
#N-Number of time steps
r=0.01
S0=1.00
Y0=0.04
N=10000.00
T=1.00
k=0.00
mu=0.20
K=2.00
sigma=0.04
total=0.00
b=5.00
a=-2.00
S=S0*np.exp((mu-0.5*(sigma**2))*T + sigma*random.gauss(0,1)*np.sqrt(T))
while k<N:
A=np.exp((-0.5)*((sigma**2)*T)*((k*np.pi*S)**2)*((1/(b-a))**2))*np.cos(((k*np.pi*S)/(b-a))*[np.log(S0/K)+(mu-0.5*(sigma**2))*T] -((k*a*np.pi)/(b-a)))
B1=np.cos((k*np.pi*b)/(b-a))+((k*np.pi)/(b-a))*np.sin((k*np.pi*b)/(b-a))
B2=np.sin((k*np.pi*b)/(b-a))-((k*np.pi)/(b-a))*np.cos((k*np.pi*b)/(b-a))
B=np.cos((k*np.pi*a)/(b-a))*(((np.exp)**b)*B1-1)+np.sin((k*np.pi*a)/(b-a))*(((np.exp)**b)*B2 +((k*np.pi)/(b-a)))
chi=(1/(1+((k*np.pi)/(b-a))**2))*B
psi=((b-a)/(k*np.pi))*np.sin((k*np.pi*a)/(b-a))
value=(A*2*K*(chi-psi))/(b-a)
total=total+value
k=k+1
call=(np.exp(-r*T)*total)/N
print("The value of the call option is:", call)
Output:
TypeError Traceback (most recent call last)
<ipython-input-1-86bcd7f2cc6d> in <module>
18 S=S0*np.exp((mu-0.5*(sigma**2))*T + sigma*random.gauss(0,1)*np.sqrt(T))
19 while k<N:
---> 20 A=np.exp((-0.5)*((sigma**2)*T)*((k*np.pi*S)**2)*((1/(b-a))**2))*np.cos(((k*np.pi*S)/(b-a))*[np.log(S0/K)+(mu-0.5*(sigma**2))*T] -((k*a*np.pi)/(b-a)))
21 B1=np.cos((k*np.pi*b)/(b-a))+((k*np.pi)/(b-a))*np.sin((k*np.pi*b)/(b-a))
22 B2=np.sin((k*np.pi*b)/(b-a))-((k*np.pi)/(b-a))*np.cos((k*np.pi*b)/(b-a))
TypeError: can't multiply sequence by non-int of type 'numpy.float64'