instrument_attr {FinancialInstrument}R Documentation

Add or change an attribute of an instrument

Description

This function will add or overwrite the data stored in the specified slot of the specified instrument.

Usage

instrument_attr(primary_id, attr, value, ...)

Arguments

primary_id

primary_id of the instrument that will be updated

attr

Name of the slot that will be added or changed

value

What to assign to the attr slot of the primary_id instrument

...

arguments to pass to getInstrument. For example, type could be provided to allow for primary_id to be an identifier that is shared by more that one instrument (of different types)

Details

If the attr you are trying to change is the “primary_id,” the instrument will be renamed. (A copy of the instrument will be stored by the name of value and the old instrument will be removed.) If the attr you are changing is “type”, the instrument will be reclassed with that type. If attr is “src”, value will be used in a call to setSymbolLookup. Other checks are in place to make sure that “currency” remains a currency object and that “multiplier” and “tick_size” can only be changed to reasonable values.

If attr is “identifiers” and value is NULL, identifiers will be set to list(). If value is not a list, add.identifier will be called with value. add.identifier will convert value to a list and append it to the current identifiers

Value

called for side-effect

Note

You can remove an attribute/level from an instrument by calling this function with value=NULL

Examples

## Not run: 
currency("USD")
stock("SPY","USD")
instrument_attr("USD","description","U.S. Dollar")
instrument_attr("SPY", "description", "An ETF")
getInstrument("USD")
getInstrument("SPY")

#Call with value=NULL to remove an attribute
instrument_attr("SPY", "description", NULL)
getInstrument("SPY")

instrument_attr("SPY","primary_id","SPX") #move/rename it
instrument_attr("SPX","type","synthetic") #re-class
instrument_attr("SPX","src",list(src='yahoo',name='^GSPC')) #setSymbolLookup
getSymbols("SPX") #knows where to look because the last line setSymbolLookup
getInstrument("SPX")

## End(Not run)

[Package FinancialInstrument version 1.3.1 Index]