From Quantwiki
Jump to: navigation, search


QuickSim Documentation

The quant software tool kit currently contains a directory called QuickSim which contains a backtester with a number of features, along with a subfolder containing example strategies that may be tested using the backtester. More documentation may be found in the Epydocs section or the tutorials, particularly QSTK Tutorial 4 and QSTK Tutorial 5.


This module contains functionality for backtesting strategies and allocation files. The backtester may be used by importing the module and calling various functions, or directly from the command line using various arguments.

Command Line Interface

From the command line, there are three basic ways a user may make use of the backtester.

Allocation Back Testing

The first and simplest way is by testing an allocation that has been placed in a pickle file. The format of the allocation table is a pandas Datamatrix, that has stock symbols as a column heading and datetime objects for indices. One of the columns is a symbol '_CASH' which represents how much of the portfolio is in cash at a given time. Each value in the matrix represents how much of the portfolio should be in a stock at the time. The backtester will warn the user if a row does not add to one, which indicates that the user has leveraged themselves on that day. The command line usage of the backtester in this way is shown below:

python quickSim.py 'allocation.pkl' 1000 'output.pkl'

The first argument is the file that contains the allocation DataMatrix. The second argument is a number representing the number of dollars that the portfolio starts out with. The final argument is the pickle file that the output should be dumped to. The output is a pandas TimeSeries that contains the value of the portfolio in dollars on a given date. The backtester gets these dates from the allocation DataMatrix, and tests for each day between the first allocation and the last, rebalancing for each row in the allocation table.

Strategy Back Testing

Another useful feature of the back tester is the ability to test strategies in the form of python scripts. Simply use these strategies from the command line, providing the proper arguements based on the particular strategy script to create an allocation file and then test the output using the method described above. More information on strategies and the example strategies provided with QSTK can be found here: Quicksim Example Strategies.

Module Interface

The backtester may also be used when imported as a module. The functionality is similar to that available in the command line interface, but provided through several function calls. The relevant functions are alloc_backtest, strategy_backtest1, and strategy_backtest2. Using the module allows more control over the types of testing you do.


This function simply tests an allocation Datamatrix in a pickle file and returns the funds time series.

from quicksim import quickSim as qs


This function takes in historical data and an allocation to test, along with the starting fund value. It then directly tests the provided DataMatrices and returns a time series of fund values.

from quicksim import quickSim as qs
# define historic
# define alloc
# ....

More Complex Strategy Testing

Further documentation is available on the quickSim module on the Complex Testing page. This page goes over more advance features of the backtester, such as testing strategies multiple times for more robust analysis. In addition to the documentation, tutorials 4 and 5 cover creating an allocation DataMatrix and testing it using the backtest.

Complex Testing

Quicksim Example Strategies

This subfolder is a module which contains various python scripts that act as example strategies. These strategies have paramaterized functions and example main sections which may be edited and used with the backtester.

Quicksim Example Strategies

Personal tools