Modified README to include better installation instructions.
This commit is contained in:
@@ -1,30 +1,127 @@
|
||||
# QuantStart Forex
|
||||
|
||||
QSForex is an open-source work-in-progress event-driven backtesting and live trading platform for use in the foreign exchange ("forex") markets.
|
||||
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, predominantly for education purposes, but also to provide the systematic trading community with a robust trading engine that allows straightforward forex strategy implementation and testing.
|
||||
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).
|
||||
|
||||
# Current Features
|
||||
|
||||
* Currently in alpha mode - very early stage!
|
||||
* Live trading with one particular forex broker, OANDA, via their Rest API
|
||||
* Event-driven architecture with price streaming (via the OANDA API)
|
||||
* Basic local portfolio replication of live trades (ultimately for backtesting purposes)
|
||||
* **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. QSForex contains a suite of unit tests for the majority of its calculation code and new tests are constantly added for new features.</li>
|
||||
* **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
|
||||
|
||||
At this stage, since the software is in alpha mode, the installation instructions are somewhat more involved. As the software evolves they will become more straightforward and documentation will become more extensive. However, the basic approach is as follows:
|
||||
1) 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.
|
||||
|
||||
1. Setup an account with OANDA and obtain the API authentication credentials
|
||||
2. Clone the repository into a suitable location on your machine
|
||||
3. Create two environment variables: OANDA_API_ACCESS_TOKEN and OANDA_API_ACCOUNT_ID, which must contain, respectively, the OANDA API Access Token and the OANDA API Account ID, as provided by OANDA
|
||||
4. Create a virtual environment ("virtualenv") for the QSForex code and utilise pip to install the requirements - `pip install -r requirements.txt`
|
||||
5. Modify `strategy.py` to create an event-driven strategy class
|
||||
6. Execute `trading.py` to carry out practice/live trading
|
||||
2) Clone this git repository into a suitable location on your machine using the following command in your terminal: ```git clone https://github.com/mhallsmoore/qsforex.git```. Alternative you can download the zip file of the current master branch at https://github.com/mhallsmoore/qsforex/archive/master.zip.
|
||||
|
||||
If you have any questions about the installation then please feel free to email me at mike AT quantstart DOT com. You might also wish to have a look at the Forex Trading Diary series on QuantStart in order to gain some intuition about how the system is built.
|
||||
3) Create a set of environment variables for all of the settings found in the ```settings.py``` file in the application root directory. Alternatively, you can "hard code" your specific settings by overwriting the ```os.environ.get(...)``` calls for each setting:
|
||||
|
||||
```
|
||||
# The data directory used to store your backtesting CSV files
|
||||
CSV_DATA_DIR = "/path/to/your/csv/data/dir"
|
||||
|
||||
# The directory where the backtest.csv and equity.csv files
|
||||
# will be stored after a backtest is carried out
|
||||
OUTPUT_RESULTS_DIR = "/path/to/your/output/results/dir"
|
||||
|
||||
# Change DOMAIN to "real" if you wish to carry out live trading
|
||||
DOMAIN = "practice"
|
||||
|
||||
# Your OANDA API Access Token (found in your Account Details on their website)
|
||||
ACCESS_TOKEN = "1234123412341234"
|
||||
|
||||
# Your OANDA Account ID (found in your Account Details on their website)
|
||||
ACCOUNT_ID = "1234123412341234"
|
||||
|
||||
# Your base currency (e.g. "GBP", "USD", "EUR" etc.)
|
||||
BASE_CURRENCY = "GBP"
|
||||
|
||||
# Your account equity in the base currency (for backtesting)
|
||||
EQUITY = Decimal("100000.00")
|
||||
```
|
||||
|
||||
4) 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:
|
||||
|
||||
```
|
||||
mkdir -p ~/venv/qsforex
|
||||
cd ~/venv/qsforex
|
||||
virtualenv .
|
||||
```
|
||||
|
||||
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 ```~/projects/qsforex/``` (change this directory below to wherever you installed QSForex), then in order to install the packages you will need to run the following commands:
|
||||
|
||||
```
|
||||
source ~/venv/qsforex/bin/activate
|
||||
pip install -r ~/projects/qsforex/requirements.txt
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
* https://www.quantstart.com/articles/Quick-Start-Python-Quantitative-Research-Environment-on-Ubuntu-14-04
|
||||
* https://www.quantstart.com/articles/Easy-Multi-Platform-Installation-of-a-Scientific-Python-Stack-Using-Anaconda
|
||||
|
||||
You will also need to create a symbolic link from your ```site-packages``` directory to your QSForex installation directory in order to be able to call ```import qsforex``` within the code. To do this you will need a command similar to the following:
|
||||
|
||||
```
|
||||
ln -s ~/projects/qsforex/ ~/venv/qsforex/lib/python2.7/site-packages/qsforex
|
||||
```
|
||||
|
||||
Make sure to change ```~/projects/qsforex``` to your installation directory and ```~/venv/qsforex/lib/python2.7/site-packages/``` to your virtualenv site packages directory.
|
||||
|
||||
You will now be able to run the subsequent commands correctly.
|
||||
|
||||
## Practice/Live Trading
|
||||
|
||||
5) At this stage, if you simply wish to carry out practice or live trading then you can run ```python trading/trading.py```, which will use the default ```TestStrategy``` 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. ```MeanReversionMultiPairStrategy``` and ensure it has a ```calculate_signals``` method. You will need to pass this class the ```pairs``` list as well as the ```events``` queue, as in ```trading/trading.py```.
|
||||
|
||||
Please look at ```strategy/strategy.py``` for details.
|
||||
|
||||
## Backtesting
|
||||
|
||||
6) 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 ```CSV_DATA_DIR``` setting in ```settings.py``` is to set to a directory where you want the historical data to live. You then need to run ```generate_simulated_pair.py```, which is under the ```scripts/``` directory. It expects a single command line argument, which in this case is the currency pair in ```BBBQQQ``` format. For example:
|
||||
|
||||
```
|
||||
cd ~/projects/qsforex
|
||||
python scripts/generate_simulated_pair.py GBPUSD
|
||||
```
|
||||
|
||||
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 ```BBBQQQ_YYYYMMDD.csv``` (e.g. ```GBPUSD_20140112.csv```) appear in your ```CSV_DATA_DIR``` for all business days in that month. If you wish to change the month/year of the data output, simply modify the file and re-run.
|
||||
|
||||
7) Now that the historical data has been generated it is possible to carry out a backtest. The backtest file itself is stored in ```backtest/backtest.py```. It currently defaults to trading GBPUSD (so will expect GBPUSD data files in ```CSV_DATA_DIR```), but this can easily be changed. In addition a basic ```MovingAverageCrossStrategy``` is implemented (from ```strategy/strategy.py```), which will backtest on the data found in ```CSV_DATA_DIR```.
|
||||
|
||||
To execute the backtest, simply run the following:
|
||||
|
||||
```
|
||||
python backtest/backtest.py
|
||||
```
|
||||
|
||||
**This will take some time.** On my Ubuntu desktop system at home, with the historical data generated via ```generate_simulated_pair.py```, it takes around 5-10 mins to run. 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.
|
||||
|
||||
8) If you wish to view the performance of the backtest you can simply run ```output.py``` to view an equity curve, period returns (i.e. tick-to-tick returns) and a drawdown curve:
|
||||
|
||||
```
|
||||
python backtest/output.py
|
||||
```
|
||||
|
||||
And that's it! At this stage you are ready to begin creating your own backtests by modifying or appending strategies in ```strategy/strategy.py``` 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 mike@quantstart.com.
|
||||
|
||||
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
|
||||
|
||||
# License Terms
|
||||
|
||||
|
||||
Reference in New Issue
Block a user