Winton Kaggle Competition

Zachary Escalante
Posted on Jun 30, 2016

Contributed by Zach Escalante. He  is currently in the NYC Data Science Academy 12 week full time Data Science Bootcamp program taking place between April 11th to July 1st, 2016. This post is based on his final class project - Capstone (due on the 12th week of the program)

Introduction

This Capstone project was an exciting opportunity for me to implement a sampling of the many machine learning techniques we as a bootcamp have been practicing for these past 12 weeks.

For my final project, I settled on working on a data set that was part of a Kaggle competition posted by Winton Capital Management which closed several months ago. I chose this specific competition because it addressed the difficult task of predicting time series. This is a very relevant problem for the financial industry (how to model asset returns, which are usually a stationary process) and one which I wanted to tackle with a plethora of new tools at my disposal. One of the important questions regarding stationary processes for financial data sets deals with outlier detection. Is it possible to implement a model that can predict (or even give a hint) as to when to expect a large movement either up or down in an asset? We very recently had a prime example of this with the UK voting to leave the EU.

Here we see the Hi Yield credit default index dropped in excess of two points overnight:

 

Screen Shot 2016-06-26 at 11.29.48 AM

The British Pound set record lows in a matter of hours versus the US dollar:

Screen Shot 2016-06-26 at 11.28.29 AM

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

These recent events highlight the necessity of being able to model time series to the best of our ability, which is why I chose this project to work on for my Capstone.

The Competition:

The Kaggle competition provided a training data set that contained 40,000 rows and 211 columns. Each row represented an observation of an asset (these could have been stocks, currencies, commodities or bonds - for linguistic ease and simplification, we will refer to them as stocks), and each column was a variable. Our first columns 2-26 were data features, the next two columns (27 & 28) were the T-2 and T-1 returns, after that we had 180 single-minute returns for the current day, followed by T+1 and T+2 returns and the two weight columns. Our goal for the competition as to use the features, T-2, T-1 and the first 120 minutes worth of returns to predict the next 60 minutes of returns and the T+1 and T+2 returns.

 

Screen Shot 2016-06-26 at 11.16.37 AM

In order to score the predictions, the contestants had to minimize the Weighted Mean Average Error:
Screen Shot 2016-06-26 at 11.01.09 AM

This meant taking each prediction and taking the difference between the prediction and the actual values and multiplying them by the respective weight. Then we sum these weights and divide by the number of observations to find the WMAE. To give some context or the difficulty of this data set, with over 800 people submitting predictions to be scored, a prediction of straight zeros (so no predictions whatsoever) would have been the 323rd best score on the leaderboard.

The Approach

My approach was to run two different models on the data set: one to predict the minute returns and the other to predict the T+1 and T+2 returns. For the T+1 and T+2 returns, I decided to use an XGBoost with stacking, due to this method's reputation for accuracy. For the minute returns, I settled on something I found in research, an Echo State Network model (a specific type of Recurrent Neural Net).

Echo State Network

A Recurrent Neural Network (RNN) is a type of Neural Network (NN) that can recursively call the output from a hidden layer of neurons and use that information to feed back into that same layer of neurons (1).

recurrent_neural_network

This is different than a feedforward structure in a typical NN where the output of each neuron on layer N feeds to each neuron in layer N+1 (dependent on whether the signal to that neuron have been triggered or not).

feedforward

The Echo State Network (ESN) is a special type of the RNN where all of the weights assigned to the input vector and the pre-specified hidden layers are randomly assigned and only the last layer's output regression weights are trained (2).

Screen Shot 2016-06-26 at 12.36.38 PM

The inputs to the ESN are summarized in this graphic

Screen Shot 2016-06-30 at 6.25.07 PM

Where the update equations are as follows

Screen Shot 2016-06-26 at 12.36.21 PM

and the final outputs are this

Screen Shot 2016-06-26 at 12.36.28 PM

