34  Interactive Time Series

Readings

  1. Publishing to a Posit server
  2. dygraphs for R
  3. timetk R package, especially section 4 about conversion functions
  4. (optional) Review tidyquant R package used in a previous task

Guided Instruction

  1. Interactive Graphs using dygraph: you may find the “strawbroom and rebase” section particularly helpful
  2. Financial Time Series

The dygraphs package is an excellent resource for those heading into the finance sector. This will also be a good time to push yourself to learn more about using the tidyqaunt package.

Your data science income has ballooned, and you need to find somewhere to invest money you have saved. You have a savvy investment friend that is kind enough to tell you about some stocks they have been watching during the last year. You will need to visualize the performance of these stocks over the last five years to help in the conversation with your friend.

However, your friend is not going to tell you the stock symbols until the beginning of your half-hour meeting (they are a busy friend). You need to program an .qmd file that will automatically build a suite of visualizations for any stocks they give you.

The dygraphs for R package requires we use an xts objects, rather than a data frame, to plot data. As such, we’ll need a conversion tool, available in the timetk package. You should notice that the xts objects needed to plot multiple stocks on a dygraphs are not tidy.

  1. Load both library(tidyverse) and library(dygraphs), installing the latter if needed.

  2. Let’s now pull current stock information from the web using library(tidyquant). The command tq_get(c("AMZN","MSFT","WMT")) will pull the last 10 years of daily stock information for Amazon, Microsoft, and Walmart. Pick your own set of 3-10 stocks and use the tq_get() function to pull stock price data.

    • Include only the most recent 5 years worth of data as you wrangle the data
  3. Visualize the stock returns as an interactive graph using dygraph.If possible, consider experimenting with some of the bells and whistles available in dygraph.

  4. (optional bonus) Evaluate the return of the portfolio as a whole using functions from the quantmod package. (quantmod is installed as a dependent package of tidyquant. Many of the tidyquant functions are actually wrappers around quantmod functions and so sometimes navigating the help files requires more effort).

  5. Write a paragraph to summarize your findings about the performance of the stocks you chose.

  6. Render the file then publish your report on returns to Posit Connect at posit.byui.edu

Submit

In I-learn submit the link to your Posit Connect file. (Make sure you edit the settings so that instructors and classmates have access to view the file).