download.file(url = "https://pubs.usgs.gov/sir/2012/5188/tables/tungsten.xlsx", destfile = "tungsten.xlsx")
tungsten <- import("https://pubs.usgs.gov/sir/2012/5188/tables/tungsten.xlsx", skip = 2)
## New names:
## * `` -> ...2
head(tungsten); tail(tungsten)
##   Year ...2 Price
## 1 1959   NA    13
## 2 1960   NA    19
## 3 1961   NA    17
## 4 1962   NA    12
## 5 1963   NA     9
## 6 1964   NA    15
##                                                                                                                                                                                                                   Year
## 54                                                                                                                      Note: Annual average prices were derived from price changes reported in the following sources:
## 55                                                                                                       1959–66, tungsten ore (wolframite) in New York, “ordinary quality,” excluding duty, in American Metal Market.
## 56                           1967–73, tungsten ore, domestic quote reflecting the U.S. Government's General Services Administration price, in American Metal Market's Metal Statistics 1972 and Metal Statistics 1974.
## 57 1974–76, tungsten ore, minimum 65% tungsten trioxide, European market, excluding duty, in U.S. Bureau of Mines Minerals Yearbook, converted from pounds sterling per metric ton unit as reported in Metal Bulletin.
## 58                                                                                                      1977–88, tungsten ore, minimum 65% tungsten trioxide, U.S. spot price, c.i.f., excluding duty, in Metals Week.
## 59                                                                                                                                             1989–2010, ammonium paratungstate, U.S. free market, in Metal Bulletin.
##    ...2 Price
## 54   NA    NA
## 55   NA    NA
## 56   NA    NA
## 57   NA    NA
## 58   NA    NA
## 59   NA    NA
tungsten[1:2] = NULL
str(tungsten)
## 'data.frame':    59 obs. of  1 variable:
##  $ Price: num  13 19 17 12 9 15 23 38 43 43 ...
tungsten = na.omit(tungsten)
tungsten <- ts(tungsten, start=c(1959), end=c(2010), frequency=1)
cpi = pdfetch::pdfetch_FRED("CPIAUCSL")  #download cpi all
head(cpi)
##            CPIAUCSL
## 1947-01-31    21.48
## 1947-02-28    21.62
## 1947-03-31    22.00
## 1947-04-30    22.00
## 1947-05-31    21.95
## 1947-06-30    22.08
tail(cpi)
##            CPIAUCSL
## 2021-02-28  263.161
## 2021-03-31  264.793
## 2021-04-30  266.832
## 2021-05-31  268.551
## 2021-06-30  270.981
## 2021-07-31  272.265
str(cpi)
## An 'xts' object on 1947-01-31/2021-07-31 containing:
##   Data: num [1:895, 1] 21.5 21.6 22 22 21.9 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr "CPIAUCSL"
##   Indexed by objects of class: [Date] TZ: UTC
##   xts Attributes:  
##  NULL
plot(cpi)

cpi.ts = ts(cpi, start = c(1947,1), end = c(2021,7), frequency = 12)
cpi.annual = window(cpi.ts, start = c(1959,1), end = c(2010, 12), frequency = 1)
tungstenr <- tungsten/cpi.annual * 100
autoplot(tungsten) + autolayer(cpi.annual) + 
  ggtitle("Inflation Impact")

autoplot(tungstenr) + ggtitle("Real price of Tungsten")

dygraphs::dygraph(tungstenr, main = "Real Price of Tungsten", 
                  ylab = "Price") %>%
  dyOptions(
    fillGraph=TRUE, 
    drawGrid = FALSE, 
    colors="#C0413B") %>%
  dyRangeSelector() %>%
  dyCrosshair(direction = "vertical") %>%
  dyHighlight(
    highlightCircleSize = 5, 
    highlightSeriesBackgroundAlpha = 0.5, 
    hideOnMouseOut = FALSE
  ) 
tungcpi <- cbind(tungsten, cpi.annual)
dygraphs::dygraph(tungcpi, main = "Nominal Price of Tungsten", 
                  ylab = "Price") %>%
  dyOptions(
    fillGraph=TRUE, 
    drawGrid = FALSE, 
    colors="#57291F") %>%
  dyRangeSelector() %>%
  dyCrosshair(direction = "vertical") %>%
  dyHighlight(
    highlightCircleSize = 5, 
    highlightSeriesBackgroundAlpha = 0.5, 
    hideOnMouseOut = FALSE
  )  

In last week’s code you wrote that the wager was intended to see if, “The inflation-adjusted prices would decrease rather than increase”. While I am not sure if I did the inflation calculation correctly, I found this to be mostly true. In the seventies, it appears as though the prices that were adjusted for inflation are much larger than the nominal prices. I first chose the year 1977 to compare the nominal and inflation-adjusted prices, and since the real price is 253.83 and the nominal price is 149, I thought the wager was incorrect. I then decided to take a look at the years 1990 and 2006 to see if this had stayed the same, but I soon realized it was the opposite: the nominal prices were higher than the real price. So it appears that the wager is in fact true.