First, let's generate some hypothetical datasets. Then we will try to merge them according to certain rules. The easiest way is to use Monte Carlo simulation to generate those datasets:
> set.seed(123) > nStocks<-4 > nPeriods<-24 > x<-runif(nStocks*nPeriods,min=-0.1,max=0.20) > a<-matrix(x,nPeriods,nStocks) > d1<-as.Date("2000-01-01") > d2<-as.Date("2001-12-01") > dd<-seq(d1,d2,"months") > stocks<-data.frame(dd,a) > colnames(stocks)<-c("DATE",paste('stock',1:nStocks,sep=''))
In the code, the first line sets up a random seed which will guarantee that any user will get the same random numbers if he/she uses the same random seed. The runif() function is used to get random numbers from a uniform distribution. In a ...