User talk:Homingbird

rm(list=ls(all=TRUE))

skew<-function(x){ num<-mean((x-mean(x))^3) den<-(mean((x-mean(x))^2))^1.5 skewness=num/den skewness }

kurt<-function(x){ num<-mean((x-mean(x))^4) den<-(mean((x-mean(x))^2))^2 kurtosis=num/den kurtosis }

data=read.csv("I:data/20080618",header=T) attach(data) library(MASS) row=dim(data)[1] time=strptime(time,"%H:%M:%S") dur=as.matrix(time[-1]-time[-row]) dur=rbind(0,dur) move=as.matrix(price[-1]-price[-row]) move=rbind(0,move) ret=as.matrix(log(price[-1]/price[-row])) ret_sq=ret*ret ret_sgn=sign(ret)

N=1500 ret_term=numeric(N) for(i in 1:N){ a=seq(1,row-1,by=i) ret_term[i]=kurt(ret[a]) } plot(ret_term,type="l") abline(h=3)

n=10 long=120 avg_dur=0 avg_move=0 index=matrix(c(1),1,1) buy=as.matrix(numeric(row)) for(i in n:row){ temp_dur=avg_dur temp_move=avg_move avg_dur=mean(dur[(i-n+1):i]) avg_move=mean(move[(i-n+1):i]) if((avg_dur0)&&(avg_dur<2)){ if(price[i]long)) index=rbind(index,i) } }

plot(time,price,type="l") points(time[index],price[index],col="red",pch="o")