################################################################ ## Initialization ################################################################ # context cleanup rm(list=ls()) # external libraries loading library(survival) library(e1071) library(tseries) library(fBasics) library(fSeries) library(nlme) ################################################################ ## Data Loading ################################################################ # load prices from file and compute returns table<-read.csv("intraday_50fundamentalists_50speculators_87651234_prices.dat", header=FALSE, sep=" ", dec=".") prices<-table$V2 date<-table$V1 returns<-diff(log(prices)) normalized_returns<-(returns-mean(returns))/sd(returns) day<-date # load world from file (optional) table_world<-read.csv("intraday_50fundamentalists_50speculators_87651234_world.dat", header=FALSE, sep=" ", dec=".") prices_world<-table_world$V2 date_world<-table_world$V1 # compute a fake price series taken from a normal with same mean and deviation than 'prices' serie fake_prices<-0 fake_prices[1]<-prices[1] fake_returns<-0 fake_returns<-rnorm((length(prices)-1),mean(diff(log(prices))), sd(diff(log(prices)))) for(i in 2:(length(prices)-1)) fake_prices[i]<-fake_prices[i-1]*(1+fake_returns[i]) ################################################################ ## General ################################################################ # prices and returns postscript(file="intraday_50fundamentalists_50speculators_87651234_prices_returns.eps", horizontal=FALSE, onefile=FALSE) par(cex=2.3) m <- matrix(1:2, 2, 1) layout(m, widths=c(1, 1),heights=c(3,2)) plot(day, prices, type="l", xlab="date", ylab="prices") lines(date_world, prices_world, type="l", col="red") grid(10,10) plot(day[1:length(day)-1] ,diff(log(prices)), type="l", xlab="date", ylab="returns", ylim=c(min(returns), max(returns))) grid(10,10) dev.off() ################################################################ ## Returns distribution shape ################################################################ # compare empirical distribution with a normal of same mean and variance postscript(file="intraday_50fundamentalists_50speculators_87651234_distribution.eps", horizontal=FALSE, onefile=FALSE, paper='special', width=10, height=10) par(cex=2.3) hist(diff(log(prices)), nclass=200, freq=FALSE,xlab="return", ylab="frequency", main="") lines(density(fake_returns),col = "red", lwd=3) dev.off() # empirical vs theoretical qqplot postscript(file="intraday_50fundamentalists_50speculators_87651234_qqplot.eps", horizontal=FALSE, onefile=FALSE, paper='special', width=10, height=10) #layout(1) par(cex=2.3) qqnorm(diff(log(prices)), main="", xlab="theoretical quantiles", ylab="empirical quantiles") grid(10,10) qqline(fake_returns, col="red", lwd=3, cex=3) dev.off() # computes kurtosis of returns cat("Kurtosis :\n", kurtosis(returns), "\n\n", sep="", file="intraday_50fundamentalists_50speculators_87651234_numericalTests.txt", append=FALSE) ################################################################ ## Returns dependency ################################################################ # auto correlation function of returns postscript(file="intraday_50fundamentalists_50speculators_87651234_ACF.eps", horizontal=FALSE, onefile=FALSE, paper='special', width=10, height=10) par(cex=2.3, lwd=3) acf<-acf(returns) plot(acf, type='l', main='', lwd=3) dev.off() # auto correlation function of absolute returns postscript(file="intraday_50fundamentalists_50speculators_87651234_ACFabs.eps", horizontal=FALSE, onefile=FALSE, paper='special', width=10, height=10) par(cex=2.3, lwd=3) acf<-acf(abs(returns)) plot(acf, type='l', main='', lwd=3) dev.off() # Jarque-Bera test capture.output(jarque.bera.test(returns), file="intraday_50fundamentalists_50speculators_87651234_numericalTests.txt", append=TRUE) cat("\n", sep="", file="intraday_50fundamentalists_50speculators_87651234_numericalTests.txt", append=TRUE) # Augmented-Dickey Fuller capture.output(adf.test(returns), file="intraday_50fundamentalists_50speculators_87651234_numericalTests.txt", append=TRUE) cat("\n", sep="", file="intraday_50fundamentalists_50speculators_87651234_numericalTests.txt", append=TRUE) # BDS capture.output(bds.test(returns), file="intraday_50fundamentalists_50speculators_87651234_numericalTests.txt", append=TRUE) cat("\n", sep="", file="intraday_50fundamentalists_50speculators_87651234_numericalTests.txt", append=TRUE) # Box test capture.output(Box.test(returns), file="intraday_50fundamentalists_50speculators_87651234_numericalTests.txt", append=TRUE) cat("\n", sep="", file="intraday_50fundamentalists_50speculators_87651234_numericalTests.txt", append=TRUE) # Hurst exponen capture.output(rsFit(returns), file="intraday_50fundamentalists_50speculators_87651234_numericalTests.txt", append=TRUE) cat("\n", sep="", file="intraday_50fundamentalists_50speculators_87651234_numericalTests.txt", append=TRUE)