R/quantstrat For Fun & Profit Motivation Why R/quantstrat? Overview: The Toolset Data Warehousing with XTS Modeling Backtesting E. Allen (firstname.lastname@example.org) Nov. 4th 2013 Pittsburgh R Users Group Lightning Talk References Jan Humme, Brian Peterson @ R/Finance 2013: http://www.rinfinance.com/agenda/2013/workshop/Humme+Peterson.pdf Guy Yollin, quantstrat/blotter lecture notes: http://www.r-programming.org/papers Blair Hull @ R/Finance 2012: http://www.rinfinance.com/agenda/2012/talk/BlairHull.pdf My Blog: http://ww.biglucre.com/ This presentation focuses on brevity and perceived gaps in more comprehensive resources. Slides will be available. R/quantstrat For Fun & Profit: Motivation Quantitative Trading Motivation • Profit! • But, it’s risky – not good for regular income to pay the rent. Don’t quit your day job – unless you’re working for a group that really knows what they’re doing. • But, it is also interesting! • Not as expensive as you might think to trade –except for High Frequency. R/quantstrat For Fun & Profit: Why R/quantstrat? Why R/quantstrat? • Features – Leveraging framework with much of what commercial packages offer. • Flexibility – Ability to change for own use. • Cost • Used in professional trading firms. • From Blair Hull: xts, xtime, indexing, sde, monomvn, lars, fUnitRoots, fGarch, manova • Proprietary trading firm contributions, even those with large operations. R/quantstrat For Fun & Profit: The Toolset The Toolset (from Humme/Peterson) R/quantstrat For Fun & Profit: The Toolset: quantstrat The Toolset: quantstrat • Part of the TradeAnalytics package • https://r-forge.r-project.org/projects/blotter/ • Not yet available on CRAN (under heavy development) • Installing quantstrat: • http://biglucre.com/environment/ (Linux/from source) • or, you can try: install.packages("quantstrat", repos="http://R-Forge.Rproject.org") R/quantstrat For Fun & Profit: The Toolset: quantstrat The Toolset: quantstrat • Recommended Reading: Trading Systems: A New Approach to System Development and Portfolio Optimisation by Tomasini and Jaekle • This text follows the development and testing of a simple system, Luxor which is featured in several quantstrat demos. R/quantstrat For Fun & Profit: The Toolset: quantstrat Professional+Commercial Tools will provide: 1. Data Warehouse 2. System Development 3. Production Strategy Deployment R/quantstrat can be used for 1 and 2 – maybe 3. R/quantstrat For Fun & Profit: The Toolset: quantstrat Toolset: quantstrat (from Humme/Peterson) R/quantstrat For Fun & Profit: The Toolset: quantstrat Toolset: quantstrat Functional Programming Workflow • Indicators and Signals add columns to mkdata xts object. • Applying a Strategy results in a blotter object that contains trade information, ready for analysis. • More advanced features include optimization methods and parallelization. R/quantstrat For Fun & Profit: Data Warehousing Data Warehousing • Acquire Data • Record from feed (IQFeed, Interactive Brokers) • Purchase (tickdata.com, IQFeed 6-mo backfill) Code for the following forthcoming at www.biglucre.com • Import Data • Use read.csv, convert to xts, name columns for BBO or OHLC data • Use FinancialInstrument SaveSymbols()/getSymbols.FI to • save xts data into daily .rda data files • load/merge subsets of daily data into xts objects R/quantstrat For Fun & Profit: Modeling Modeling R offers many useful packages. Some examples: • urca: Unit root and cointegration tests for time series data http://cran.r-project.org/web/packages/urca/index.html • fGarch: Rmetrics - Autoregressive Conditional Heteroskedastic Modelling http://cran.r-project.org/web/packages/urca/index.html R/quantstrat For Fun & Profit: Backtesting Backtesting (from Humme/Peterson) R/quantstrat For Fun & Profit: Backtesting Backtesting (from Humme/Peterson) R/quantstrat For Fun & Profit: Optimization Optimization/Parallelization (from Guy Yollin) R/quantstrat For Fun & Profit: Questions? Questions? Appendix A: Equity curve for a strategy under development.