## SIMPLE EXERCISE PYTHON LIKELIHOOD RATIO TEST FOR LEVY STABLE DISTRIBUTIONS WITH TWO DIFFERENT TAIL INDICES

August 17, 2015 by zulfahmed

This is a simple exercise that illustrates the use of characteristic functions of the Levy stable distribution for and . the likelihood ratio test checks a chi-squared distribution.

import numpy as np

import scipy.stats as st

import Quandl

# Let x be a vector of time series points

# Let N be length(x)

# Let t = 1:N

# We want the likelihood ratio test for whether x comes from P versus Q

tok = “CoHxdmas1Pz2t7Hk8maE”

x = Quandl.get(“WIKI/AAPL”,ahtoken=tok)

print(x)

r = np.diff(np.log(x[“Adj. Close”]))

r[np.isnan(r)]=0

N=len(r)

a = -0.1

b = 0.1

D = 201

xvals = np.linspace(a,b,num=D)

xivals = np.linspace(-np.pi,np.pi,num=D)

# Let alpha1, alpha2 be two parameters

alpha1 = (0.5+0.15)**(-1)

alpha2 = (0.5+0.2)**(-1)

c=1.0

z1 = np.exp( c*abs(xivals)**alpha1)

z2 = np.exp( c*abs(xivals)**alpha2)

p1 = np.fft.ifft(z1)

p2 = np.fft.ifft(z2)

pi1 = np.sum(np.abs(p1))

pi2 = np.sum(np.abs(p2))

p1 = np.real(p1)/pi1

p2 = np.real(p2)/pi2

def spacebin( x0, xvals):

c = 1000

idx = 0

for j in range(len(xvals)):

if np.abs(x0-xvals[j])<c:

idx = j

c=np.abs(x0-xvals[j])

return idx

llk1 = 0

llk2 = 0

for j in range(N):

idx = spacebin(r[j],xvals)

llk1 = llk1 + np.log( p1[idx])

llk2 = llk2 + np.log( p2[idx])

print(llk1)

print(llk2)

print st.chi2.ppf(2*llk1-2*llk2,0)

### Like this:

Like Loading...

*Related*

## Leave a Reply