Learn R Programming

FinancialInstrument

FinancialInstrument provides infrastructure for defining, storing, and managing financial instrument metadata in R. Rather than focusing on market prices or returns, the package models the instruments themselves; their identities, specifications, and relationships. These instrument definitions can then be shared across research, trading, portfolio management, and analytics workflows.

The package supports currencies, equities, funds, futures, options, spreads, synthetic instruments, and custom instrument classes while remaining independent of any particular market data provider.

Design Philosophy

Most financial software begins with market data. FinancialInstrument begins with the instrument.

A stock is more than a price series. A futures contract is more than a ticker. Every financial instrument has identity, metadata, relationships, and contract specifications that exist independently of any particular data vendor.

For example:

A futures root defines the common contract specification (currency, multiplier, tick size, exchange, and related metadata). Individual future series inherit those properties while adding contract-specific information such as expiration dates and identifiers. Options, spreads, and synthetic instruments build upon the same hierarchical model rather than requiring separate frameworks.

This approach separates instrument metadata from market data, allowing a single instrument definition to be reused regardless of whether prices originate from Yahoo Finance, Bloomberg, Refinitiv, Interactive Brokers, Polygon, or another data source.

FinancialInstrument therefore acts as an instrument registry and metadata model that can support many different quantitative finance workflows.

Status

The package is being prepared for resubmission to CRAN. Until it is available from CRAN again, install the development version from GitHub.

Installation

Install the package from GitHub with remotes:

install.packages("remotes")
remotes::install_github("JustinMShea/FinancialInstrument")

After the package returns to CRAN, the standard installation command will be:

install.packages("FinancialInstrument")

Quick start

Financial instruments are stored in the package-level .instrument environment. Define currencies before defining instruments denominated in those currencies.

library(FinancialInstrument)

# Define currencies
currency(c("USD", "EUR", "JPY"))

# Define stocks
stock(
  c("AAPL", "MSFT"),
  currency = "USD",
  exchange = "NASDAQ"
)

# Retrieve an instrument definition
getInstrument("AAPL")

# List the instruments currently defined
ls_instruments()

# Display instrument metadata as a data frame
instrument.table()

Additional metadata can be supplied as named arguments:

stock(
  "IBM",
  currency = "USD",
  exchange = "NYSE",
  description = "IBM common stock",
  identifiers = list(
    Bloomberg = "IBM US Equity",
    Yahoo = "IBM"
  )
)

getInstrument("IBM")

Futures and options

A futures root specification can be defined with its contract multiplier and tick size:

currency("USD")

future(
  "ES",
  currency = "USD",
  multiplier = 50,
  tick_size = 0.25,
  description = "E-mini S&P 500 futures"
)

future_series(
  root_id = "ES",
  suffix_id = "Z26",
  expires = "2026-12-18"
)

For equity options, define the underlying stock and the option root before defining individual contracts:

stock("SPY", currency = "USD")

option(
  ".SPY",
  currency = "USD",
  multiplier = 100,
  tick_size = 0.01,
  underlying_id = "SPY"
)

option_series(
  root_id = "SPY",
  expires = "2027-01-15",
  callput = "call",
  strike = 600
)

Functions that retrieve data from external providers can be affected by provider availability, API changes, authentication requirements, or rate limits.

Saving instrument definitions

Save the current instrument environment:

saveInstruments("instruments.RData")

Load saved definitions into the current environment:

loadInstruments("instruments.RData")

To replace the current instrument environment with the saved definitions:

reloadInstruments("instruments.RData")

Reporting problems

Please report reproducible bugs and documentation problems through the GitHub issue tracker. Include:

  • the output of sessionInfo();
  • a minimal reproducible example;
  • the complete warning or error message;
  • the operating system and R version.

License

FinancialInstrument is distributed under a GNU General Public License, see the Description file for details. The package is free software and comes with absolutely no warranty.

Copy Link

Version

Install

install.packages('FinancialInstrument')

