forgot to copy the list ---------- Forwarded message ---------- From: G See <gsee000 at gmail.com> Date: Thu, Dec 29, 2011 at 5:33 PM Subject: Re: [R-SIG-Finance] Mulitple FI Sources To: Mark Harrison <harrisonmark1 at gmail.com> Mark, You did not tell us which version of FinancialInstrument you are using, but my guess is that it is out of date. Also, you defined your exchange_rate backwards. ?Please see ?exchange_rate ... or the e-mail I sent you on Dec 17th ;-) Now, I'll let you know upfront that setSymbolLookup.FI doesn't really work. ?(more specifically, setSymbolLookup doesn't work well when you pass it a list). ?It sort of works, but once you've used it, the defaults you set cannot be overridden without another call to setSymbolLookup.FI. ?Luckly, you don't really need setSymbolLookup.FI. Before we get to that, getSymbols.FI requires a single base_dir for a given Symbol. ?If you want to end up with a single xts object with data from 2 different base directories, then you'll have to load the data from each base directory separately, then rbind or merge the data together. If you're simply asking how to have different instruments have different directories, one solution may be to update to the latest version of FinancialInstrument. ?You can make multiple calls to setSymbolLookup.FI and use the "Symbols" argument to set different directories for different Symbols, or you can use the "src" argument of an "instrument" call or in an "instrument_attr" call. ?(I'll demonstrate below.) But, as I already mentioned, I'd avoid doing that because setSymbolLookup does not really work when it is given a list. ?So, instead I'd simply use setSymbolLookup to specify that "FI" is the src, and call setDefaults on getSymbols.FI. ?Here's some code to show why.
# Create 2 directories
dir.create("tmpA")
dir.create("tmpB")
# make/save 2 different versions of data
XXX <- xts(1:10, Sys.time()-10:1*60)
saveSymbols.days("XXX", "tmpA")
XXX <- xts(20:11, Sys.time()-10:1*60)
saveSymbols.days("XXX", "tmpB")
# Define the stock. If you use "src" arg, 'setSymbolLookup'
# will be called. ?Don't specify "dir"
stock("XXX", currency("USD"),
+ ? ? ? src=list(src="FI", extension='rda')) [1] "XXX"
getSymbols("XXX", dir='tmpA', auto.assign=FALSE)
? ? ? ? ? ? ? ? ? ?[,1] 2011-12-29 17:10:37 ? ?1 2011-12-29 17:11:37 ? ?2 2011-12-29 17:12:37 ? ?3 2011-12-29 17:13:37 ? ?4 2011-12-29 17:14:37 ? ?5 2011-12-29 17:15:37 ? ?6 2011-12-29 17:16:37 ? ?7 2011-12-29 17:17:37 ? ?8 2011-12-29 17:18:37 ? ?9 2011-12-29 17:19:37 ? 10
getSymbols("XXX", dir='tmpB', auto.assign=FALSE)
? ? ? ? ? ? ? ? ? ?[,1] 2011-12-29 17:10:37 ? 20 2011-12-29 17:11:37 ? 19 2011-12-29 17:12:37 ? 18 2011-12-29 17:13:37 ? 17 2011-12-29 17:14:37 ? 16 2011-12-29 17:15:37 ? 15 2011-12-29 17:16:37 ? 14 2011-12-29 17:17:37 ? 13 2011-12-29 17:18:37 ? 12 2011-12-29 17:19:37 ? 11
# Since we didn't set the global default for "dir",
# it works. ?But,
# If you specify "dir" with setSymbolLookup,
# it will be used even if you provide a local arg
setSymbolLookup.FI("tmpA", Symbols='XXX')
getSymbols("XXX", auto.assign=FALSE)
? ? ? ? ? ? ? ? ? ?[,1] 2011-12-29 17:10:37 ? ?1 2011-12-29 17:11:37 ? ?2 2011-12-29 17:12:37 ? ?3 2011-12-29 17:13:37 ? ?4 2011-12-29 17:14:37 ? ?5 2011-12-29 17:15:37 ? ?6 2011-12-29 17:16:37 ? ?7 2011-12-29 17:17:37 ? ?8 2011-12-29 17:18:37 ? ?9 2011-12-29 17:19:37 ? 10
getSymbols("XXX", dir='tmpB', auto.assign=FALSE) #dir arg is ignored!!!
? ? ? ? ? ? ? ? ? ?[,1] 2011-12-29 17:10:37 ? ?1 2011-12-29 17:11:37 ? ?2 2011-12-29 17:12:37 ? ?3 2011-12-29 17:13:37 ? ?4 2011-12-29 17:14:37 ? ?5 2011-12-29 17:15:37 ? ?6 2011-12-29 17:16:37 ? ?7 2011-12-29 17:17:37 ? ?8 2011-12-29 17:18:37 ? ?9 2011-12-29 17:19:37 ? 10
# have to re-setSymbolLookup either with setSymbolLookup.FI,
# or instrument_attr as below
instrument_attr("XXX", "src", list(src='FI', dir='tmpB'))
getSymbols("XXX", auto.assign=FALSE)
? ? ? ? ? ? ? ? ? ?[,1] 2011-12-29 17:10:37 ? 20 2011-12-29 17:11:37 ? 19 2011-12-29 17:12:37 ? 18 2011-12-29 17:13:37 ? 17 2011-12-29 17:14:37 ? 16 2011-12-29 17:15:37 ? 15 2011-12-29 17:16:37 ? 14 2011-12-29 17:17:37 ? 13 2011-12-29 17:18:37 ? 12 2011-12-29 17:19:37 ? 11
# You're better off NOT providing a list to "src", and
# instead using setDefaults on getSymbols.FI
rm_instruments("XXX")
stock("XXX", currency("USD"), src='FI')
[1] "XXX"
setDefaults('getSymbols.FI', dir='tmpB', extension='rda')
setSymbolLookup(XXX='FI')
getSymbols("XXX", auto.assign=FALSE)
? ? ? ? ? ? ? ? ? ?[,1] 2011-12-29 17:10:37 ? 20 2011-12-29 17:11:37 ? 19 2011-12-29 17:12:37 ? 18 2011-12-29 17:13:37 ? 17 2011-12-29 17:14:37 ? 16 2011-12-29 17:15:37 ? 15 2011-12-29 17:16:37 ? 14 2011-12-29 17:17:37 ? 13 2011-12-29 17:18:37 ? 12 2011-12-29 17:19:37 ? 11
getSymbols("XXX", dir='tmpA', auto.assign=FALSE)
? ? ? ? ? ? ? ? ? ?[,1] 2011-12-29 17:10:37 ? ?1 2011-12-29 17:11:37 ? ?2 2011-12-29 17:12:37 ? ?3 2011-12-29 17:13:37 ? ?4 2011-12-29 17:14:37 ? ?5 2011-12-29 17:15:37 ? ?6 2011-12-29 17:16:37 ? ?7 2011-12-29 17:17:37 ? ?8 2011-12-29 17:18:37 ? ?9 2011-12-29 17:19:37 ? 10
# Clean up
unlink("tmpA", recursive=TRUE)
unlink("tmpB", recursive=TRUE)
HTH,
Garrett
On Wed, Dec 28, 2011 at 2:37 PM, Mark Harrison <harrisonmark1 at gmail.com> wrote:
I am using R and RStudio versions 2.13.1 and 0.94.106 respectively.
I am using Financial Instrument and everything is working for a single data
source. ?I have my Rprofile file setup to load packages, define my
instruments, and set my symbol lookup souce.
# packages to load at startup
library(quantmod)
library(fTrading)
# currencies defined
currency("USD")
currency("GBP")
# now exchange rates
# British Pound Rates
exchange_rate("GBPUSD","GBP","USD")
# Set symbol lookups
setSymbolLookup.FI("HistFX", storage_method="rda")
Once I start R or RStudio everything loads and I can run the following and
everything works:
getSymbols.FI("GBPUSD")
This all works for a single data source but I have multiple data sources or
data sets that I would like to access and would like to put everything in
my RProfile but I have yet to figure out how to make it work.
For example, I have a series of historical data files that I got from a
vendor who is not my broker. ?So I want to keep my historical data files
separate in one directory 'HistFX' and any data I get from my broker in a
separate folder called 'Broker' for example.
So the directories might look like:
C:\Documents\HistFX\GBPUSD
C:\Documents\Broker\GBPUSD
I tried adding multiple lines to my RProfile with for each source but it
looks like the last line read in is the 'live' one. ?I even tried adding
'src=' to try and distinguish one from the other
setSymbolLookup.FI("HistFX", storage_method="rda")
setSymbolLookup.FI("Broker", storage_method="rda")
setSymbolLookup.FI("HistFX", storage_method="rda", src="hist")
setSymbolLookup.FI("Broker", storage_method="rda", src='broker")
I realize the simplest solution would be to just add a setSymbolLookup.FI
command to any script I use pointing to the data I want to use - i.e.
historical or broker - but like I said I was trying to do this in the
RProfile.
Any help would be appreciated.
? ? ? ?[[alternative HTML version deleted]]
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.