20161110 quantstrat in seattle

60
Today’s Slides https://goo.gl/xkH9QY go to the 5th page and click out all links on the page And reserved your port on the spreadsheet

Upload: chia-chi-chang

Post on 27-Jan-2017

46 views

Category:

Data & Analytics


1 download

TRANSCRIPT

Page 1: 20161110 quantstrat in seattle

Today’s Slideshttps://goo.gl/xkH9QY

go to the 5th page and click out all links on the page

And reserved your port on the spreadsheet

Page 2: 20161110 quantstrat in seattle

Mining Trading Strategies with R

using quantstrat and R packages

George (Chia-Chi) Chang20161110

Page 3: 20161110 quantstrat in seattle

Copyright © 2016 木刻思股份有限公

司. All rights reserved.

Unless otherwise indicated, all materials on these pages are copyrighted by 木刻思股份有限公司. All rights reserved. No part of these pages, either text or image may be used for any purpose other than personal use. Therefore, reproduction, modification, storage in a retrieval system or retransmission, in any form or by any means, electronic, mechanical or otherwise, for reasons other than personal use, is strictly prohibited without prior written permission.

Page 4: 20161110 quantstrat in seattle

Quick Surveys● How many of you use R ? ● How many of you did have some REAL trading experience in financial market

? ● What kind of signals & strategies did you use in trading ? (your intuition is also

one kind of useful signal too)

● Did anyone use MultiChart ? AmiBroker ? Interactive Broker APIs ?● Did anyone use quantmod ? blotter ? quantstrat ?

Page 5: 20161110 quantstrat in seattle

Learning By HackingLAB / Collaborative Notes / Broadcasting Notes

Page 6: 20161110 quantstrat in seattle

Sample Codeshttps://github.com/c3h3/quantstrat-seattle-20161110

Page 7: 20161110 quantstrat in seattle

● Quick Surveys● Architecture of Trading System● [Hands-on] quantmod 101● History of Backtesting with R

○ [Hands-on] PerformanceAnalytics 101○ [Hands-on] blotter 101○ [Hands-on] quantstrat 101

● Basic Concepts of Quantitative Trading● [Hands-on] quantstrat 102● [Hands-on] quantmod with ML● Blindness of ML● Two kind of Backtesting● Self Introduction & TW.R & MLDM Monday

Outlines

Page 8: 20161110 quantstrat in seattle

Architecture of Trading SystemData -> Signals & Strategy ->

Transaction & Actions -> Rewards & Results

Page 9: 20161110 quantstrat in seattle

Architecture of Trading System● Data

○ Real-time Data○ Historical Data

● Signals & Strategy○ Rule-Based○ Model-Based○ Human-Based (Intuition-Based)

● Transaction & Actions○ Enter & Exit ○ Long & Short○ Position Sizing

● Rewards & Results○ Win | Lose○ Metrics (winning prob, WLR, DrawDown, … )

Page 10: 20161110 quantstrat in seattle

Real-Time Trading Backtesting & Mining

Real-Time Data

Signals & Strategy

Transactions & Actions

Rewards & Results

Historical Data

Mining Strategies & Objectives

(human brain)

Indicators & Signals & Action Rules(Bottom-Up Versus Top-Down)

Strategy Metrics & Backtesting Results

Parameter Search & Optimization

Final Results & Strategy

Page 11: 20161110 quantstrat in seattle

History of Backtesting with R

PerformanceAnalytics (2007)blotter (2008)

quantstrat (2010)

Page 12: 20161110 quantstrat in seattle

quantmod 101Hands-on LAB

Page 13: 20161110 quantstrat in seattle

quantmod 101: getSymbols & ChartSeries

Page 14: 20161110 quantstrat in seattle

Yahoo! Finance

Page 15: 20161110 quantstrat in seattle

Yahoo! Finance

Page 16: 20161110 quantstrat in seattle

PerformanceAnalytics101

Hands-on LAB

Page 17: 20161110 quantstrat in seattle

PerformanceAnalytics:● Data Retrieving & Technical Indicator

○ quantmod:: getSymbol○ quantmod:: ChartSeries○ TTR:: SMA

● Performance analysis○ PerformanceAnalytics:: CalculateReturns○ PerformanceAnalytics::charts.PerformanceSummary○ PerformanceAnalytics::chart.RollingPerformance○ chart.RelativePerformance○ PerformanceAnalytics::chart.Drawdown○ PerformanceAnalytics::chart.RiskReturnScatter○ PerformanceAnalytics::SharpeRatio○ PerformanceAnalytics::VaR

Page 18: 20161110 quantstrat in seattle

blottor 101Hands-on LAB

Page 19: 20161110 quantstrat in seattle

Blotter Important Functions: ● initializtion:

○ blotter::initPort○ blotter::initAcct

● simulation:○ blotter::addTxn○ blotter::updatePortf○ blotter::updateAcct○ blotter::updateEndEq○ blotter::getPosQty

● plot & summary:○ blotter::chart.Posn○ blotter::chart.ME○ blotter::PortfReturns○ blotter::getAccount○ blotter::getPortflio○ blotter::getTxns○ blotter::tradeStats

Page 20: 20161110 quantstrat in seattle

quantstrat 101Hands-on LAB

Page 21: 20161110 quantstrat in seattle

Quantstrat: ● init strategy object:

○ quantstrat::strategy

● define strategies:○ quantstrat::add.indicator○ quantstrat::add.signal○ quantstrat::add.rule

