Professional Documents
Culture Documents
This is the old Auquan Toolbox, which is a stripped down version of our new, more powerful toolbox. If you
are new to writing strategies, continue practicing with this toolbox. If you are comfortable with financial data,
find the new, expanded version which provides extensive functionality and customization here
We provide daily price data for 600 stocks listed on NASDAQ which are (or were) a part of S&P500 since
2001. The code below will automatically download the stocks data for you. The full list of stocks is here
The modules are in the folder auquanToolbox. We also provide sample strategies to demonstrate how to use
the toolbox.
Table of Contents
1. Installation
2. How to write a trading strategy?
3. Backtesting
1. Installation
Python 2.7
You need Python 2.7 (Python 3 will be supported later) to run this toolbox. There are several distributions of
Python 2.7 that can be used. For an easy installation process, we recommend Anaconda since it will reliably
install all the necessary dependencies. Download Anaconda and follow the instructions on the installation
page. Once you have Python, you can then install the toolbox.
Auquan Toolbox
There are multiple ways to install this toolbox.
The easiest way and the most recommended way is via pip. Just run the following command: pip install
-U auquanToolbox It will also install all the dependencies. Now you can just call import auquanToolbox
within your code to import the toolbox. If you want to run a strategy, find the path for the strategy, and run
python {path_to_strategy} . If we publish any updates to the toolbox, the same command pip
install -U auquanToolbox will also automatically get the new version of the toolbox.
You can also choose to clone the master branch of this repo or download the code from this repo. After you
do that, navigate to the root folder of this project and run python setup.py install . This will also install
all the dependencies, and you are good to run an existing strategy or create a new one. You would have to
redownload the toolbox code, if we published any changes to the toolbox.
Dependencies
Python 2.7 (Python 3 will be supported soon)
numpy
pandas
matplotlib
settings:
This function takes no arguments and has to return the following parameters:
It takes lookback_data as argument, which is historical data for the past “lookback”(as defined in settings)
number of days. It is a dictionary of following features:
KeyName Description
SIGNAL Long (+1), short (-1) or no position (0) for all securities in markets[]
WEIGHTS The weight of each stock in your portfolio.
PRICE Optional. If specified, buy orders are executed only if next day’s open price is equal or lower than
the price and sell orders are executed if it is equal or higher than the price. Set as 0 if you don’t
want to specify a price.
3. Backtesting:
The system is run by calling the command
backtest(exchange, markets, trading_strategy, date_start, date_end, lookback)
You can set an optional verbose=True to see more details
Execution happens at the day’s open price. When executed, the system will automatically calculate the
quantity of each stock to buy and sell to maintain the portfolio weights specified by you. For example if you
are trading AAPL and GOOG, your portfolio value is 1,000,000 and your order is:
If no price is specified(as in this example), order exection happens at stock’s open price. If you specify a price,
the system will buy the specified quantity of stock if it’s open price <= price specified here and sell the
specified quantity of a stock if it’s price >= price specified here. No action is taken if the price criteria is not
met.
Cost to Trade: The system automatically accounts for trading costs. We apply a commssion (fees charged by
the exchange and the broker) and slippage (the difference inprice at which you placed your order and the
price at which you actually traded.)
We use 0.10 per stock as commission and 5% of the daily range slippage((HIGH - LOW) * 0.05)
Total cost to trade = 0.10 + (HIGH - LOW) * 0.05
After evaluation, the sytem plots a chart of daily and total pnl for the strategy and daily long/short exposure.
We also plot total pnl for a benchmark index. You can view performance for individual stocks using the GUI.
Run logs and order,position and pnl information is stored in csv in the runlogs folder.
auquan-toolbox-python is maintained by Auquan
This page was generated by GitHub Pages.