20161110 quantstrat in seattle
TRANSCRIPT
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
Mining Trading Strategies with R
using quantstrat and R packages
George (Chia-Chi) Chang20161110
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.
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 ?
Learning By HackingLAB / Collaborative Notes / Broadcasting Notes
Sample Codeshttps://github.com/c3h3/quantstrat-seattle-20161110
● 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
Architecture of Trading SystemData -> Signals & Strategy ->
Transaction & Actions -> Rewards & Results
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, … )
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
History of Backtesting with R
PerformanceAnalytics (2007)blotter (2008)
quantstrat (2010)
quantmod 101Hands-on LAB
quantmod 101: getSymbols & ChartSeries
Yahoo! Finance
Yahoo! Finance
PerformanceAnalytics101
Hands-on LAB
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
blottor 101Hands-on LAB
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
quantstrat 101Hands-on LAB
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
Architecture of quantstratcreated by
C.Y. Yen
who is the Founder of RLadies.TW
Basic Concepts of making quantitative trading strategy
What is the only wayto make money from market ?
The Only Way is ... ● Buy Low and Sell High● Trends up: Buy first, then sell● Trends down: Sell first, then buy
Arbitrage or Anti-arbitrageE = pW - (1-p)L - T > 0
Arbitrage or Anti-arbitrageAssum T = 0, WLR = W/L
p > 1 / (1+WLR)
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
quantstrat 102create indicators by yourself
create signals by yourself
quantmod with MLClassification
Principle Component AnalysisClustering
Blindness of MLBlindness from PCA
Blindness from Vector Quantization
The two keysHelp you apply machine learning
in the real world
Can Learn ONLYThrough Real
Practice
Can Learn fromSchool or Practice
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)
Machine could NOT Learn by itself.
It just like a child.It learn by training data !
sometimes would learn badly!
When orange-apple classifier meet an banana?
Two Kind of BacktestingTop-Down & Button-Up
Entry Signal & Price
Timeout SignalStop Price
Exit Signal
After Event:How to evaluate event?
Before Event:How to predict event?
Limit Price
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)
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))
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)
Button-UpProbabilistic Modeling
Exit Signal
After Event:How to evaluate event?
Before Event:How to predict event?
Limit Price
Timeout Signal
Entry Signal & Price
Stop Price
Limit = 0.06 / Stop = 0.02
Limit = 0.06 / Stop = 0.06
Self Introductionand TW.R & MLDM Monday
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)
4 Years agoI read a Book ……
I started a community
Welcome to MLDM Monday
when you visit Taiwan next time !
Welcome to join us !
Thank youfor your attention !