Python scipy.optimize.minimize给出了ZeroDivisionError

时间:2015-09-04 21:43:10

标签: python scipy volatility

我正在尝试用Python实现SABR(Stochastic alpha,beta,rho)来计算隐含波动率。这里的链接非常准确,简洁地从幻灯片17开始解释SABR:http://lesniewski.us/papers/presentations/MIT_March2014.pdf

这个方法看起来很简单,但我遇到的问题是每次运行程序时都会收到ZeroDivisonError。我相信这可能是因为我在校准期间错误地选择了我的初始alpha,rho和sigma0。但是,我无法在网上找到如何选择初始值以保证找到最小值。

这是我的代码:

# args = [alpha, rho, sigma0]
# The other parameters (T, K, F0, beta, rho, marketVol) are globals
def calcImpliedVol(args):
    alpha = args[0] 
    rho = args[1]
    sigma0 = args[2]

    # From MIT powerpoint, slide 21
    Fmid = (F0 + K) / 2.0
    gamma1 = 1.0 * beta / Fmid
    gamma2 = 1.0 * beta * (beta - 1) / Fmid**2
    xi = 1.0 * alpha / (sigma0 * (1 - beta)) * (F0**(1-beta) - K**(1-beta))
    e = T * alpha**2 # From MIT powerpoint, slide 19

    # From MIT powerpoint, slide 21
    impliedVol = \
        1.0 * alpha * log(F0/K) / D(rho, xi) * \
        (1 + ((2 * gamma2 - gamma1**2 + 1 / Fmid**2)/24.0 * (sigma0 * Fmid**beta / alpha)**2 + \
        (rho * gamma1 / 4.0) * (sigma0 * Fmid**beta / alpha) + ((2 - 3 * rho**2) / 24.0)) * e) - \
        marketVol

    # Returns lambda function in terms of alpha, rho, sigma0
    return impliedVol;

# From MIT powerpoint, slide 21
def D(rho, xi):
    result = log((sqrt(1 - 2 * rho * xi + xi**2) + xi - rho) / (1-rho))
    return result

# Find optimal alpha, rho, sigma0 that minimizes calcImpliedVol - marketVol
def optimize():
    result = optimize.minimize(calcImpliedVol, [alpha_init, rho_init, sigma0_init])
    return result

非常感谢,非常感谢!

1 个答案:

答案 0 :(得分:0)

使用限制搜索间隔。