Commodities - commodities

Data - Investing

Info

Code
i_g("bib/ukraine/soyuz-kourou-1.png")

Nobs

Code
commodities_var |>
  select(name, full_name) |>
  right_join(commodities |>
               rename(name = commodity) |>
               group_by(name) |>
               summarise(Nobs = n(),
                         value1 = last(Close)), by = "name") |>
  arrange(-Nobs) %>%
  {if (is_html_output()) datatable(., filter = 'top', rownames = F) else .}

Crude Oil WTI, Rough Rice, US Wheat

2000-

Code
commodities |>
  filter(commodity %in% c("Rough Rice", "US Wheat", "Crude Oil WTI"),
         Date >= as.Date("2000-01-01")) |>
  group_by(commodity) |>
  mutate(Close = 100*Close/Close[Date == as.Date("2011-01-19")]) |>
  ggplot() + geom_line(aes(x = Date, y = Close, color = commodity)) + 
  theme_minimal() + xlab("") + ylab("Index (100 = 2007)") +
  scale_x_date(breaks = seq(1960, 2100, 2) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_log10(breaks = seq(20, 500, 20)) +
  scale_color_commodity() +
  theme(legend.position = c(0.15, 0.9),
        legend.title = element_blank())

2010-

Code
commodities |>
  filter(commodity %in% c("Rough Rice", "US Wheat", "Crude Oil WTI"),
         Date >= as.Date("2010-01-01")) |>
  group_by(commodity) |>
  mutate(Close = 100*Close/Close[Date == as.Date("2011-01-19")]) |>
  ggplot() + geom_line(aes(x = Date, y = Close, color = commodity)) + 
  theme_minimal() + xlab("") + ylab("Index (100 = 2007)") +
  scale_x_date(breaks = seq(1960, 2100, 2) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_log10(breaks = seq(20, 500, 20)) +
  scale_color_commodity() +
  theme(legend.position = c(0.15, 0.9),
        legend.title = element_blank())

2017-

Code
commodities |>
  filter(commodity %in% c("Rough Rice", "US Wheat", "Crude Oil WTI"),
         Date >= as.Date("2017-01-01")) |>
  group_by(commodity) |>
  mutate(Close = 100*Close/Close[Date == min(Date)]) |>
  ggplot() + geom_line(aes(x = Date, y = Close, color = commodity)) + 
  theme_minimal() + xlab("") + ylab("Index (100 = 2007)") +
  scale_x_date(breaks = seq(1960, 2100, 1) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_log10(breaks = seq(20, 500, 20)) +
  scale_color_commodity() +
  theme(legend.position = c(0.15, 0.9),
        legend.title = element_blank())

2000-2016

Code
commodities |>
  filter(commodity %in% c("Rough Rice", "US Wheat", "Crude Oil WTI"),
         Date >= as.Date("2000-01-01"),
         Date <= as.Date("2016-01-01")) |>
  group_by(commodity) |>
  mutate(Close = 100*Close/Close[Date == as.Date("2011-01-19")]) |>
  ggplot() + geom_line(aes(x = Date, y = Close, color = commodity)) + 
  theme_minimal() + xlab("") + ylab("Index (100 = 2007)") +
  scale_x_date(breaks = seq(1960, 2100, 1) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_log10(breaks = seq(20, 500, 20)) +
  scale_color_commodity() +
  theme(legend.position = c(0.15, 0.9),
        legend.title = element_blank())

Gold, Cocoa

Code
commodities |>
  filter(commodity %in% c("Gold", "US Cocoa")) |>
  ggplot() + geom_line(aes(x = Date, y = Close, color = commodity)) + 
  theme_minimal() + xlab("") + ylab("Price") +
  scale_x_date(breaks = seq(1960, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_log10(breaks = seq(0, 20000, 1000),
                labels = dollar_format(accuracy = 1)) +
  scale_color_commodity() +
  theme(legend.position = c(0.25, 0.9),
        legend.title = element_blank())

Copper, Heating Oil

Code
commodities |>
  filter(commodity %in% c("Copper", "Heating Oil"),
         Open >= 0.001) |>
  ggplot() + geom_line(aes(x = Date, y = Close, color = commodity)) +
  theme_minimal() + xlab("") + ylab("Price") +
  scale_x_date(breaks = seq(1960, 2100, 2) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_log10(breaks = seq(0, 10, 1),
                labels = dollar_format(accuracy = 1)) +
  scale_color_commodity() +
  theme(legend.position = c(0.25, 0.9),
        legend.title = element_blank())

Code
commodity_chart <- function(sel, from = NULL, ylab = "Prix", log = FALSE,
                             legend_pos = "bottom") {
  d <- commodities |> filter(commodity %in% sel)
  if (!is.null(from)) d <- d |> filter(Date >= as.Date(from))

  g <- d |>
    ggplot() + geom_line(aes(x = Date, y = Close, color = commodity)) +
    theme_minimal() + xlab("") + ylab(ylab) +
    scale_x_date(date_labels = "%Y") +
    scale_color_commodity() +
    theme(legend.position = legend_pos, legend.title = element_blank())
  if (log) g <- g + scale_y_log10()
  g
}

Métaux précieux : Argent, Platine, Palladium

Depuis 2009

Code
commodity_chart(c("Silver", "Platinum", "Palladium"), from = "2009-10-14",
                 ylab = "$ / once", log = TRUE)

Depuis 2020

Code
commodity_chart(c("Silver", "Platinum", "Palladium"), from = "2020-01-01",
                 ylab = "$ / once")

Métaux industriels (LME) : Étain, Nickel, Plomb, Zinc

Le cuivre coté sur cette page (Copper, contrat COMEX) est en $/livre, pas en $/tonne comme les autres métaux du LME ci-dessous — voir la comparaison avec le fioul dans la section “Copper, Heating Oil” plus haut.

Depuis 2008

Code
commodity_chart(c("Zinc", "Lead", "Nickel", "Tin"), from = "2008-07-07",
                 ylab = "$ / tonne", log = TRUE)

Depuis 2016 (avec l’aluminium)

Code
commodity_chart(c("Aluminum", "Zinc", "Lead", "Nickel", "Tin"),
                 from = "2016-11-21", ylab = "$ / tonne", log = TRUE)

Céréales et oléagineux : Maïs, Blé, Soja, Avoine

Depuis 1990

Code
commodity_chart(c("US Corn", "US Wheat", "US Soybeans"), from = "1990-01-02",
                 ylab = "Cents / boisseau")

Depuis 2008 (avec l’avoine)

Code
commodity_chart(c("US Corn", "US Wheat", "US Soybeans", "Oats"),
                 from = "2008-07-15", ylab = "Cents / boisseau")

Depuis 2020

Code
commodity_chart(c("US Corn", "US Wheat", "US Soybeans", "Oats"),
                 from = "2020-01-01", ylab = "Cents / boisseau")

Softs (New York) : Café, Sucre, Coton

Depuis 2009

Code
commodity_chart(c("US Coffee C", "US Sugar #11", "US Cotton #2"),
                 from = "2009-10-14", ylab = "Cents / livre", log = TRUE)

Depuis 2020

Code
commodity_chart(c("US Coffee C", "US Sugar #11", "US Cotton #2"),
                 from = "2020-01-01", ylab = "Cents / livre", log = TRUE)

Bétail : Bovins vifs, Bovins maigres, Porcs

Depuis 2013

Code
commodity_chart(c("Live Cattle", "Feeder Cattle", "Lean Hogs"),
                 from = "2013-08-09", ylab = "Cents / livre")

Depuis 2020

Code
commodity_chart(c("Live Cattle", "Feeder Cattle", "Lean Hogs"),
                 from = "2020-01-01", ylab = "Cents / livre")