[R-SIG-Finance] Update price data on disk using mmap package
Wolfgang Wu
wobwu22 at gmail.com
Wed Feb 29 10:58:18 CET 2012
Hello everyone,
I am currently storing my price data for fast access as a mmap file on
disk. This works great and is super fast. All data is in one big file
which I subset to get the data I need into memory.
Now I will need to update that data that is stored on disk on a daily
basis to store new data. The solution I currently have is to load all
data into memory, append the new data to the data in memory and then
store everything again as mmap on disk. Unfortunately I am running into
memory problems now when loading all of the data into memory.
So my question is: Is it possible to append new prices directly into my
file on disk without loading everything into memory? And if, how?
Any help is appreciated!!
Here is an example of what I am trying to do:
library(quantmod)
library(mmap)
#Just for setting up the example
getSymbols('SPY')
xtsPrices <- SPY[1:(nrow(SPY)-1), ];
xtsNewPrice <- last(SPY);
#Save prices in mmap on disk
cFile <- 'C:/temp/PriceData.mmap'
nPrices <- as.numeric(xtsPrices);
mmapPrices <- as.mmap(nPrices, mode=double(), file=cFile);
munmap(mmapPrices);
#Now I would like to append the new prices directly to the mmap object
on disk
mmapPrices <- mmap(file=cFile, mode=double());
nNewPrice <- as.numeric(xtsNewPrice);
mmapPrices <- c(mmapPrices, nNewPrice); #This line does not work how I
hoped it would.
Regards,
Wolfgang
More information about the R-SIG-Finance
mailing list