Monthly Downloads

35

Version

1.4.1

License

GPL-2 | GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Justin M. Shea

Last Published

August 4th, 2026

Functions in FinancialInstrument (1.4.1)

format_id

format an id
getInstrument

Primary accessor function for getting objects of class 'instrument'
fn_SpreadBuilder

Calculate prices of a spread from 2 instruments.
formatSpreadPrice

format the price of a synthetic instrument
instrument

instrument class constructors
instrument.auto

Create an instrument based on name alone
getSymbols.FI

getSymbols method for loading data from split files
instrument.table

Create data.frame with attributes of all instruments
instrument_attr

Add or change an attribute of an instrument
.get_rate

get an exchange rate series
ls_by_currency

List instruments by currency denomination
ls_expiries

show unique expiration dates of instruments
load.instruments

Load instrument metadata into the .instrument environment
ls_by_expiry

list or remove instruments by expiration date
is.instrument.name

check each element of a character vector to see if it is either the primary_id or an identifier of an instrument
find.instrument

Find the primary_ids of instruments that contain certain strings
expires.xts

xts expires extraction method
ls_underlyings

show names of underlyings
make_spread_id

Construct a primary_id for a spread instrument from the primary_ids of its members
is.currency

class test for object supposedly of type 'currency'
is.instrument

class test for object supposedly of type 'instrument'
is.currency.name

check each element of a character vector to see if it is either the primary_id or an identifier of a currency
option_series.yahoo

Constructor for series of options using yahoo data
ls_strikes

show strike prices of defined options
next.future_id

Get the primary_id of the next-to-expire (previously expiring) future_series instrument
parse_suffix

parse a suffix_id
parse_id

Parse a primary_id
ls_instruments_by

Subset names of instruments
ls_instruments

List or Remove instrument objects
month_cycle2numeric

coerce month_cycle to a numeric vector
setSymbolLookup.FI

Set quantmod-style SymbolLookup for instruments
root_contracts

future metadata to be used by load.instruments
saveSymbols.days

Save data to disk
future_series

Constructors for series contracts
print.id.list

id.list class print method
redenominate

Redenominate (change the base of) an instrument
print.suffix.list

suffix.list class print method
print.instrument

instrument class print method
saveInstruments

Save and Load all instrument definitions
update_instruments.instrument

Update instruments with metadata from another instrument.
update_instruments.yahoo

updates instrument metadata with data from yahoo
.to_daily

Extract a single row from each day in an xts object
update_instruments.masterDATA

Update instrument metadata for ETFs
sort.instrument

instrument class sort method
synthetic

synthetic instrument constructors
update_instruments.iShares

update iShares and SPDR ETF metadata
update_instruments.morningstar

Update instrument metadata for ETFs
sort_ids

sort primary_ids of instruments
volep

generate endpoints for volume bars
all.equal.instrument

instrument all.equal method
C2M

Month-to-Code and Code-to-Month
buildHierarchy

Construct a hierarchy of instruments useful for aggregation
Notionalize

Convert price series to/from notional value
to_secBATV

Convert tick data to one-second data
add.identifier

Add an identifier to an instrument
FindCommonInstrumentAttributes

Find attributes that more than one instrument have in common
add.defined.by

Add a source to the defined.by field of an instrument
CompareInstrumentFiles

Compare Instrument Files
build_series_symbols

Construct a series of symbols based on root symbol and suffix letters
expires

Extract the correct expires value from an instrument
expires.character

Character expires extraction method
currencies

currency metadata to be used by load.instruments
expires.spread

spread expires extraction method
expires.instrument

instrument expires extraction method
FinancialInstrument-package

Construct, manage and store contract specifications for trading
buildRatio

construct price ratios of 2 instruments
buildSpread

Construct a price/level series for pre-defined multi-leg spread instrument
exchange_rate

Constructor for spot exchange rate instruments
build_spread_symbols

Build symbols for exchange guaranteed (calendar) spreads