● Execution in Backtesting Process:○ quantstrat::sigCrossover○ quantstrat::sigComparison○ quantstrat::ruleSignal○ quantstrat::addOrder

● get Strategy & Order Book○ quantstrat::getStrategy○ quantstrat::getOrderBook

Page 22: 20161110 quantstrat in seattle

Architecture of quantstratcreated by

C.Y. Yen

who is the Founder of RLadies.TW

Page 23: 20161110 quantstrat in seattle

Basic Concepts of making quantitative trading strategy

Page 24: 20161110 quantstrat in seattle

What is the only wayto make money from market ?

Page 25: 20161110 quantstrat in seattle

The Only Way is ... ● Buy Low and Sell High● Trends up: Buy first, then sell● Trends down: Sell first, then buy

Page 26: 20161110 quantstrat in seattle

Arbitrage or Anti-arbitrageE = pW - (1-p)L - T > 0

Page 27: 20161110 quantstrat in seattle

Arbitrage or Anti-arbitrageAssum T = 0, WLR = W/L

p > 1 / (1+WLR)

Page 28: 20161110 quantstrat in seattle

Signals in Trading System● Entry Signals

○ Primary Signals○ Filters

● Exit Signals○ Stop Signals○ Limit Signals○ Time-out Signals○ Filters

Stop Price

Limit Price

Exit Signal

Timeout Signal

Entry Signal & Price

Signal Filters

Page 29: 20161110 quantstrat in seattle

quantstrat 102create indicators by yourself

create signals by yourself

Page 30: 20161110 quantstrat in seattle

quantmod with MLClassification

Principle Component AnalysisClustering

Page 31: 20161110 quantstrat in seattle

Blindness of MLBlindness from PCA

Blindness from Vector Quantization

Page 32: 20161110 quantstrat in seattle
Page 33: 20161110 quantstrat in seattle
Page 34: 20161110 quantstrat in seattle
Page 35: 20161110 quantstrat in seattle
Page 36: 20161110 quantstrat in seattle
Page 37: 20161110 quantstrat in seattle
Page 38: 20161110 quantstrat in seattle
Page 39: 20161110 quantstrat in seattle
Page 40: 20161110 quantstrat in seattle
Page 41: 20161110 quantstrat in seattle

The two keysHelp you apply machine learning

in the real world

Page 42: 20161110 quantstrat in seattle

Can Learn ONLYThrough Real

Practice

Can Learn fromSchool or Practice

Page 43: 20161110 quantstrat in seattle

Modeling Procedures:● Choose a Real Problem● Collecting Related Data● Choose a method convert Data to Vectors (or Tensors)● Decompose Real Problem into several ML or Math Problems● Solve each ML or Math Problem individually ● Combine the Solutions of all ML or Math Problems● Check is that truly solve the Real Problem ?

(ref: Moving Forward through the Darkness)

Page 44: 20161110 quantstrat in seattle

Machine could NOT Learn by itself.

It just like a child.It learn by training data !

sometimes would learn badly!

Page 45: 20161110 quantstrat in seattle

When orange-apple classifier meet an banana?

Page 46: 20161110 quantstrat in seattle

Two Kind of BacktestingTop-Down & Button-Up

Page 47: 20161110 quantstrat in seattle

Entry Signal & Price

Timeout SignalStop Price

Exit Signal

After Event:How to evaluate event?

Before Event:How to predict event?

Limit Price

Page 48: 20161110 quantstrat in seattle

Entry Signal & Price

Timeout SignalStop Price

Exit Signal

Before Event:How to predict event?

Limit Price

X Y

After Event:How to evaluate event?

Button-Up: P(e(Y)|X)

Page 49: 20161110 quantstrat in seattle

Entry Signal & Price

Timeout SignalStop Price

Exit Signal

Before Event:How to predict event?

Limit Price

X Y

After Event:How to evaluate event?

Top-Down: P(X|e(Y))

Page 50: 20161110 quantstrat in seattle

Entry Signal & Price

Timeout SignalStop Price

Exit Signal

Before Event:How to predict event?

Limit Price

X Y

After Event:How to evaluate event?

ML & DL: Y = f(X)

Page 51: 20161110 quantstrat in seattle

Button-UpProbabilistic Modeling

Page 52: 20161110 quantstrat in seattle

Exit Signal

After Event:How to evaluate event?

Before Event:How to predict event?

Limit Price

Timeout Signal

Entry Signal & Price

Stop Price

Page 53: 20161110 quantstrat in seattle

Limit = 0.06 / Stop = 0.02

Page 54: 20161110 quantstrat in seattle

Limit = 0.06 / Stop = 0.06

Page 55: 20161110 quantstrat in seattle
Page 56: 20161110 quantstrat in seattle

Self Introductionand TW.R & MLDM Monday

Page 57: 20161110 quantstrat in seattle

About Chia-Chi (George) ● Organizer of Taiwan R User Group and MLDM Monday● 7 years experience in quantitative trading in future & option market● 5 years consultant experience in machine learning & data mining● 4 years experience in e-commerce (consultant & join SaaS teams)● 4 years experience in building of recommendation and search engine ● Volunteer in PyCon APAC 2014 (program officer)● Volunteer in PyCon APAC 2015 (program officer)

Page 59: 20161110 quantstrat in seattle

Welcome to MLDM Monday

when you visit Taiwan next time !

Welcome to join us !

Page 60: 20161110 quantstrat in seattle

Thank youfor your attention !