Bloomberg maintains tick-by-tick historical data for only 140 days. However, you may want to backtest your strategies with a longer history. In this case, you can archive these tickdata by yourself and do backtesting with the archived data. Since version 0.2, AlgoQuant supports downloading tick-by-tick data from Bloomberg and saving them as CSV files via the Bloomberg Java API v3 (assuming that you have access to a Bloomberg terminal).
After you download the AlgoQuant package, you will find that there is a folder
lib/blpapi-dummy which contains the Bloomberg API jar file (
blpapi3.jar). This file is a dummy for AlgoQuant to compile. To use the Bloomberg Java API, you need to replace the file with the real API jar file. If your machine has been deployed the Bloomberg API, you can find the real jar file in your hard drive, for example,
Note that the version number of the API may be automatically upgraded by Bloomberg.
The code for connecting, downloading and saving the tickdata is located in the package
com.numericalmethod.algoquant.data.historicaldata.bloomberg. You can find in the package a simple demo application “
TickDataDownloadApp“, which accepts command-line arguments and downloads tickdata of a given period for a given security:
Usage: TickDataDownloadApp <security> <startDate (yyyy-MM-dd)> <endDate (yyyy-MM-dd)> <output dir>
Note that the start date should be within 140 days as it is the oldest history you can download from Bloomberg.
Here is how it works. The Bloomberg system provides a core service named “
//blp/refdata” which allows downloading a wide range of market data. The code opens a session to connect to the
localhost at port
8194 (change the settings in
SimpleSessionFactory if you are using a different port). Then, it sends the
IntradayTickRequest with the security symbol, start and end dates. Upon receiving the response, the
BloombergTickDataFileWriter saves the data as zipped CSV files in the specified output folder (one file per trading day). For example,
TickDataDownloadApp "5 HK Equity" 2012-12-01 2012-12-21 data
will save the data as
.csv.zip files in the folder “
data/5 HK Equity“.
Since AlgoQuant is source-available, you are free to change the code to download different data, or save the data into your database instead of files.
Happy downloading data! 🙂
Reference: Bloomberg API Version 3.x Developer’s Guide