Learn R Programming

FinancialInstrument (version 1.3.1)

update_instruments.instrument: Update instruments with metadata from another instrument.

Description

Update instruments with metadata from another instrument.

Usage

update_instruments.instrument(Symbols, source_id, create.new = FALSE,
  ignore = "identifiers", assign_i = TRUE)

Arguments

Symbols

charcter vector of primary_ids or other instrument identifiers. of instruments to be updated. Alternatively, Symbols can be an instrument or list of instruments.

source_id

The primary_id (or other identifier) of an instrument, or an instrument. The source_id instrument will be used to update the metadata of Symbols' instruments.

create.new

If FALSE (Default), only attributes that exist but have empty values will be updated. If TRUE, new attributes will be created if source_id has them, but the Symbols do not.

ignore

vector of names of instrument attributes that should not be copied to the updated instruments.

assign_i

TRUE/FALSE. If TRUE, the updated instruments will be assigned back into the instrument environment. If FALSE, a list of updated instruments will be returned

Value

if isTRUE(assign_i) a vector of primary_ids of the instruments that were upated. Otherwise, a list of updated instrument objects.

Details

By default, only attributes that have a value of "" will be given a new value.

If create.new is TRUE, then if there are attributes in source_id that are not in the Symbols' instrument, those attributes will be copied to the updated instruments unless they are in ignore.

See Also

update_instruments.yahoo, all.equal.instrument

Examples

Run this code
# NOT RUN {
#rm_instruments()
currency("USD")
synthetic("SPX", "USD", identifiers=list(yahoo="GSPC"),
          tick_size=0.01,
         liquidHours="T08:30:00/T15:00:00", 
         extraField='something else', 
         assign_i=TRUE)
stock("SPY", "USD", liquidHours="", assign_i=TRUE)
all.equal(getInstrument("SPX"), getInstrument("SPY"))
getInstrument("SPY")
## update SPY metadata based on the metadata of SPX
## Only attributes that == "" are updated by default
update_instruments.instrument("SPY", "SPX", assign_i=FALSE) #liquidHours
update_instruments.instrument("SPY", "SPX", create.new=TRUE,
                              ignore=c("identifiers", "type"), 
                              assign_i=FALSE)
# Although you probably do NOT want to, this will
# copy everything new -- including identifiers and type!
update_instruments.instrument("SPY", "SPX", create.new=TRUE, ignore=NULL, 
                              assign_i=FALSE) 
# }

Run the code above in your browser using DataLab