Previous chapter
Case StudiesCrypto Currencies
Next chapter

Crypto Currencies

Plotting Crypto Currencies using the tidyverse.

Questions

  1. Load object data/06-plotting-06.rda
  2. Plot Time Series line chart using ggplot()
    • Use gather() reformat the data.frame from wide to long format using Date as id variable.
    • Use facet_grid() to plot to different panels, adjust parameter scales.
    • Remove x-axis label (xlab()) for each plot, set y-axis label to USD.
  3. What do we observe? Hint: Zoom to time frame where no NA's are present (e.g. from 2017-07-01) or consider na.omit() before step 2.
  4. Plot relative performances by indexing each coin to 100 at the start, adjust y-axis as necessary. Use scale_y_continuous(labels = scales::percent) to format y-axis as percent.
  5. Which coin performed best in percentage terms? Use absolute performance numbers from 4. and show the absolute performance numbers for each coin on the last observation day.
  6. Select performances for the first day of each month output the resulting table. Hint Use filter() with floor_date to filter rows for the start of each month. Bonus: Calculate the MOM returns using group_by(coin) and mutate() to calculate the difference price_adj - lag(price_adj).

1. Read Data

load(file = "data/06-plotting-06.rda")

2. Plot Time Series

3. Zoom

4. Performance Plot

Hint

  1. Extract values from 2017-07-01 into a separate data.frame and do a left join by coin.
  2. Divide prices by prices from 2017-07-01

5. Performance Table

Absolute performance on last date:

##         Date.x   BTCUSD   ETHUSD    XRPUSD
## 115 2017-10-23 2.527511 1.128503 0.8322165

Absolute performance on first month of day:

## # A tibble: 4 x 4
##   Date.x     BTCUSD ETHUSD XRPUSD
##   <date>      <dbl>  <dbl>  <dbl>
## 1 2017-07-01   1     1      1    
## 2 2017-08-01   1.16  0.886  0.769
## 3 2017-09-01   2.09  1.54   1.10 
## 4 2017-10-01   1.89  1.20   0.876

MOM Performance

## # A tibble: 4 x 4
##   Date.x     BTCUSD ETHUSD XRPUSD
##   <date>      <dbl>  <dbl>  <dbl>
## 1 2017-07-01 NA     NA     NA    
## 2 2017-08-01  0.161 -0.114 -0.231
## 3 2017-09-01  0.926  0.652  0.328
## 4 2017-10-01 -0.196 -0.333 -0.221