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())