34 Interactive Time Series
Readings
- Publishing to a Posit server
- dygraphs for R
- timetk R package, especially section 4 about conversion functions
- (optional) Review tidyquant R package used in a previous task
Guided Instruction
- Interactive Graphs using dygraph: you may find the “strawbroom and rebase” section particularly helpful
- 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.
Load both library(tidyverse) and library(dygraphs), installing the latter if needed.
Let’s now pull current stock information from the web using
library(tidyquant)
. The commandtq_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 thetq_get()
function to pull stock price data.- Include only the most recent 5 years worth of data as you wrangle the data
Visualize the stock returns as an interactive graph using
dygraph.
If possible, consider experimenting with some of the bells and whistles available indygraph.
(optional bonus) Evaluate the return of the portfolio as a whole using functions from the
quantmod
package. (quantmod
is installed as a dependent package oftidyquant
. Many of thetidyquant
functions are actually wrappers aroundquantmod
functions and so sometimes navigating the help files requires more effort).Write a paragraph to summarize your findings about the performance of the stocks you chose.
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).