import sys
from random import gauss
from math import exp,sqrt
import math
from scipy.stats import norm
from math import *
def american_option(type_s, S0, sigma, r, d, K, N, T):
d1= log(float(S0)/K)+ ((r-d+ sigma*sigma/2)*T)/(sigma*sqrt(T))
d2= d1- sigma*sqrt(T)
if type_s== 'call':
m = S0*exp(-d*T)*N*(d1)- K*exp(-r*T)*N*(d2)
elif type_s== 'put':
m = K*exp(-r*T)*N*(-d2)- S0*exp(-d*T)*N*(-d1)
return m
american_option(100, 0.3, 0.1, 0.05, 110, 12, 365,)
in american_option(S0,sigma,r,d,K,N,T,type) 4 5如果type =='call': 6 m = S0 * exp(-d * T) N(d1) - K exp(-r * T) N(d2) 7 elif type =='put': 8 m = K exp(-r * T)* N(-d2) - S0 * exp(-d * T)* N(-d1)
TypeError:'int'对象不可调用
m = S0 * exp(-d * T) N (d1) - K exp(-r T) N (d2 )
TypeError:'int'对象不可调用