A Filter System for Selecting Trading Instruments

Enables filtering datasets of tradable instruments by prior specified identifiers which correspond to saved filter expressions. A filter is a named expression bound to a target dataset, stored once in a package level registry, and later applied to select trading codes such as tickers or symbols out of a universe, price or signal dataset. The design follows the `filters` package, replacing the clinical study dataset convention with a trading instrument convention.


filters.trade

A filter system for selecting trading instruments, in the spirit of the filters package.

A filter is a named expression bound to a target dataset. Filters are defined once, kept in a package level registry for the length of the R session, and applied later to select trading codes (tickers, symbols) out of a universe, price or signal dataset.

Installation

# install.packages("devtools")
devtools::install()

Usage

library(filters.trade)

# Load the starter definitions shipped in inst/filters.yaml
load_filters(system.file("filters.yaml", package = "filters.trade"))

tickers <- data.frame(
  SYMBOL = c("AAA", "BBB", "CCC"),
  SECTOR = c("Technology", "Energy", "Technology"),
  MARKET_CAP = c(1e11, 5e10, 4e9),
  stringsAsFactors = FALSE
)

prices <- data.frame(
  SYMBOL = c("AAA", "BBB", "CCC"),
  CLOSE = c(10, 20, 30),
  stringsAsFactors = FALSE
)

# Select a single dataset
apply_filter(tickers, "TECH", target = "TICKERS")

# Combine filters with underscores, and propagate the selected codes to
# every other dataset in the list
apply_filter(list(tickers = tickers, prices = prices), "TECH_LARGECAP")

Filters can also be defined in code:

add_filter(
  id = "MEGACAP",
  title = "Mega Cap",
  target = "TICKERS",
  condition = MARKET_CAP >= 2e11
)

Or in a yaml file:

MEGACAP:
  title: Mega Cap
  target: TICKERS
  condition: MARKET_CAP >= 2e11

Trading conventions

Two conventions replace the clinical study conventions of filters:

  • SYMBOL is the column holding the trading code. Override with options(filters.trade.code_col = "ticker").
  • TICKERS is the dataset holding the master list of trading codes. Override with options(filters.trade.code_dataset = "UNIVERSE").

After TICKERS has been filtered, every other dataset is restricted to the trading codes that survived, so a selection made on the universe carries through to prices and signals.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("filters.trade")

0.0.1 by Joe Zhu, 2 months ago


Browse source code at https://github.com/cran/filters.trade


Authors: Joe Zhu [aut, cre]


Documentation:   PDF Manual  


Apache License (>= 2.0) license


Imports yaml

Suggests roxygen2, testthat


See at CRAN