Skip to content

Instantly share code, notes, and snippets.

@raddy
Created September 4, 2013 15:57
Show Gist options
  • Save raddy/6439080 to your computer and use it in GitHub Desktop.
Save raddy/6439080 to your computer and use it in GitHub Desktop.
Step 1 SVI Quasi Explicit -- Python
def f_gradient(params,y,market_vols,tte,q):
c,d,abar = params
y = y[market_vols>0]
vols = market_vols[market_vols>0]
n = len(y)
Y1 = np.sum(y)
Y2 = np.sum(y**2)
Y3 = np.sum(np.sqrt(y**2+1))
Y4 = np.sum(y*np.sqrt(y**2+1))
var_t = vols**2*tte
v = np.sum(var_t)
vY = np.sum(var_t*y)
vY2 = np.sum(var_t*np.sqrt(y**2+1))
A = np.array([(n+Y2),Y4,Y3,Y4,Y2,Y1,Y3,Y1,n]).reshape((3,3))
b = np.array([vY2,vY,v])
return np.ascontiguousarray(np.linalg.solve(A,b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment