## Code for denoising volatility and scale-free check

May 25, 2015 by zulfahmed

library(igraph)

library(tnet)

library(wavethresh)

prices<-read.table("vol.csv",sep=",",header=T)

g<-as.matrix(prices[,2:189])

r<-diff(log(g))

r[is.na(r)]10000]<-0

h.noisy<-log(r**2+0.00001)

print(dim(g))

# denoise

m<-matrix(0,nrow=2**14,ncol=256)

m[1:dim(h.noisy)[1],1:188]<-h.noisy

mw<-wd(m)

mwt<-threshold(mw,force.sure=T)

mrecon<-wr(mwt)

mrecon<-matrix(mrecon,nrow=2**14,byrow=TRUE)

print(dim(mrecon))

# this is the volatility object

h<-mrecon[1:dim(h.noisy)[1],1:188]

# the graph from covariance structure

C<-matrix(0,nrow=188,ncol=188)

for (i in 1:188){

for (j in 1:i) {

v<-cov(h[,i],h[,j])

C[i,j]<-v

C[j,i]<-v

}

}

t<-sd(C)

C<-C-t

C[C<0]<-0

# degree sequence count of nonzeros

deg<-matrix(0,nrow=1,ncol=188)

for (i in 1:188){

deg[i]0)

}

# fit power law

pfit<-power.law.fit(deg)

print(pfit$alpha)

# we found alpha=0.4027 so scale-free net

A0]<-1

lambda<-eigen(A)

print(lamda[1])

print(lamda[2])

### Like this:

Like Loading...

*Related*

## Leave a Reply