Package: qstrader
QSTraderDevelopmentDetailsTest StatusVersion InfoCompatibilityLicenseQSTrader is a free Python-based open-source modular schedule-driven backtesting framework for long-short equities and ETF based systematic trading strategies.QSTrader can be best described as a loosely-coupled collection of modules for carrying out end-to-end backtests with realistic trading mechanics.The default modules provide useful functionality for certain types of systematic trading strategies and can be utilised without modification. However the intent of QSTrader is for the users to extend, inherit or fully replace each module in order to provide custom functionality for their own use case.The software is currently under active development and is provided under a permissive "MIT" license.Previous Version and Advanced Algorithmic TradingPlease note that the previous version of QSTrader, which is utilised through theAdvanced Algorithmic Tradingebook, can be found along with the appropriate installation instructionshere.It has recently been updated to support Python 3.9, 3.10, 3.11 and 3.12 with up to date package dependencies.InstallationInstallation requires a Python3 environment. The simplest approach is to download a self-contained scientific Python distribution such as theAnaconda Individual Edition. You can then install QSTrader into an isolatedvirtual environmentusing pip as shown below.Any issues with installation should be reported to the development team as issueshere.condacondais a command-line tool that comes with the Anaconda distribution. It allows you to manage virtual environments as well as packagesusing the same tool.The following command will create a brand new environment calledbacktest.conda create -n backtest pythonThis will use the conda default Python version. At time of writing this was Python 3.12. QSTrader currently supports Python 3.9, 3.10, 3.11 and 3.12. Optionally you can specify a python version by substituting python==3.9 into the command as follows:conda create -n backtest python==3.9In order to start using QSTrader, you need to activate this new environment and install QSTrader using pip.conda activate backtest
pip3 install qstraderpipAlternatively, you can usevenvto handle the environment creation andpipto handle the package installation.python -m venv backtest
source backtest/bin/activate  # Need to activate environment before installing package
pip3 install qstraderFull DocumentationComprehensive documentation and beginner tutorials for QSTrader can be found on QuantStart.com athttps://www.quantstart.com/qstrader/.QuickstartThe QSTrader repository provides some simple example strategies at/examples.Within this quickstart section a classic 60/40 equities/bonds portfolio will be backtested with monthly rebalancing on the last day of the calendar month.To get started download thesixty_forty.pyfile and place into the directory of your choice.The 60/40 script makes use of OHLC 'daily bar' data from Yahoo Finance. In particular it requires theSPYandAGGETFs data. Download the full history for each and save as CSV files in same directory assixty_forty.py.Assuming that an appropriate Python environment exists and QSTrader has been installed (seeInstallationabove), make sure to activate the virtual environment, navigate to the directory withsixty_forty.pyand type:python sixty_forty.pyYou will then see some console output as the backtest simulation engine runs through each day and carries out the rebalancing logic once per month. Once the backtest is complete a tearsheet will appear:You can examine the commentedsixty_forty.pyfile to see the current QSTrader backtesting API.If you have any questions about the installation or example usage then please feel free to emailsupport@quantstart.comor raise an issuehere.Current FeaturesBacktesting Engine- QSTrader employs a schedule-based portfolio construction approach to systematic trading. Signal generation is decoupled from portfolio construction, risk management, execution and simulated brokerage accounting in a modular, object-oriented fashion.Performance Statistics- QSTrader provides typical 'tearsheet' performance assessment of strategies. It also supports statistics export via JSON to allow external software to consume metrics from backtests.Free Open-Source Software- QSTrader has been released under a permissive open-source MIT License. This allows full usage in both research and commercial applications, without restriction, but with no warranty of any kind whatsoever (seeLicensebelow). QSTrader is completely free and costs nothing to download or use.Software Development- QSTrader is written in the Python programming language for straightforward cross-platform support. QSTrader contains a suite of unit and integration tests for the majority of its modules. Tests are continually added for new features.License TermsCopyright (c) 2015-2024 QuantStart.com, QuarkGluon LtdPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Trading DisclaimerTrading equities on margin carries a high level of risk, and may not be suitable for all investors. Past performance is not indicative of future results. The high degree of leverage can work against you as well as for you. Before deciding to invest in equities you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with equities trading, and seek advice from an independent financial advisor if you have any doubts.