- QuantStart Forex
- Current Features
- fxcmpy Python Package
- Installation and Usage
- Main features
- Practice/Live Trading
- Here are 124 public repositories matching this topic...
- 3 Best Forex Brokers for 2020
- Save Your Login Credentials
- License Terms
- Python Algorithmic Trading Library
- Forex Trading Disclaimer
QSForex is an open-source event-driven backtesting and live trading platform for use in the foreign exchange ("forex") markets, currently in an "alpha" state.
It has been created as part of the Forex Trading Diary series on QuantStart.com to provide the systematic trading community with a robust trading engine that allows straightforward forex strategy implementation and testing.
The software is provided under a permissive "MIT" license (see below).
- Open-Source - QSForex has been released under an extremely permissive open-source MIT License, which allows full usage in both research and commercial applications, without restriction, but with no warranty of any kind whatsoever.
- Free - QSForex is completely free and costs nothing to download or use.
- Collaboration - As QSForex is open-source many developers collaborate to improve the software.
New features are added frequently. Any bugs are quickly determined and fixed.
- Software Development - QSForex is written in the Python programming language for straightforward cross-platform support.
fxcmpy Python Package
QSForex contains a suite of unit tests for the majority of its calculation code and new tests are constantly added for new features.
- Event-Driven Architecture - QSForex is completely event-driven both for backtesting and live trading, which leads to straightforward transitioning of strategies from a research/testing phase to a live trading implementation.
- Transaction Costs - Spread costs are included by default for all backtested strategies.
- Backtesting - QSForex features intraday tick-resolution multi-day multi-currency pair backtesting.
- Trading - QSForex currently supports live intraday trading using the OANDA Brokerage API across a portfolio of pairs.
- Performance Metrics - QSForex currently supports basic performance measurement and equity visualisation via the Matplotlib and Seaborn visualisation libraries.
Installation and Usage
Visit http://www.oanda.com/ and setup an account to obtain the API authentication credentials, which you will need to carry out live trading.
I explain how to carry this out in this article: https://www.quantstart.com/articles/Forex-Trading-Diary-1-Automated-Forex-Trading-with-the-OANDA-API.
Clone this git repository into a suitable location on your machine using the following command in your terminal: .
Alternative you can download the zip file of the current master branch at https://github.com/mhallsmoore/qsforex/archive/master.zip.
Create a set of environment variables for all of the settings found in the file in the application root directory.
Alternatively, you can "hard code" your specific settings by overwriting the calls for each setting:
- Create a virtual environment ("virtualenv") for the QSForex code and utilise pip to install the requirements. For instance in a Unix-based system (Mac or Linux) you might create such a directory as follows by entering the following commands in the terminal:
This will create a new virtual environment to install the packages into.
Assuming you downloaded the QSForex git repository into an example directory such as (change this directory below to wherever you installed QSForex), then in order to install the packages you will need to run the following commands:
This will take some time as NumPy, SciPy, Pandas, Scikit-Learn and Matplotlib must be compiled.
There are many packages required for this to work, so please take a look at these two articles for more information:
You will also need to create a symbolic link from your directory to your QSForex installation directory in order to be able to call within the code. To do this you will need a command similar to the following:
Make sure to change to your installation directory and to your virtualenv site packages directory.
You will now be able to run the subsequent commands correctly.
- At this stage, if you simply wish to carry out practice or live trading then you can run , which will use the default trading strategy.
This simply buys or sells a currency pair every 5th tick.
It is purely for testing - do not use it in a live trading environment!
If you wish to create a more useful strategy, then simply create a new class with a descriptive name, e.g.
and ensure it has a method. You will need to pass this class the list as well as the queue, as in .
Please look at for details.
- In order to carry out any backtesting it is necessary to generate simulated forex data or download historic tick data.
If you wish to simply try the software out, the quickest way to generate an example backtest is to generate some simulated data.
The current data format used by QSForex is the same as that provided by the DukasCopy Historical Data Feed at https://www.dukascopy.com/swiss/english/marketwatch/historical/.
To generate some historical data, make sure that the setting in is to set to a directory where you want the historical data to live. You then need to run , which is under the directory.
It expects a single command line argument, which in this case is the currency pair in format. For example:
At this stage the script is hardcoded to create a single month's data for January 2014.
That is, you will see individual files, of the format (e.g. ) appear in your for all business days in that month.
Here are 124 public repositories matching this topic...
If you wish to change the month/year of the data output, simply modify the file and re-run.
- Now that the historical data has been generated it is possible to carry out a backtest. The backtest file itself is stored in , but this only contains the class. To actually execute a backtest you need to instantiate this class and provide it with the necessary modules.
The best way to see how this is done is to look at the example Moving Average Crossover implementation in the file and use this as a template.
3 Best Forex Brokers for 2020
This makes use of the which is found in . This defaults to trading both GBP/USD and EUR/USD to demonstrate multiple currency pair usage. It uses data found in .
To execute the example backtest, simply run the following:
This will take some time. On my Ubuntu desktop system at home, with the historical data generated via , it takes around 5-10 mins to run.
Save Your Login Credentials
A large part of this calculation occurs at the end of the actual backtest, when the drawdown is being calculated, so please remember that the code has not hung up!
Please leave it until completion.
- If you wish to view the performance of the backtest you can simply use to view an equity curve, period returns (i.e. tick-to-tick returns) and a drawdown curve:
And that's it! At this stage you are ready to begin creating your own backtests by modifying or appending strategies in and using real data downloaded from DukasCopy (https://www.dukascopy.com/swiss/english/marketwatch/historical/).
If you have any questions about the installation then please feel free to email me at [email protected]
If you have any bugs or other issues that you think may be due to the codebase specifically, feel free to open a Github issue here: https://github.com/mhallsmoore/qsforex/issues
Copyright (c) 2015 Michael Halls-Moore
Permission 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.
Python Algorithmic Trading Library
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.
Forex Trading Disclaimer
Trading foreign exchange 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 foreign exchange 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 foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts.