R version 2.5.1 (2007-06-27) Copyright (C) 2007 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] > ################################################################ > ## Initialization > ################################################################ > # context cleanup > rm(list=ls()) > > # external libraries loading > library(survival) Loading required package: splines > library(e1071) Loading required package: class > library(tseries) Loading required package: quadprog Loading required package: zoo Attaching package: 'zoo' The following object(s) are masked from package:base : rapply > library(fBasics) Loading required package: MASS Loading required package: fEcofin Loading required package: fCalendar Rmetrics, (C) 1999-2006, Diethelm Wuertz, GPL fCalendar: Time, Date and Calendar Tools Rmetrics, (C) 1999-2005, Diethelm Wuertz, GPL fBasics: Markets and Basic Statistics Attaching package: 'fBasics' The following object(s) are masked from package:e1071 : kurtosis, skewness > library(fSeries) Loading required package: mgcv This is mgcv 1.3-25 Loading required package: nnet Rmetrics, (C) 1999-2006, Diethelm Wuertz, GPL fSeries: The Dynamical Process Behind Financial Markets > library(nlme) > > ################################################################ > ## Data Loading > ################################################################ > > # load prices from file and compute returns > table<-read.csv("SASM_100fundamentalist_0speculators_prices.dat", header=FALSE, sep=" ", dec=".") > prices<-table$V2[1000:5000] > date<-table$V1[1000:5000] > returns<-diff(log(prices)) > normalized_returns<-(returns-mean(returns))/sd(returns) > day<-date > > # load world from file (optional) > table_world<-read.csv("SASM_100fundamentalist_0speculators_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="./images/SASM_100fundamentalist_0speculators_prices_returns.eps", horizontal=FALSE, onefile=FALSE, width=10, height=10) > 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() null device 1 > > ################################################################ > ## Returns distribution shape > ################################################################ > > # compare empirical distribution with a normal of same mean and variance > postscript(file="./images/SASM_100fundamentalist_0speculators_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() null device 1 > > # empirical vs theoretical qqplot > postscript(file="./images/SASM_100fundamentalist_0speculators_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() null device 1 > > # computes kurtosis of returns > cat("Kurtosis :\n", kurtosis(returns), "\n\n", sep="", file="./SASM_100fundamentalist_0speculators_numericalTests.txt", append=FALSE) > > ################################################################ > ## Returns dependency > ################################################################ > > # auto correlation function of returns > postscript(file="./images/SASM_100fundamentalist_0speculators_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() null device 1 > > # auto correlation function of absolute returns > postscript(file="./images/SASM_100fundamentalist_0speculators_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() null device 1 > > # Jarque-Bera test > capture.output(jarque.bera.test(returns), file="./SASM_100fundamentalist_0speculators_numericalTests.txt", append=TRUE) NULL > cat("\n", sep="", file="./SASM_100fundamentalist_0speculators_numericalTests.txt", append=TRUE) > > # Augmented-Dickey Fuller > capture.output(adf.test(returns), file="./SASM_100fundamentalist_0speculators_numericalTests.txt", append=TRUE) NULL Warning message: p-value smaller than printed p-value in: adf.test(returns) > cat("\n", sep="", file="./SASM_100fundamentalist_0speculators_numericalTests.txt", append=TRUE) > > # BDS > capture.output(bds.test(returns), file="./SASM_100fundamentalist_0speculators_numericalTests.txt", append=TRUE) NULL > cat("\n", sep="", file="./SASM_100fundamentalist_0speculators_numericalTests.txt", append=TRUE) > > # Box test > capture.output(Box.test(returns), file="./SASM_100fundamentalist_0speculators_numericalTests.txt", append=TRUE) NULL > cat("\n", sep="", file="./SASM_100fundamentalist_0speculators_numericalTests.txt", append=TRUE) > > # Hurst exponen > capture.output(rsFit(returns), file="./SASM_100fundamentalist_0speculators_numericalTests.txt", append=TRUE) NULL > cat("\n", sep="", file="./SASM_100fundamentalist_0speculators_numericalTests.txt", append=TRUE) > > proc.time() user system elapsed 2.732 0.080 2.807