# Quantifying and predicting market behavior

This is a collection of tools for quantifying and predicting market behavior. The dev branch is here. Clone and modify at will; see legal warnings below.

### Variational autoencoder for sequences

The relevant paper is Kingma and Welling. Implementation is in Keras, surprising exactly no-one. To run it:

cd src
./equity_modes.py <start-date> <end-date> <seq-len>


Start date and end date should be in the form yyyymmdd, while the sequence length should be an integer. For any meaningful results remember that trading weeks work in fives; fewer than two weeks of data is kind of meaningless. Most general results in are in the half year range and up.

You can use this model to generate samples from the underlying probability distribution over price paths. In models there are many examples of pre-trained models—ones that start with generator generate price time series. These series are normalized to have unit variance and zero mean; you will have to specify a mean and standard deviation after you get the time series for it to make any sense.

Here’s an example of the distribution over paths generated by the VAE.

### Equity classification

This is a collection of tools to classify sequences of equity prices. Right now it consists of

• A neural net sequence classifier (BinaryClassifierMLP) with varying number of layers, etc. Given a sequence $X(t),...,X(t+n)$, this predicts 1 if $X(t+n+k)&space;-&space;X(t+n+1)&space;>0$, and 0 if $X(t+n+k)&space;-&space;X(t+n+1)&space;\leq&space;0$.

• ensemble_classification.ipynb is a notebook with code to create ensemble classifiers for the same task.

### Interpretable predictions

Often we may want to make a prediction about the future of an asset that, while less accurate than one generated by a neural network or ensemble estimator, is easily interpretable. We have tools to automatically fit an ARIMA model to any asset price and provide a “mean trend” prediction for the next fifty days:

./predict.sh <ticker_name>


This depends on an updated version of R and its forecast and quantmod libraries.

### stat_tools

Just a selection of utilities for working with time series data and tensors.

All work copyright David Rushing Dewhurst 2018-. All rights reserved. You may use this code and associated mathematics for academic work only (and with proper attribution, i.e., a citation); absolutely no use for commercial or revenue-generating purposes is allowed.

Back to my homepage

Back to my github

Github equation rendering done neatly via codecogs, which you should check out.