Quantcast

Setting up Financial Instrument

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Setting up Financial Instrument

harrisonmark1
I am trying to setup Financial Instrument but I keep getting an error which
I cannot find the cause of.  I am trying to follow the instructions given
by Brian Peterson in previous postings about how to setup persistent data
collections.

I am running Windows 7 64Bit using RStudio version 0.94.106 and R version
2.13.1.  I primarily do things in RStudio but I do open an R window if I
run into issues just to confirm it is not the GUI.

My base_dir is C:/Users/Mark/Documents which is what I get when I run
getwd() or set a variable like mydir <- getwd().

I have a folder under this directory for data for the aussie dollar so
there is a folder called AUDUSD - C:/Users/Mark/Documents/AUDUSD

I updated my R Profile - and run the following from a command line to check
that it works - so that when I start RStudio everything should be setup
including loading packages and financial instruments:
library(quantmod)
library(FinancialInstrument)
currency("USD")
currency("AUD")
exchange_rate("AUDUSD","AUD","USD")

I set the symbol lookup:
setSymbolLookup.FI(base_dir=mydir, storage_method="rda", src="FI")

I also have a file in my base_dir and in the AUDUSD directory
2011.12.17.AUDUSD.rda

I can load this file straight from the base directory using the command:
load("2011.12.17.AUDUSD.rda")

However, when I run the command:
getSymbols("AUDUSD", src="FI")

I get the error:

Error in if (ssd[length(ssd)] != symbol) dir <- paste(dir, symbol, sep = "/") :
  argument is of length zero



I have tried looking through the getSymbols code and searching via RSeek
but cannot find an answer.  Any help would be appreciated.

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Setting up Financial Instrument

gsee
Hi Mark,

I suspect that the problem is that getSymbols.FI ignores data that falls on
a weekend.  Since the only data that you have is for today which is a
Saturday, getSymbols.FI does not load it.  This is something we have
recently been talking about changing.

I think your call to "exchange_rate" isn't quite right.  It should probably
be either
exchange_rate("AUDUSD", "USD", "AUD")
or, more simply,
exchange_rate("AUDUSD")

To illustrate how it would work if you had data from a weekday, I'll use a
subset of data from 1 year ago.

> library(FinancialInstrument)
<snip>

> AUDUSD <- structure(c(0.98815, 0.988, 0.98815, 0.98825, 0.98825, 0.98825,
+ 0.9882, 0.98825, 0.98815, 0.9882, 0.98835, 0.9883, 0.98815, 0.9883,
+ 0.98835, 0.9884, 0.98835, 0.9884, 0.98835, 0.98825, 0.98835,
+ 0.98845, 0.988225, 0.988075, 0.988225, 0.9883, 0.988325, 0.9883,
+ 0.9883, 0.9883, 0.9882, 0.988275, 0.9884), class = c("xts", "zoo"
+ ), .indexCLASS = c("POSIXct", "POSIXt"), .indexTZ = "", index =
structure(c(1292616000,
+ 1292616060, 1292616120, 1292616180, 1292616240, 1292616300, 1292616360,
+ 1292616420, 1292616480, 1292616540, 1292616600), tzone = "", tclass =
c("POSIXct",
+ "POSIXt")), .Dim = c(11L, 3L), .Dimnames = list(NULL,
c("AUDUSD.Bid.Price",
+ "AUDUSD.Ask.Price", "AUDUSD.Mid.Price")))

> AUDUSD
                    AUDUSD.Bid.Price AUDUSD.Ask.Price AUDUSD.Mid.Price
2010-12-17 14:00:00          0.98815          0.98830         0.988225
2010-12-17 14:01:00          0.98800          0.98815         0.988075
2010-12-17 14:02:00          0.98815          0.98830         0.988225
2010-12-17 14:03:00          0.98825          0.98835         0.988300
2010-12-17 14:04:00          0.98825          0.98840         0.988325
2010-12-17 14:05:00          0.98825          0.98835         0.988300
2010-12-17 14:06:00          0.98820          0.98840         0.988300
2010-12-17 14:07:00          0.98825          0.98835         0.988300
2010-12-17 14:08:00          0.98815          0.98825         0.988200
2010-12-17 14:09:00          0.98820          0.98835         0.988275
2010-12-17 14:10:00          0.98835          0.98845         0.988400

> #mydir <- getwd()
> dir.create("tmpdata")

> # Save to disk
> saveSymbols.days("AUDUSD", base_dir='tmpdata', extension='rda')

> # Delete from workspace
> rm("AUDUSD")

> # Define currencies and exchange_rate
> currency(c("USD", "AUD"))
[1] "USD" "AUD"

> exchange_rate('AUDUSD')
[1] "AUDUSD"

> # setSymbolLookup for all instruments in .instrument envir
> setSymbolLookup.FI("tmpdata", extension='rda', split_method='days')

> # load from disk
> getSymbols("AUDUSD", from='2010-12-17', to='2011-12-17')
[1] "AUDUSD"

> AUDUSD
                    AUDUSD.Bid.Price AUDUSD.Ask.Price AUDUSD.Mid.Price
2010-12-17 14:00:00          0.98815          0.98830         0.988225
2010-12-17 14:01:00          0.98800          0.98815         0.988075
2010-12-17 14:02:00          0.98815          0.98830         0.988225
2010-12-17 14:03:00          0.98825          0.98835         0.988300
2010-12-17 14:04:00          0.98825          0.98840         0.988325
2010-12-17 14:05:00          0.98825          0.98835         0.988300
2010-12-17 14:06:00          0.98820          0.98840         0.988300
2010-12-17 14:07:00          0.98825          0.98835         0.988300
2010-12-17 14:08:00          0.98815          0.98825         0.988200
2010-12-17 14:09:00          0.98820          0.98835         0.988275
2010-12-17 14:10:00          0.98835          0.98845         0.988400
> ## Alternatively
> # rm_instruments(keep.currencies=FALSE) # <-- delete all instrument
metadata
> currency(c("AUD", "USD"))
[1] "AUD" "USD"
> exchange_rate("AUDUSD", src=list(src="FI", dir='tmpdata',
extension='rda', split_method='days'))
[1] "AUDUSD"
> getSymbols("AUDUSD")
[1] "AUDUSD"
> AUDUSD
                    AUDUSD.Bid.Price AUDUSD.Ask.Price AUDUSD.Mid.Price
2010-12-17 14:00:00          0.98815          0.98830         0.988225
2010-12-17 14:01:00          0.98800          0.98815         0.988075
2010-12-17 14:02:00          0.98815          0.98830         0.988225
2010-12-17 14:03:00          0.98825          0.98835         0.988300
2010-12-17 14:04:00          0.98825          0.98840         0.988325
2010-12-17 14:05:00          0.98825          0.98835         0.988300
2010-12-17 14:06:00          0.98820          0.98840         0.988300
2010-12-17 14:07:00          0.98825          0.98835         0.988300
2010-12-17 14:08:00          0.98815          0.98825         0.988200
2010-12-17 14:09:00          0.98820          0.98835         0.988275
2010-12-17 14:10:00          0.98835          0.98845         0.988400
>
> # clean up
> unlink('tmpdata', recursive=TRUE)

HTH,
Garrett

On Sat, Dec 17, 2011 at 5:37 PM, Mark Harrison <[hidden email]>wrote:

> I am trying to setup Financial Instrument but I keep getting an error which
> I cannot find the cause of.  I am trying to follow the instructions given
> by Brian Peterson in previous postings about how to setup persistent data
> collections.
>
> I am running Windows 7 64Bit using RStudio version 0.94.106 and R version
> 2.13.1.  I primarily do things in RStudio but I do open an R window if I
> run into issues just to confirm it is not the GUI.
>
> My base_dir is C:/Users/Mark/Documents which is what I get when I run
> getwd() or set a variable like mydir <- getwd().
>
> I have a folder under this directory for data for the aussie dollar so
> there is a folder called AUDUSD - C:/Users/Mark/Documents/AUDUSD
>
> I updated my R Profile - and run the following from a command line to check
> that it works - so that when I start RStudio everything should be setup
> including loading packages and financial instruments:
> library(quantmod)
> library(FinancialInstrument)
> currency("USD")
> currency("AUD")
> exchange_rate("AUDUSD","AUD","USD")
>
> I set the symbol lookup:
> setSymbolLookup.FI(base_dir=mydir, storage_method="rda", src="FI")
>
> I also have a file in my base_dir and in the AUDUSD directory
> 2011.12.17.AUDUSD.rda
>
> I can load this file straight from the base directory using the command:
> load("2011.12.17.AUDUSD.rda")
>
> However, when I run the command:
> getSymbols("AUDUSD", src="FI")
>
> I get the error:
>
> Error in if (ssd[length(ssd)] != symbol) dir <- paste(dir, symbol, sep =
> "/") :
>  argument is of length zero
>
>
>
> I have tried looking through the getSymbols code and searching via RSeek
> but cannot find an answer.  Any help would be appreciated.
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Setting up Financial Instrument

