Learn R Programming

⚠️There's a newer version (1.3.7) of this package.Take me there.

Overview

RTL is a purposely designed for traders, analysts and risk practitioners in Commodities and Finance. It also supports delivery of Finance classes from one of the creator also in Academics at the Alberta School of Business.

Send feedback to pcote@ualberta.ca. We welcome feedback, suggestions and collaboration.

Energy Markets Reference Data

  • expiry_table: NYMEX and ICE contracts expiry tables.
  • holidaysOil: Holiday calendars for NYMEX and ICE.
  • tradeCycle: US and Canadian crude oil trading calendars.
  • tickers_eia: Mapping of EIA tickers to crude and refined products markets for building supply demand balances.
  • eiaStorageCap: Historical EIA crude storage capacity by PADD.
  • eiaStocks: Sample data set of EIA.gov stocks for key commodities.
  • cancrudeassays contains historical Canadian crude assays by batch from Crudemonitor. cancrudeassayssum is a summarised average assays version.
  • crudeassaysXOM for all publicly available complete assays in Excel format from ExxonMobil
  • crudeassaysBP for all publicly available complete assays in Excel format from BP

Swap Pricing and Contract Roll Adjustement

  • rolladjust() adjusts continuous contracts returns for roll adjustments using expiry_table.
  • swapCOM() computes Calendar Month Average commodity swap prices.
  • swapInfo() returns all information required to price first line futures contract averaging swap or CMA physical trade, including a current month instrument with prior settlements.
  • swapIRS() computes IRS swap prices.

Charting

  • chart_fwd_curves(): plots historical forward curves, a useful feature to understand the pricing dynamics of a market.
  • chart_zscore() supports seasonality adjusted analysis of residuals, particularly useful when dealing with commodity stocks and/or days demand time series with trends as well as non-constant variance across seasonal periods.
  • chart_eia_steo() and chart_eia_sd() return either a chart or dataframe of supply demand balances from the EIA.
  • chart_spreads() to generate specific contract spreads across years e.g. ULSD March/April. Requires Morninstar credentials.

APIs

Valid credentials for commercial API services are required.

Genscape

Genscape API functions:

  • getGenscapeStorageOil().
  • getGenscapePipeOil().

Morningstar Commodities

Morningstar Marketplace API functions:

  • getPrice(), getPrices() and getCurve() using your own Morningstar credentials. Current feeds included:

    • ICE_EuroFutures and ICE_EuroFutures_continuous.
    • CME_NymexFutures_EOD and CME_NymexFutures_EOD_continuous.
    • CME_NymexOptions_EOD.
    • CME_CbotFuturesEOD and CME_CbotFuturesEOD_continuous.
    • CME_Comex_FuturesSettlement_EOD and CME_Comex_FuturesSettlement_EOD_continuous.
    • LME_AskBidPrices_Delayed.
    • CME_CmeFutures_EOD and CME_CmeFutures_EOD_continuous.
    • CME_STLCPC_Futures.
    • ICE_NybotCoffeeSugarCocoaFutures and ICE_NybotCoffeeSugarCocoaFutures_continuous.
    • Morningstar_FX_Forwards.
    • … see ?getPrice for up to date selection and examples.

GIS Dataset

EIA

  • crudepipelines <- getGIS(url = "https://www.eia.gov/maps/map_data/CrudeOil_Pipelines_US_EIA.zip")
  • refineries <- getGIS(url = "https://www.eia.gov/maps/map_data/Petroleum_Refineries_US_EIA.zip")
  • productspipelines <- getGIS(url = "https://www.eia.gov/maps/map_data/PetroleumProduct_Pipelines_US_EIA.zip")
  • productsterminals <- getGIS(url = "https://www.eia.gov/maps/map_data/PetroleumProduct_Terminals_US_EIA.zip")
  • ngpipelines <- getGIS(url = "https://www.eia.gov/maps/map_data/NaturalGas_InterIntrastate_Pipelines_US_EIA.zip")
  • ngstorage <- getGIS(url = "https://www.eia.gov/maps/map_data/PetroleumProduct_Terminals_US_EIA.zip")
  • nghubs <- getGIS(url = "https://www.eia.gov/maps/map_data/NaturalGas_TradingHubs_US_EIA.zip")
  • lngterminals <- getGIS(url = "https://www.eia.gov/maps/map_data/Lng_ImportExportTerminals_US_EIA.zip")
  • tradeHubs has North Americas crude oil trading hubs (WIP).

Alberta Oil Sands, Petroleum and Natural Gas

  • AB <- getGIS(url = "https://gis.energy.gov.ab.ca/GeoviewData/OS_Agreements_Shape.zip")

