# [R] How do I make this faster?

From: Hasan Diwan <hasan.diwan_at_gmail.com>
Date: Sat, 09 Apr 2011 09:49:52 +0200

dataTrack <- getSymbols(commandArgs(trailingOnly=T), from='2009-11-21', to='2011-04-03')
stockData <- get(dataTrack)
currencies <- row.names(oanda.currencies[grep(pattern='oz.', fixed=T, x =as.vector(oanda.currencies\$oanda.df.1.length.oanda.df...2....1.)) == F])   correlations <- vector()
values <- list()
# optimise these loops using the apply family
for (i in currencies) {
for (j in currencies) {

```      if (i == j) next()
fx <- getFX(paste(i, j, sep='/'), from='2009-11-20', to='2011-04-02')
# Prepare data by getting rates for market days only
fx <- get(fx)
fx <- fx[which(index(fx) %in% index(QQQ\$QQQ.Close))]
correlation <- cor(fx, QQQ\$QQQ.Close)
correlations <- c(correlations, correlation)
string <- paste(paste(i,j,sep='/'), correlation, sep=',')
values <- c(values,paste(string,'\n', sep=''))
```
}
}
# TODO eliminate NA's

values <- values[which(correlations[is.na(correlations) == F])]   correlations <- correlations[is.na(correlations) == F]   values <- values[order(correlations, decreasing=T)]   write.table(values, file=commandArgs(trailingOnly=T), sep='', qmethod=NULL, quote = F, row.names=F, col.names=F)   rm('currencies', 'correlations', 'values', 'fx', 'string')   return()
}
lagtime <- as.integer(commandArgs(trailingOnly=T)) if (is.na(lagtime)) lagtime <- 1
print(paste(Sys.time(), '<--- starting', lagtime, 'day lag currencies correlation with', commandArgs(trailingOnly=T), 'from 2009-11-20 to 2011-04-03'))
currencyCorrelation(lagtime)
print(paste(Sys.time(), '<--- ended, results in', commandArgs(trailingOnly=T)))
```--
Sent from my mobile device
Envoyait de mon telephone mobil

[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help