Top Banner
1 Make you trade ideas into AI. Start free. On mobile. Hitoshi Harada CTO [email protected] http://alpaca.ai Chart Pattern Matching in Financial Trading Using RNN http://www.capitalico.com
18

Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

Mar 31, 2018

Download

Documents

vonhan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

1

Make you trade ideas into AI.Start free. On mobile.

Hitoshi [email protected]://alpaca.ai

Chart Pattern Matching in Financial Trading Using RNN

http://www.capitalico.com

Page 2: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

Entry Point

What Technical Traders Are Looking For 2

Page 3: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

Diversit y Of The Pattern - Al l Downtrend 3

Page 4: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

• Fuzzy Pattern Recognition for everyone • Generalization (no hand crafted features) • Multiple time series (OHLC price + indicators) • Time scale, value scale, distortion

James N.K. Liu *, Raymond W.M. Kwong : Automatic extraction and identification of chart patterns towards financial forecast, 2006

Problem And Needs - Fuzzy Pattern Recognit ion

Zhe Zhang, Jian Jiang, Xiaoyan Liu, Ricky Lau, Huaiqing Wang, Rui Zhang: A Real Time Hybrid Pattern Matching Scheme for Stock Time Series, 2010

4

Page 5: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

How To Solve The Problem? 5

SPEECH RECOGNITION WITH DEEP RECURRENT NEURAL NETWORKS, Hinton, et al. 2013 Capitalico

“ah” “p” “down trend”

Page 6: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

Interactive Training Data Col lect ion & Training 6

Page 7: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

• Train by what you see & judge • No programming nor

conditional setting, but purely from charts like traders do

• Multi-dimensional input • Not only the single time-

series data of price movement but also various indicators altogether

Our Approach - Fuzzy Pattern Recognit ion without Programming 7

Page 8: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

• Network • Input:

• N-dim Fully Connected Layer • LSTM Layer x 2 or 4 ( x250 units ) • Fully Connected Layer ( x250 units ) • Dropout • Sigmoid • Output:

• 1-dim confidence level

• Training • Align with fixed number of candles • Mean squared error for loss • AdaDelta for optimizer • BPTT through aligned length

• Data • 1k+ samples collected by experts • about hundred instances for each strategy

Input

LSTM

LSTM

Fully Connected

Output

Fully Connected

Time

Experiments Deep Learning Based Approach 8

Sigmoid

Input

LSTM

LSTM

Fully Connected

Output

Fully Connected

Sigmoid

Input

LSTM

LSTM

Fully Connected

Output

Fully Connected

Sigmoid

Page 9: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

x-axis: time (1.0=entry point)blue: training data / orange: testing data

Experiments Fitt ing Reasonably

y-ax

is: c

onfid

ence

9

Page 10: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

Experiments Framework 10

Page 11: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

Dropout

• Dropout vs # of training samples

• Bigger Mini-Batches by looping samples

• Made it Adaptive depending on importance

11

dropout enabled (x: iteration count, y: loss)

dropout w/ bigger mini-batches (x: iteration count, y: loss)

Page 12: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

Forget Gate Bias (Learning To Forget: Continual Predict ion With Lstm, Fel ix Et Al .) 12

Page 13: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

Trial And Error To Speed Up Training 13

• Dynamic Dropout

• Dynamic Batchsize

• Multi-GPU Training

• Other Frameworks like Keras

• GRU

• IRNN

• Lot more…

Page 14: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

14

• Previous studies have limitations to difficulty of feature crafting.

• LSTM based deep neural network fits well with individual patterns.

• LSTM-variant doesn’t make much difference, but forget-gate bias,

normalization, preprocessing, and modeling etc. matter

• Build better base model by pre-training

• Reinforcement Learning using profit and risk preference

• Visualize and rationalize LSTM decision making

• Generative Model

Conclusion & Future Work 14

Page 15: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

QUESTIONS AND ANSWERS

http://alpaca.ai / [email protected]

http://www.capitalico.com

Make you trade ideas into AI.Start free. On mobile.

Page 16: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

• Ken-ichi Kainijo and Tetsuji Tanigawa: Stock Price Pattern Recognition - A Recurrent Neural Network Approach -, 1990

• S Hochreiter, J Schmidhuber: Long short-term memory, 1997

• FA Gers, J Schmidhuber, F Cummins: Learning to forget: Continual prediction with LSTM, 2000

• James N.K. Liu *, Raymond W.M. Kwong: Automatic extraction and identification of chart patterns towards financial forecast, 2006

• X Guo, X Liang, X Li: A stock pattern recognition algorithm based on neural networks, 2007

• Z Zhang, J Jiang, X Liu, R Lau, H Wang: A real time hybrid pattern matching scheme for stock time series, 2010

• A Graves, A Mohamed, G Hinton: Speech recognition with deep recurrent neural networks, 2013

• A Graves, N Jaitly: A Mohamed, Hybrid speech recognition with deep bidirectional LSTM, 2013

• Tara N. Sainath, Oriol Vinyals, Andrew Senior, Has¸im Sak: CONVOLUTIONAL, LONG SHORT-TERM MEMORY, FULLY CONNECTED DEEP NEURAL NETWORKS

References 16

Page 17: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

Need For Gpu And Distr ibuted Computation 17

• Model Training

• Takes around 10 minutes on a single GPU core

• Requires 2GB of GPU RAM

• Backtesting

• Calculate various metrics over the historical data

• Livetesting

• Thousands of models need to monitor live candles and update the state of LSTM

Page 18: Chart Pattern Matching in Financial Trading Using RNNon-demand.gputechconf.com/.../s6309-hitoshi-harada-chart-pattern... · Chart Pattern Matching in Financial Trading Using RNN ...

Need For Distr ibuted Computation 18

DB

Postgresql Redis etcd

Load Balancer

WEB

Flask

tesla k80

WORKER

Live

Market Watch

Market Data

Historical Real time

Queue

Celery

Trading

Algos = ~10MB x1-10K