Read-only mirror of 'blotter' from r-forge SVN. Contribute to rforge/blotter development by creating an account on GitHub.
Quantitative Strategy Model Framework
Specify, build, and back-test quantitativefinancial trading and portfolio strategies.
Readme
Transaction-oriented infrastructure for constructing trading systems andsimulation. Provides support for multi-asset class and multi-currencyportfolios for backtesting and other financial research.
Overview
quantstrat provides a generic infrastructure to model and backtestsignal-based quantitative strategies. It is a high-level abstractionlayer (built on xts, FinancialInstrument, blotter, etc.) that allows youto build and test strategies in very few lines of code. quantstrat isstill under heavy development but is being used every day on realportfolios. We encourage you to send contributions and test cases viathe appropriate GitHub mediums (Pull requests and Issue tracker).
Installation
In order to installquantstrat fromGitHub, you will first need to install devtoolsand blotter from GitHub.
Example: maCross
The demos in thedemo folderare great for learning how to use quantstrat specifically. Below is anexample of themaCrossstrategy, a simple moving average strategy using a short-term SMA of 50days and a long-term SMA of 200 days.
We specify the symbol/s and currency/ies before defining the stockmetadata using the stock() function from theFinancialInstrumentpackage, available on CRAN.
Next we set up the rest of the backtest charateristics:
We are now ready to add indicators, signals and rules. For moreinformation on the theory of this approach, see below sections “AboutSignal-Based Strategy Modeling” and “How quantstrat ModelsStrategies”.
Now all we need to do is add our market data before calling theapplyStrategy function to initiate the backtest.
Before we can review results using chart.Posn(), we update theportfolio.
If you would like to zoom into a particular period, you can usequantmod’s zoomChart().
quantmod::zoomChart()Warning
A backtest cannot be unseen. In the words of Lopez de Prado from hisbook Advances in Financial Machine Learning, “Backtesting is one of themost essential, and yet least understood, techniques in the quantarsenal. A common misunderstanding is to think of backtesting as aresearch tool. Researching and backtesting is like drinking and driving.Do not research under the influence of a backtest. …A good backtest canbe extremely helpful, but backtesting well is extremely hard.”
For a comprehensive overview of an hypothesis based approach to researchand backtesting, see Developing & Backtesting Systematic TradingStrategies.
Resources
Below is a growing list of resources (some actively being developed) asrelates to quantstrat:
About Signal-Based Strategy Modeling
A signal-based strategy model first generates indicators. Indicators arequantitative values derived from market data (e.g. moving averages, RSI,volatility bands, channels, momentum, etc.). Indicators should beapplied to market data in a vectorized (for fast backtesting) orstreaming (for live execution) fashion, and are assumed to bepath-independent (i.e. they do not depend on account / portfoliocharacteristics, current positions, or trades).
The interaction between indicators and market data are used to generatesignals (e.g. crossovers, thresholds, multiples, etc.). These signalsare points in time at which you may want to take some action, eventhough you may not be able to. Like indicators, signals may be appliedin a vectorized or streaming fashion, and are assumed to bepath-independent.
Rules use market data, indicators, signals, and current account /portfolio characteristics to generate orders. Notice that rules aboutposition sizing, fill simulation, order generation / management, etc.are separate from the indicator and signal generation process. Unlikeindicators and signals, rules are generally evaluated in apath-dependent fashion (path-independent rules are supported but arerare in real life) and are aware of all prior market data and currentpositions at the time of evaluation. Rules may either generate new ormodify existing orders ( e.g. risk management, fill, rebalance, entry,exit).
How quantstrat Models Strategies![]()
quantstrat uses FinancialInstrument to specify instruments (includingtheir currencies) and uses blotter to keep track of transactions,valuations, and P&L across portfolios and accounts.
Indicators are often standard technical analysis functions like thosefound in TTR; and signals are often specified by the quantstrat sig*functions (i.e. sigComparison, sigCrossover, sigFormula, sigPeak,sigThreshold). Rules are typically specified with the quantstratruleSignal function.
The functions used to specify indicators, signals, and rules are notlimited to those mentioned previously. The name parameter toadd.indicator, add.signal, and add.rule can be any R function. Becausethe supporting toolchain is built using xts objects, custom functionswill integrate most easily if they return xts objects.
The strategy model is created in layers and makes use of delayedexecution. This means strategies can be applied–unmodified–to severaldifferent portfolios. Before execution, quantstrat strategy objects donot know what instruments they will be applied to or what parameterswill be passed to them.
For example, indicator parameters such as moving average periods orthresholds are likely to affect strategy performance. Default values forparameters may (optionally) be set in the strategy object, or set atcall-time via the parameters argument of applyStrategy (parameters is anamed list, used like the arguments lists).
quantstrat models orders, which may or may not become transactions. Thisprovides a lot of extra ability to evaluate how the strategy is actuallyworking, not working, or could be improved. For example, the performanceof strategies are often affected by how often resting limit orders arechanged / replaced / canceled. An order book allows the quantitativestrategist to examine market conditions at the time these decisions aremade. Also, the order history allows for easy computation of things thatare important for many strategies, like order-to-fill ratios.
Functions in quantstrat
Vignettes of quantstrat
Details
Include our badge in your README[![Rdoc](http://www.rdocumentation.org/badges/version/quantstrat)](http://www.rdocumentation.org/packages/quantstrat)
This document is a collection of resources for building packages for Runder Microsoft Windows, or for building R itself (version 1.9.0 or later). The originalcollection was put together by Prof. Brian Ripley and Duncan Murdoch; it is currentlymaintained by Jeroen Ooms.
The authoritative source of information for tools to work with the current release of R is the'R Administration and Installation' manual. In particular, please read the'Windows Toolset' appendix.
Rtools Downloads
Some of the tools are incompatible with obsolete versions of R.We maintain one actively updated version of the tools, and other 'frozen' snapshotsof them. We recommend that users use the latest release of Rtools with the latest release of R.
The current version of this file is recorded here: VERSION.txt.
The change history to the Rtools is below.
Tools for 64 bit Windows builds
Rtools 2.12 and later include both 32 bit and 64 bit tools.
Most of the tools used for 32 bit builds work fine as well for 64 bit builds,but the gcc version may be different, and it has changed a number of times.
R 3.3.0 and later use a toolchain based on gcc 4.9.3 and mingw-w64 v3, puttogether by Jeroen Ooms and others. See the project page for details.
R-patched subsequent to Jan 22, 2012, R-devel, and releases after 2.14.1 used a toolchain based on pre-4.6.3 gcc, put together by Prof. Brian Ripley and available as multi.zip on his web page. Rtools 2.15 to 3.3 includes this toolchain. It uses the same gcc version for both 32 and 64 bit builds. Separate versions of the gdbdebugger are also included for each archtecture.
Builds of R 2.13.x and R 2.14.{0,1} used a release based on pre-4.5.2 gcc. Rtools 2.14 includesbinaries put together by Prof. Brian Ripley and available from his web page. To install these, select the 'MinGW64' component when installing Rtools.
For the later R 2.11.x versions, we used the MinGW-w64version based on pre-4.4.4 gcc from Prof. Ripley, which is no longer available.We also used this version for development builds of R 2.12.0 up to July 20.
R 2.11.0 used
http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Automated%20Builds/mingw-w64-1.0-bin_i686-mingw_20100322.zip , but this is apparently no longer availablefor download.
To install any of these older versions, follow the instructions on Prof. Ripley's web page.
Downloads
There are a number of downloads described in the 'Windows Toolset' appendix.
To build packages:
Optional additions:
For building R, all of the above, plus:
After running the Rtools installer, follow the instructions in Rtools.txtto complete your installation.
Special situationsObtaining the R source code
There are two ways to obtain the R source code: from the Subversion repository, and from CRAN in acompressed tar file.
Subversion is an open source version control system. Afterobtaining and installing it, you can obtain the latest development source usingwhich will install it into the specified directory. (Normally you would use a different home directoryfor this unstable development code than you would use for a released version of R.)
R Quantstrat Manual Download Windows 7
Alternatively, compressed tar files containing the source may bedownloaded from CRAN.Do remember to unpack the sources by using our tar: WinZip will notrespect the symbolic links in the file. A typical tar command line would be:
Extras
Modified sources of gdbm-1.8.3 are availablefor experiments with Luke Tierney's gdbm package.
Change HistoryChanges since R 3.3.0
The version number has been updated to 3.4.x.y.
Support for the gcc 4.6.3 toolchain has been dropped.
We have updated Tcl/TK to version 8.6.4. If you are using Rtools34to build R 3.3.x, you will need to change
TCL_VERSION = 85 to TCL_VERSION = 86 in R_HOME/src/gnuwin32/fixed/etc/Makeconf. Changes since R 3.2.2
Both the gcc 4.6.3 toolchain and a toolchain based on gcc 4.9.3 and mingw-w64 v3 are now included. For use with the newer toolchaina compiled copy of libicu55 is also included; it will be installed in Rtools/mingw_libsif the newer compilers are selected.
Changes since R 3.1.3
The version number has been updated to 3.3.x.y.
Rtools33 has been started. Due to test failures with gcc 4.9.2, it will not be usedin R 3.2.0, and gcc 4.6.3 is included in Rtools33. We expect that gcc 4.9.2 or laterwill be included in a future release.
The 32 and 64 bit builds of the gdb debugger have been copied into the Rtools/bindirectory as gdb.exe and gdb64.exe respectively. The copies in the gcc-4.6.3 remain, butwill not be included when that compiler is dropped.
The scripts and cross-compiler used to build gcc 4.9.2 are available on CRAN and its mirrorsin the bin/windows/Rtools/scripts directory, along with notes on the build.
The bitmap libraries have been removed; they are now downloaded and installed when building R by usingmake rsync-extsoft.
The Cygwin 'cygpath.exe' utility has been added to Rtools/bin; this allows conversion between Cygwin-style pathsused in shell scripts and native Windows-style paths.
Changes since R 3.1.2
The version number has been updated to 3.2.x.y.
The Cygwin tools have been updated to versions current as of January 7, 2015.
R version 3.2.0 will require texinfo 5.2 to build the manuals, and it has been added to the tools.It will also require a copy of Perl, which is NOT includedin the tools. By default the manuals will no longer be built; follow the instructionsin src/gnuwin32/MkRules.dist if you would like to build them.
Changes since R 3.0.2
The Cygwin tools have been updated to versions current as ofNovember 19, 2013. Cygwin now builds separate 32 bit and 64 bitversions; we include 32 bit versions of the tools. If your system only has 64bit Cygwin DLLs installed, you will need to add our Cygwin DLLs to your path(or install the 32 bit Cygwin DLLs into Cygwin).
The bitmap library libpng has been updated to version 1.6.9.
Changes since R 3.0.0
The version number has been updated to 3.1.x.y.
We now record the minimum supported R version in the registry data in entry 'MinRVersion'within the Rtools/X.Y key. Earlier versions of R should use an earlier version of Rtools. This valuemay be less than the minimum listed in the table above. The table is a promise to try to maintaincompatibility; this value is what we actually maintained.
We also record the full version number, e.g. 3.1.0.1935, in entry 'FullVersion' in the registry.
Changes since R 2.15.2The bitmap libraries have been updated to libpng 1.5.13, libtiff 4.0.3 and jpeg-9.The version number has been changed from 2.16.x to 3.0.x, following the R renumbering.Changes since R 2.15.1The bitmap libraries have been updated to jpeg-8d, libpng 1.5.12, and libtiff 4.0.2.The Cygwin tools have been updated to versions current as of July 13, 2012. NB: some of thetools now require you to have a HOME environment variable, listing your homedirectory. One way you can create it in a Windows command shell is by usingRtools 2.15 has been frozen.Changes since R 2.14.1The pre-4.6.3 toolchain has been updated to fix a bug in the sqrt() function.R now uses pre-4.6.3 gcc for all current builds, and that is the only version included in Rtools 2.15.Changes since R 2.14.0The new toolchain based on gcc pre-4.5.4 has been added.Changes since R 2.13.1The Info-zip utilities have been updated: zip.exe is now version 3.0, unzip.exe is version 6.00.Rtools 2.13 has been frozen.Changes since R 2.12.2We have updated all of the tools to current Cygwin versions as of March 25, 2011. We addedthe 'du' utility from Cygwin. We have dropped Vanilla Perl.The libjpeg version has been updated to 8c, and libpng has been updated to 1.5.1.Rtools 2.12 has been frozen.We have added the Rtools version number to Rtools.txt and to a new file, VERSION.txt.Changes since R 2.11.1Prior to October 18, 2010, builds of Rtools212.exe did not correctly install the 'extras' required to build R. Version 2.12.0.1892 or later should fix this.We have now updated all of the tools to current Cygwin versions, and haveupdated the compilers, and included the 64 bit compilers into Rtools. SeeProf. Ripley's pagefor the details. Perl is rarely needed in R since R 2.12.0, so it is by defaultnot installed.Rtools 2.11 has been frozen.Changes since R 2.11.0The 32 bit version of R-devel (to become R 2.12.0 in fall, 2010) will be built with gcc 4.5.x, so Rtools212 contains a completelynew MinGW toolchain based on gcc 4.5.0. Current plans are to continue building R 2.11.x and patches toit with Rtools211, based on gcc 4.2.1.Changes since R 2.10.1
Rtools210 was frozen, and Rtools211 has been introduced containing the following changes:
We have updated Tcl/TK to version 8.5.8.
Versions 6b, 7 and 8 of libjpeg have been dropped, and version 8a has been added.
We have updated libpng to version 1.4.1
Changes since R 2.9.2
Rtools29 was frozen, and Rtools210 has been introduced containing the following changes.
We have updated tar to version 1.21.
We have updated the libpng library to libpng-1.2.40.
We have added version 7 of libjpeg.
We have updated to version 5.3.5 (Unicode) of Inno Setup
We have added the 'file' command.
Changes since R 2.8.1
We have updated the Cygwin utilities and DLLs, the MinGW utilities, and the Tcl/Tk filesto current versions as of February 18, 2009.
Changes since R 2.8.0
We have frozen Rtools28.exe, and introduced Rtools29.exe.
Changes since R 2.7.2
We have updated the Cygwin utilities and DLLs to current versions as of September 5, 2008.
We have updated libpng (used in building R) to version 1.2.31.
Changes since R 2.7.0
We have updated the Cygwin utilities and DLLs to current versions as of May 21, 2008.
The installer no longer requires a reboot if the PATH is changed, and won't suggestadding Rtools at the head of the PATH if it is already there.
We have started the 2.8 series of installers, dropping support for R 2.6.x and earlier.
The installer now sets registry entries like those of R, so that other tools can find it. Only fixes tothis code will affect Rtools27.exe, the contents are otherwise frozen.
Changes since R 2.6.2
The installer now includes versions 8.4.15 (for R up to 2.6.x) and 8.5.2 (for R 2.7.x or later)of the TCL/TK bundle, and iconv.dll version 1.12.
Inno Setup 5.2.3 is now used.
The libtiff library 3.8.2 has been added (for TIFF support in 2.7.0), and the libpng libraryhas been updated to version 1.2.25.
Changes since R 2.6.1
The Win32 API files have been updated to version 3.11.
The MinGW run-time has been updated to version 3.14.
Both versions 8.4.15 (for R up to 2.6.x) and 8.5.0 (for R 2.7.x or later)of the TCL/TK bundle are now included in the installer.
The installer now detects incomplete Cygwin uninstalls, and removes the leftovermount information that caused bugs in our build tools. It also allows manual editingof the system PATH.
The Cygwin tools have been updated to current versions, as of January 18, 2008. Dates onfiles have been reset to the original dates, rather than a build date of Rtools27.exe.
Changes since R 2.6.0
Support for gcc 3.4.5 has been dropped. For the life of R 2.6.x, both 'GCC4_SUFF=-sjlj' and 'GCC4_SUFF=' will be supported;subsequently, the gcc 4.2.1 tools will not include the suffix.
The Win32 API files have been updated to version 3.10.
Changes since R 2.5.1Quantstrat Trader
The Rtools installer now includes both MinGW gcc versions 3.4.5 (used for R versions 2.5.x) and 4.2.1 (used for R 2.6.x and later), as well as Vanilla Perl. See the Rtools.txt file for the latest information.
tools.zip and R_Tcl.zip are no longer being distributed, now that they have been merged into the Rtools installer.
The MinGW run-time has been updated to version 3.13.
Inno Setup has been updated to version 5.1.14.
The binary tools have been updated to current Cygwin versions (except custom versions, as noted in the README.txtfile).
![]() Changes since R 2.5.0
Inno Setup version 5.1.12 is now used (for Windows Vista compatibility).
The TCL/TK bundle has been updated to version 8.4.15, and now includes the manuals in CHM help format.
Changes since R 2.4.1
Warning: the current MinGW releases will not run in Microsoft Vista.
We have just put together an experimentalRtools installer. This packages up the R tools bundle, the MinGWtools, and the TCL/TK, Unicode and bitmap support.It does not include Perl, LaTeX, the HTML Help Workshop, or theInno Setup installer.
We no longer recommend using the pre-packaged MinGW versions; it ishard to keep track of which versions they package. Instead we recommendusing the installer above or downloading the components directly from theversions on the Sourceforge download page.
<
Changes since R 2.4.0
MinGW run-time version 3.11or higher is now required.
Inno Setup version 5.1.7 or higher is now required.
Changes since R 2.3.1
The iconv.zip internationalization library has beenupdated to version 1.11.
R Quantstrat Manual Download Windows 10
The R_Tcl.zip files for Tcl/Tk support have been updated to version 8.4.13.
mingw-runtime >= 3.10 is required to build R (a bug fix in the handingof MBCS code is required). This is enforced by a check in buildingRpwd.exe.
Our daily builds no longer use the patched version of ld.exe, we use a newerversion of the unpatched utility. We have not tested the new setup on Windows NT4. If you are usingthat OS and the builds do not work, please let us know.
Quantstrat GithubChanges since R 2.2.1
- The cmp utility is required to build R; a copy has been added to tools.zip [NB: tools.zip is no longer distributed].
R Quantstrat Manual Download Free
- There is a bug in the MinGW ld.exe linker utility version 2.16.91 20050827.This bug does not affect the linking method used in R up to 2.2.x, but is likely to affect the method usedin R 2.3.x or higher, making such builds fail to run on Windows NT 4 systems. Our dailybuilds are now using the patched version, but it is not included in the Rtools collection.See the instructions below to obtain and install a copy of the patched version.
Changes since R 2.1.1
The following changes have been made since the release of R 2.1.1:
- The R_Tcl.zip files for tcl/tk support have been updated to version 8.4.11.
- Version 3.4.4 of the MinGW gcc compilers, 3.8 of the MinGW runtime, 2.15.94 ofthe MinGW binutils, and 3.3 of the w32api are now used in builds.
- A broken version of tar.exe has finally been replaced in tools.zip [NB: tools.zip is no longer distributed].
- The MinGW tools are now available in a file named MinGW-5.0.0.exe on the MinGW website. Choosethe 'candidate' packages. This will download and install mingw-runtime-3.8.tar.gz, w32api-3.3.tar.gz, binutils-2.16.91-20050827-1.tar.gz,gcc-core-3.4.4-20050522-1.tar.gz, gcc-g++-3.4.4-20050522-1.tar.gz, and gcc-g77-3.4.4-20050522-1.tar.gz.
- Inno setup 5.1.5 or better is needed to build the installer.
Changes since R 2.1.0
The following changes have been made since the release of the R 2.1.0 Installation and Administration manual:
Manual Download Free
- Version 5.1.2 or better of the Inno Setup installer (currently in beta testing) is nowrequired for r-patched and r-devel, and is expected to be required for future releases.
- The head utility is now needed to build R; a copy has been added totools.zip [NB: tools.zip is no longer distributed].
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |