Olivier.S
Olivier.S

Reputation: 15

Instrument objects in R's `FinancialInstrument` package. `ls(envir=FinancialInstrument:::.instrument)`

I'd like to load one of my xts object as financial instrument in my environment (vs. getting the symbols from yahoo, google, etc) but I can't.

My xts is a EURUSD daily OHLC series.

ls(envir=FinancialInstrument:::.instrument) is giving me :

[1] "IWM" "QQQ" "SPY" "USD"

from previous getSymbols operations sourced at yahoo.

I have a bloomberg and I am importing intraday series etc through xls to R so I'd like to include those imports (such as EURUSD) in my environment.

Upvotes: 0

Views: 149

Answers (2)

FXQuantTrader
FXQuantTrader

Reputation: 6891

Your instruments you store in FinancialInstrument no direct dependence with what data you collect with getSymbols. You define and remove instruments as desired from the hidden .instrument environment in FinancialInstrument as desired, ideally using the helper functions below. Note that you can use getSymbols obviously to get data, but you still want to define the instrument using an appropriate helper like below.

This code should be self explanatory but may help you understand what is going on.

> ls_instruments()
NULL
> stock("AAPL", currency = "USD")
Error in instrument(primary_id = primary_id, currency = currency, multiplier = multiplier,  : 
  currency USD must be defined first
> currency("USD")
[1] "USD"
> stock("AAPL", currency = "USD")
[1] "AAPL"
> ls_instruments()
[1] "AAPL" "USD" 
> currency("JPY")
[1] "JPY"
> exchange_rate("USDJPY", currency = "JPY")
[1] "USDJPY"
> getInstrument("USDJPY")
primary_id      :"USDJPY"
currency        :"JPY"
multiplier      :1
tick_size       :0.01
identifiers     : list()
type            :"exchange_rate" "currency"
counter_currency:"USD"
> ls_instruments()
[1] "AAPL"   "JPY"    "USD"    "USDJPY"
> rm_stocks("AAPL")
> ls_instruments()
[1] "JPY"    "USD"    "USDJPY"
> rm_exchange_rates("USDJPY")
> ls_instruments()
[1] "JPY" "USD"

Upvotes: 0

Olivier.S
Olivier.S

Reputation: 15

It looks like :

exchange_rate("EURUSD") [1] "EURUSD"

automatically added the EURUSD pair to the environment.

Upvotes: 0

Related Questions