post list
QuantDare
categories
risk management

Playing with Prophet on Financial Time Series (Again)

rcobo

risk management

Seeing the market through the trees

xristica

risk management

Lévy Flights. Foraging in a Finance blog. Part II

mplanaslasa

risk management

Principal Component Analysis

j3

risk management

Exploring Extreme Asset Returns

rcobo

risk management

Playing around with future contracts

J. González

risk management

BETA: Upside Downside

j3

risk management

Returns clustering with k-Means algorithm

psanchezcri

risk management

Predicting Gold using Currencies

libesa

risk management

Inverse ETFs versus short selling: a misleading equivalence

J. González

risk management

Cointegración: Seguimiento sobre cruces cointegrados

T. Fuertes

risk management

Using Decomposition to Improve Time Series Prediction

libesa

risk management

Clasificando el mercado mediante árboles de decisión

xristica

risk management

In less of a Bayes haze…

libesa

risk management

Cointegración

T. Fuertes

risk management

Cópulas: una alternativa en la medición de riesgos

mplanaslasa

risk management

¿Por qué usar rendimientos logarítmicos?

jsanchezalmaraz

risk management

In a Bayes haze…

libesa

risk management

Teoría de Valores Extremos

kalinda

risk management

Playing with Prophet on Financial Time Series

rcobo

09/03/2017

No Comments
Playing with Prophet on Financial Time Series

Two weeks ago, Facebook launched Prophet, an amazing forecasting tool available in Python and R.

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!

prophet

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)
  })
}

Tweet about this on TwitterShare on LinkedInShare on FacebookShare on Google+Email this to someone

add a comment

wpDiscuz