The algorithm is run as follows:

Screen Shot 2016-06-30 at 6.31.33 PM

I chose an ESN to analyze the 60 individual minute returns of our data set for the simple reason that the recurrent nature of the network helps it to handle time series quite well (3). The ESN Algorithm has three main parameters to tune: the reservoir size (size of our hidden layer matrix), the spectral radius (this scales the weights of the reservoir matrix) and alpha, the leaking rate.

XGBoost

An XGBoost with stacking has historically performed very well for many people competing in Kaggle competitions. Due to the prolificacy of the XGBoost algorithm, I will focus on the practical implementation steps in after the data was cleaned and our missingness addressed in R:

  1. Fit a sparse model matrix to our data frame Screen Shot 2016-06-30 at 7.17.49 PM
  2. Run a Matrix
    Screen Shot 2016-06-30 at 7.19.32 PM
  3. Set the parameters

Screen Shot 2016-06-30 at 7.25.30 PM4. Train our model

Screen Shot 2016-06-30 at 7.27.28 PM

The tuning parameters that I found to give the greatest accuracy for my XGBoost model was grounds = 500, a max_depth = 9, and an eta = 0.1.

Results

For my ESN model, I optimized the parameters according to the minimization of the WMAE function. In order to determine whether our model was an improvement over our benchmark (guessing zero for each return), I graphed the WMAE of our model predictions over a subset of our training data:

Reservoir Size

Screen Shot 2016-06-26 at 3.36.54 PM

We can see here that a reservoir size of 130 is the reservoir size that gets the closes to beating our benchmark.

Spectral Radius

Screen Shot 2016-06-26 at 4.05.15 PM

After choosing my spectral radius, I settled on a radius factor of 1.25 value which once again, gets me the closest to beating our zero benchmark.

Alpha Parameter: Leaking Rate

Screen Shot 2016-06-26 at 3.20.38 PM

Lastly I tuned the alpha parameter and was unable to beat a zero benchmark. Unfortunately this meant that Echo State Network failed to add predictive accuracy to my data set. The main reason for this I believe is that the model was only able to learn for 120 observations for each stock. This is not nearly enough training data as per the examples I encountered in order to gain predictive power. Other examples I saw has a minimum of several thousand observations.

Considering that adding the predictions including the individual minute returns would only increase my WMAE and decrease my final submission rank, I chose to only submit my T+1 returns using an XGBoost:

Screen Shot 2016-06-26 at 4.12.08 PM

My final rank was a 747th on the leaderboard.

Improvements and Future Work

In order to improve my XGBoost algorithm, I need to spend more time analyzing important variables and tuning my XGBoost. I'm confident that with more time dedicated to these steps, I could break through the 0-guess benchmark that placed in the top 50% of all submissions.

The more interesting part to me is exploring how to create an ESN algorithm that can both capture the pattern,  and in predict the movements of a stationary time series data set. Research in this area is limited, but preliminary results indicate this is possible. I believe that financial assets (stocks, bonds, currencies - I realize these are not all technically 'assets', but they would still suffice) with long time series histories and multiple potential explanatory variables would be a promising data bank to work from.

Thank you for taking the time to read this blog. If you have additional questions or comments, feel free to reach out to me at [email protected]

References:

(1) http://blog.josephwilk.net/ruby/recurrent-neural-networks-in-ruby.html

(2) http://minds.jacobs-university.de/sites/default/files/uploads/papers/PracticalESN.pdf

(3) http://minds.jacobs-university.de/ESNresearch

 

About Author

Zachary Escalante

Zachary Escalante

Zach Escalante's path to the field of Data Analysis has not been a conventional one. Born and raised in South Florida, Zach did his first bachelor's degree in Finance at Florida Atlantic University (FAU). Following the completion of...
View all posts by Zachary Escalante >

Related Articles

Leave a Comment

No comments found.

View Posts by Categories


Our Recent Popular Posts


View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp