Have you heard about the new Facebook Research project? In February 2017, the giant social network launched Prophet, an amazing forecasting tool available in Python and R. And it looks that you can play with it by using financial time series.
Here’s a bit of info from the Facebook research website:
“Forecasting is a data science task that is central to many activities within an organization. For instance, large organizations like Facebook must engage in capacity planning to efficiently allocate scarce resources and goal setting in order to measure performance relative to a baseline. Producing high quality forecasts is not an easy problem for either machines or for most analysts. We have observed two main themes in the practice of creating a variety of business forecasts:
- Completely automatic forecasting techniques can be brittle and they are often too inflexible to incorporate useful assumptions or heuristics.
- Analysts who can produce high-quality forecasts are quite rare because forecasting is a specialized data science skill requiring substantial experience.
The result of these themes is that the demand for high-quality forecasts often far outstrips the pace at which analysts can produce them. This observation is the motivation for our work building Prophet: we want to make it easier for experts and non-experts to make high-quality forecasts that keep up with demand. […]”
I work with a specific type of time series: Financial time series. These have specific characteristics that make them especially difficult. When I first read about the new Facebook Prophet tool, I thought it would be great to test it out on financial time series (for example: stock prices, ETF prices, mutual funds prices…), just to see what would happen.
This post provides a first look at Prophet, using financial time series from Yahoo Finance through a shiny app.
Hope you enjoy, and don’t forget to comment on this post if you find anything interesting!
Thanks:
Sean J. Taylor, Ben Letham, and all the team
Links:
– Research Facebook Prophet
– Github
– Prophet R package
Code:
ui.r
fluidPage( titlePanel("Playing with Prophet on Financial Time Series"), fluidRow( column(3, wellPanel( h3("Prophet: Automatic Forecasting Procedure"), sliderInput("lookback", "Train window size (months):", min = 12, max = 60, value = 36, step = 1), sliderInput("forward", "Forecast window size (months):", min = 1, max = 12, value = 6, step = 1), textInput("sym", "Symbol (Yahoo Finance!)", "FB"), checkboxInput("seasonal","Add yearly seasonal factor:", FALSE) )), column(6, plotOutput("plot1", width = 1200, height = 900) ) ) )
server.r
library(prophet) library(quantmod) library(data.table) function(input, output) { output$plot1 <- renderPlot({ mydf <- getSymbols(input$sym, src = "yahoo", from = Sys.Date()-(input$lookback*30), to = Sys.Date(), auto.assign = FALSE) mydf <- data.frame(mydf[,6]) mydf <- copy(mydf) setDT(mydf, keep.rownames = TRUE) colnames(mydf)<- c("ds", "y") m <- prophet(mydf,yearly.seasonality = input$seasonal, weekly.seasonality = FALSE) future <- make_future_dataframe(m, periods = input$forward*30) forecast <- predict(m, future) plot(m, forecast) }) }