-1

I want to initialize a curreny pair using FinancialInstrument. The data contains exchange rates for a certain currency pair (e.g. USD_CHF, USD_EUR etc.).

But this doesn't work, why?

> currency("USD")
[1] "USD"
> instrument("USD_CHF",currency="USD",multiplier=1)
primary_id :"USD_CHF"
currency   :"USD"
multiplier :1
tick_size  : NULL
identifiers: list()
type       : NULL
> getInstrument("USD_CHF")
[1] FALSE
Warning message:
In getInstrument("USD_CHF") :
  instrument USD_CHF not found, please create it first.

Or at first it works after creating there is an output with the correct primary_id. However getInstrument doesn't work..and my code thereafter neither.

Brian G. Peterson
  • 3,531
  • 2
  • 20
  • 21
MichiZH
  • 5,587
  • 12
  • 41
  • 81
  • 2
    You've fired off quite a few questions today. I suggest grabbing a cup of coffee and sitting down with the documentation for a few hours. – GSee Aug 15 '13 at 13:25
  • I've studied the documentation but not everything is clearly described or I don't understand it just like that. The answer below is great and exactly what I was looking for. But I'm grabbing a Cup of coffee now anyway ;-) – MichiZH Aug 15 '13 at 13:51
  • Have a look at the demos too – GSee Aug 15 '13 at 14:01

1 Answers1

3

It didn't save the instrument because the default for the assign_i argument is FALSE.

> instrument("USD_CHF", currency="USD", multiplier=1, assign_i=TRUE)
[1] "USD_CHF"
> getInstrument("USD_CHF")
primary_id :"USD_CHF"
currency   :"USD"
multiplier :1
tick_size  : NULL
identifiers: list()
type       : NULL

You're going to make your life difficult if you use that naming convention because parse_id will not know how to make sense of that. I suggest USDCHF or USD.CHF. You could use USD_CHF as an identifier (other than the primary_id) if you want so that getInstrument (and getSymbols.FI) could still find it by that name.

Also, you'd be better off using the exchange_rate constructor

> currency("USD")
[1] "USD"
> currency("CHF")
[1] "CHF"
> exchange_rate("USDCHF")
[1] "USDCHF"
> getInstrument("USDCHF")
primary_id      :"USDCHF"
currency        :"CHF"
multiplier      :1
tick_size       :0.01
identifiers     : list()
type            :"exchange_rate" "currency"
counter_currency:"USD"
GSee
  • 48,880
  • 13
  • 125
  • 145
  • this works great and makes a lot more sense than Instrument. Thx alot. However I still get this error and don't know why: Error in get(Symbol, pos = env) : object 'USDCHF' not found – MichiZH Aug 15 '13 at 14:08
  • Because you didn't read post I [told you to see](http://stackoverflow.com/questions/18247760/blotter-position-fill-doesnt-work-on-chart-guy-yollins-example#comment26762967_18247760) in another question of yours a couple hours ago. – GSee Aug 15 '13 at 14:15
  • Oh yeah sorry I'm definitely done for today, worked too long... Thx again GSee. – MichiZH Aug 15 '13 at 14:16
  • And you apparently didn't read the [comment that Brian left you](http://stackoverflow.com/questions/18247760/blotter-position-fill-doesnt-work-on-chart-guy-yollins-example#comment26767966_18247760). :-( – GSee Aug 15 '13 at 14:17