Interest Rates

  • usSwapIR: Sample data set output of getIRswapCurve.
  • usSwapCurves: Sample data set output of RQuantlib::DiscountCurve().

Python

A python version of RTL for most functions is available at https://pypi.org/project/risktools/.

Installation

Latest Package devtools::install_github("risktoollib/RTL")

CRAN Stable install.packages("RTL")

Copy Link

Version

Install

install.packages('RTL')

Monthly Downloads

536

Version

1.3.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Philippe Cote

Last Published

November 7th, 2022

Functions in RTL (1.3.0)

futuresMonths

futuresMonths
chart_spreads

Futures contract spreads comparison across years
distdescplot

Summary of distribution properties of a timeseries
fitOU

Fits a Ornstein–Uhlenbeck process to a dataset
efficientFrontier

Markowitz Efficient Frontier
fizdiffs

Randomized data of physical crude differentials
expiry_table

Metadata for expiry of common commodity futures contract.
eia2tidy

EIA API call with tidy output
eiaStocks

Data for EIA weekly stocks
eurodollar

Data for Eurodollar futures contracts
eiaStorageCap

Data for working storage capacity in the US
getPrice

Morningstar Commodities API single call
futuresSpecs

futuresSpecs
getGenscapeStorageOil

Genscape API call for oil storage
fxfwd

Data for USDCAD FX forward rates
getGIS

Extract and convert GIS data from a URL
ref.opt.inputs

Metadata for teaching refinery optimization using a LP model - INPUTS
getGenscapePipeOil

Genscape API call for oil pipelines
promptBeta

Computes betas of futures contracts with respect to the 1st line contract
refineryLP

LP model for refinery optimization
getPrices

Morningstar Commodities API multiple calls
ref.opt.outputs

Metadata for teaching refinery optimization using a LP model - OUTPUTS
ohlc

ohlc
npv

NPV
getCurve

Morningstar Commodities API forward curves
garch

Wrapper for a Garch(1,1) returning either a plot or data.
spot2futConvergence

Data for spot to futures convergence - historical data
%>%

Pipe operator
planets

Data for IR compounding exercises
simMultivariates

Multivariate Normal from historical dataset
simOU

OU process simulation
spot2futCurve

Data for spot to futures convergence - forward curve
steo

steo
holidaysOil

Metadata for NYMEX and ICE holiday calendars
ry

Sample RBC stock price data set
spy

Sample SPY ETF data set
swapIRS

Interest Rate Swap
swapInfo

Commodity Swap details to learn their pricing
simGBM

GBM process simulation
tickers_eia

Metadata of key EIA tickers grouped by products.
tradeStrategyDY

Sample Quantitative Trading strategy
returns

Compute absolute, relative or log returns.
rolladjust

Adjusts daily returns for futures contracts roll
usSwapCurves

Data for US interest rate discounting using zero rates curve.
swapFutWeight

Commodity Calendar Month Average Swap futures weights
swapCOM

Commodity Calendar Month Average Swaps
tradeHubs

GIS Data for Crude Oil Trading Hubs
tradeStrategySMA

Sample Quantitative Trading strategy
simOUJ

OUJ process simulation
simOUt

OU process simulation
tradeStats

Risk-reward statistics for quant trading
tradeCycle

Data for Canadian and US physical crude trading calendars
uso

Sample USO ETF data set
usSwapCurvesPar

Data for US interest rate discounting using zero rates parallel curve.
tradeprocess

Data for teaching the various ways to monetize a market call.
wtiSwap

Data for WTI Calendar Month Average Swap pricing
tsQuotes

Interest Rate Curve Data for RQuantlib .
CRReuro

Cox-Ross-Rubinstein binomial option model
RTL-package

RTL: Risk Tool Library - Trading, Risk, 'Analytics' for Commodities
bond

Bond pricing
chart_PerfSummary

Cumulative performance and drawdown summary.
chart_eia_steo

EIA Short Term Energy Outlook
chart_pairs

Pairwise scatter plots for timeseries
chart_zscore

Z-Score applied to seasonal data divergence
CLc1

CLc1
CLc2

CLc2
cancrudeassays

Data for Canadian crude assays reported by Crude Monitor
crudeassaysXOM

Data for ExxonMobil crude assays
crudeassaysBP

Data for BP crude assays
dflong

Data for commodity prices in a long dataframe format
dfwide

Data for commodity prices in a wide dataframe format
chart_fwd_curves

Plots historical forward curves
crudes

Data for crude assays of 50+ types of crude oil.
CLc1c2

CLc1c2
cancrudeprices

Randomized data for Canadian crude pricing.
chart_eia_sd

EIA weekly Supply Demand information by product group