harrisonmark1
In reply to this post by harrisonmark1
Thanks for all the help Garrett.  I walked through your example and went
back to my RProfile and commented out everything I had added so I could
follow your suggestions by hand.

Long story short the 'zoo' package had a problem or was not being loaded
correctly which is why - I think - I was getting the error I was.  For
whatever reason when loading from the profile I was not seeing any 'zoo'
error or maybe I was but it did not register.

Now loading is working and thanks to you I know why my weekend date will
not load.


On Sat, Dec 17, 2011 at 8:26 PM, G See <[hidden email]> wrote:

> Hi Mark,
>
> I suspect that the problem is that getSymbols.FI ignores data that falls
> on a weekend.  Since the only data that you have is for today which is a
> Saturday, getSymbols.FI does not load it.  This is something we have
> recently been talking about changing.
>
> I think your call to "exchange_rate" isn't quite right.  It should
> probably be either
> exchange_rate("AUDUSD", "USD", "AUD")
> or, more simply,
> exchange_rate("AUDUSD")
>
> To illustrate how it would work if you had data from a weekday, I'll use a
> subset of data from 1 year ago.
>
> > library(FinancialInstrument)
> <snip>
>
> > AUDUSD <- structure(c(0.98815, 0.988, 0.98815, 0.98825, 0.98825,
> 0.98825,
> + 0.9882, 0.98825, 0.98815, 0.9882, 0.98835, 0.9883, 0.98815, 0.9883,
> + 0.98835, 0.9884, 0.98835, 0.9884, 0.98835, 0.98825, 0.98835,
> + 0.98845, 0.988225, 0.988075, 0.988225, 0.9883, 0.988325, 0.9883,
> + 0.9883, 0.9883, 0.9882, 0.988275, 0.9884), class = c("xts", "zoo"
> + ), .indexCLASS = c("POSIXct", "POSIXt"), .indexTZ = "", index =
> structure(c(1292616000,
> + 1292616060, 1292616120, 1292616180, 1292616240, 1292616300, 1292616360,
> + 1292616420, 1292616480, 1292616540, 1292616600), tzone = "", tclass =
> c("POSIXct",
> + "POSIXt")), .Dim = c(11L, 3L), .Dimnames = list(NULL,
> c("AUDUSD.Bid.Price",
> + "AUDUSD.Ask.Price", "AUDUSD.Mid.Price")))
>
> > AUDUSD
>                     AUDUSD.Bid.Price AUDUSD.Ask.Price AUDUSD.Mid.Price
> 2010-12-17 14:00:00          0.98815          0.98830         0.988225
> 2010-12-17 14:01:00          0.98800          0.98815         0.988075
> 2010-12-17 14:02:00          0.98815          0.98830         0.988225
> 2010-12-17 14:03:00          0.98825          0.98835         0.988300
> 2010-12-17 14:04:00          0.98825          0.98840         0.988325
> 2010-12-17 14:05:00          0.98825          0.98835         0.988300
> 2010-12-17 14:06:00          0.98820          0.98840         0.988300
> 2010-12-17 14:07:00          0.98825          0.98835         0.988300
> 2010-12-17 14:08:00          0.98815          0.98825         0.988200
> 2010-12-17 14:09:00          0.98820          0.98835         0.988275
> 2010-12-17 14:10:00          0.98835          0.98845         0.988400
>
> > #mydir <- getwd()
> > dir.create("tmpdata")
>
> > # Save to disk
> > saveSymbols.days("AUDUSD", base_dir='tmpdata', extension='rda')
>
> > # Delete from workspace
> > rm("AUDUSD")
>
> > # Define currencies and exchange_rate
> > currency(c("USD", "AUD"))
> [1] "USD" "AUD"
>
> > exchange_rate('AUDUSD')
> [1] "AUDUSD"
>
> > # setSymbolLookup for all instruments in .instrument envir
> > setSymbolLookup.FI("tmpdata", extension='rda', split_method='days')
>
> > # load from disk
> > getSymbols("AUDUSD", from='2010-12-17', to='2011-12-17')
> [1] "AUDUSD"
>
> > AUDUSD
>                     AUDUSD.Bid.Price AUDUSD.Ask.Price AUDUSD.Mid.Price
> 2010-12-17 14:00:00          0.98815          0.98830         0.988225
> 2010-12-17 14:01:00          0.98800          0.98815         0.988075
> 2010-12-17 14:02:00          0.98815          0.98830         0.988225
> 2010-12-17 14:03:00          0.98825          0.98835         0.988300
> 2010-12-17 14:04:00          0.98825          0.98840         0.988325
> 2010-12-17 14:05:00          0.98825          0.98835         0.988300
> 2010-12-17 14:06:00          0.98820          0.98840         0.988300
> 2010-12-17 14:07:00          0.98825          0.98835         0.988300
> 2010-12-17 14:08:00          0.98815          0.98825         0.988200
> 2010-12-17 14:09:00          0.98820          0.98835         0.988275
> 2010-12-17 14:10:00          0.98835          0.98845         0.988400
> > ## Alternatively
> > # rm_instruments(keep.currencies=FALSE) # <-- delete all instrument
> metadata
> > currency(c("AUD", "USD"))
> [1] "AUD" "USD"
> > exchange_rate("AUDUSD", src=list(src="FI", dir='tmpdata',
> extension='rda', split_method='days'))
> [1] "AUDUSD"
> > getSymbols("AUDUSD")
> [1] "AUDUSD"
> > AUDUSD
>                     AUDUSD.Bid.Price AUDUSD.Ask.Price AUDUSD.Mid.Price
> 2010-12-17 14:00:00          0.98815          0.98830         0.988225
> 2010-12-17 14:01:00          0.98800          0.98815         0.988075
> 2010-12-17 14:02:00          0.98815          0.98830         0.988225
> 2010-12-17 14:03:00          0.98825          0.98835         0.988300
> 2010-12-17 14:04:00          0.98825          0.98840         0.988325
> 2010-12-17 14:05:00          0.98825          0.98835         0.988300
> 2010-12-17 14:06:00          0.98820          0.98840         0.988300
> 2010-12-17 14:07:00          0.98825          0.98835         0.988300
> 2010-12-17 14:08:00          0.98815          0.98825         0.988200
> 2010-12-17 14:09:00          0.98820          0.98835         0.988275
> 2010-12-17 14:10:00          0.98835          0.98845         0.988400
> >
> > # clean up
> > unlink('tmpdata', recursive=TRUE)
>
> HTH,
> Garrett
>
> On Sat, Dec 17, 2011 at 5:37 PM, Mark Harrison <[hidden email]>wrote:
>
>> I am trying to setup Financial Instrument but I keep getting an error
>> which
>> I cannot find the cause of.  I am trying to follow the instructions given
>> by Brian Peterson in previous postings about how to setup persistent data
>> collections.
>>
>> I am running Windows 7 64Bit using RStudio version 0.94.106 and R version
>> 2.13.1.  I primarily do things in RStudio but I do open an R window if I
>> run into issues just to confirm it is not the GUI.
>>
>> My base_dir is C:/Users/Mark/Documents which is what I get when I run
>> getwd() or set a variable like mydir <- getwd().
>>
>> I have a folder under this directory for data for the aussie dollar so
>> there is a folder called AUDUSD - C:/Users/Mark/Documents/AUDUSD
>>
>> I updated my R Profile - and run the following from a command line to
>> check
>> that it works - so that when I start RStudio everything should be setup
>> including loading packages and financial instruments:
>> library(quantmod)
>> library(FinancialInstrument)
>> currency("USD")
>> currency("AUD")
>> exchange_rate("AUDUSD","AUD","USD")
>>
>> I set the symbol lookup:
>> setSymbolLookup.FI(base_dir=mydir, storage_method="rda", src="FI")
>>
>> I also have a file in my base_dir and in the AUDUSD directory
>> 2011.12.17.AUDUSD.rda
>>
>> I can load this file straight from the base directory using the command:
>> load("2011.12.17.AUDUSD.rda")
>>
>> However, when I run the command:
>> getSymbols("AUDUSD", src="FI")
>>
>> I get the error:
>>
>> Error in if (ssd[length(ssd)] != symbol) dir <- paste(dir, symbol, sep =
>> "/") :
>>  argument is of length zero
>>
>>
>>
>> I have tried looking through the getSymbols code and searching via RSeek
>> but cannot find an answer.  Any help would be appreciated.
>>
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> [hidden email] 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.
>>
>
>

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] 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.
Loading...