Learn R Programming

RTL (version 1.3.0)

chart_spreads: Futures contract spreads comparison across years

Description

Plots specific contract pairs across years with time being days from expiry.

Usage

chart_spreads(
  cpairs = cpairs,
  daysFromExpiry = 200,
  from = "2012-01-01",
  conversion = c(1, 1),
  feed = "CME_NymexFutures_EOD",
  iuser = "x@xyz.com",
  ipassword = "pass",
  title = "March/April ULSD Nymex Spreads",
  yaxis = "$ per bbl",
  output = "chart"
)

Value

A plotly object or a dataframe

Arguments

cpairs

Data frame of contract pairs - see example.

daysFromExpiry

Number of days (numeric) from expiry to compute spreads.

from

From date as character string

conversion

Defaults to c(1,1) first and second contracts. 42 from $ per gallons to bbls.

feed

Morningstar Feed Table.

iuser

Morningstar user name as character - sourced locally in examples.

ipassword

Morningstar user password as character - sourced locally in examples.

title

Title for chart.

yaxis

y-axis label.

output

"chart" for plotly object or "data" for dataframe.

Author

Philippe Cote

Examples

Run this code
if (FALSE) {
cpairs <- dplyr::tibble(
  year = c("2014", "2019", "2020"),
  first = c("@HO4H", "@HO9H", "@HO0H"),
  second = c("@CL4J", "@CL9J", "@CL0J")
)
chart_spreads(
  cpairs = cpairs, daysFromExpiry = 200, from = "2012-01-01",
  conversion = c(42, 1), feed = "CME_NymexFutures_EOD",
  iuser = "x@xyz.com", ipassword = "pass",
  title = "March/April ULSD Nymex Spreads",
  yaxis = "$ per bbl",
  output = "data"
)
}

Run the code above in your browser using DataLab