Menu

Overview

Michael Martinez

Overview of the code and software design

The project is currently splitted into two parts:

  • Python modules for retrieving financial market data from two websites:

    • Boursorama.com provides (more or less) real-time access to the market. The website does not provide APIs to query the data, the HTML pages are parsed by the class Parser_Bourso. The parser need to be updated when the design of the pages are modified.
    • Yahoo is used for historical (daily) updates. The CSV API from Yahoo!Finace make easy the download of historical quotes.

These modules are used to query those websites directly to get instantaneous data or to update periodically (e.g. 30 sec.) the values of a predefined list of stocks/devises (see the [Usage] page).

  • C++ application divided into modules and subdirectories:

    • The utils/ directory contains common functionalities shared by the whole application: enumerations (TimeScale, Indicator), utilities functions (Utils, FullName) generally static functions defined in their own namespace, base classes for an observer-subject pattern and a general file handling exception class.
    • In src_cpp/ are defined the model to store time series data, wrapper functions to embed the Python modules, the interface to TA-lib for computing technical indicators and a TCP server listening for the real time update of the data by the ServerPortfolio Python module. Only the STL, Boost and TA-lib libraries are required for the compilation. All modules are compiled in an independent shared library: libstock.so
    • In src_gui_root/ is implemented the GUIStock application with the graphical user interface within the ROOT framework. It follows as much as possible a MVC pattern (model in src_cpp) enforced by splitting the source code in subdirectories (Controllers/, View/). The drawable objects and their properties (lines, japanese candles, bars...) are defined in a separate library: libobjectstock.so

Software design

The model

The model consists of the storage of time series of market quotes, its update through the ServerPortfolio modules and the computation of techinal indicators. All classes are defined in libstock.so

Storage and retrival of data

A vector (StockManager::vec_stock) stores all Stock in memory. The class StockManager is defined as a singleton class and conveniently implements the most used functionnalities on the stocks (Loading/getting stocks, updating data and computing indicators) as wrapper functions to Stock member functions. It can be easily retrieved and used by an other application linked with libstock.so with the static function:

StockManager *fstockmanager = StockManager::getInstance(Utils::PATH_DATA);

It also owns a TCPServer object used for receiving data update from the ServerPortfolio Python modules in real-time mode.

This class represents the main dependency between the graphical interface and the model.

Stock is the main class for dealing with the financial data. To each object is associated a quote: a share, an indice or a devise. The time-series data (values of the quotes and indicators) are stored in a map with the TimeScale as key and a vector of ListDataStock as value.

The timescale (Utils/TimeScale.h) data consists of an enumeration for the time representation: intantaneous, 5 minutes, 10 minutes, daily, weekly... Only instantaneous (dCSV) or daily data (CSV) are stored on the filesystem (in data/csv or dcsv), other timescales are computed from them with Stock::Transform_TimeScale.

Templates and template policies for time series data in ListDataStock

Values of the stocks and indicators are stored in a vector defined in the ListDataStock class.

The first requirement was to store different data types:

  • Quotes consists of a date and opening, closing, lowest and highest quotes (DataStock::DataCSV)
  • Most indicators (average, MACD...) are defined by a date and an unique or multiple values (DataStock::SimpleData and DataStock::MultiData).

Then ListDataStock is defined as a template instantiated for each data type, e.g. ListDataStock<DataCSV>

To Store ListDataStocks as a value of the Stock's map (stored as pointer in a vector), all ListDataStock<> derive from a base class: ListDataStockBase

An arbitrary choice concerns the chronological ordering of the data in the vector. CSV format is usually presented from the newest to the oldest data (non-chronological), the TA-lib library expects input data in the chronological order, other algorithms are easier to implement either in a chronological or non-chronological order.

To solve this problem, a class template policy has been implemented for ListDataStock.
PolicyChronologic.h defines 2 class templates: VecChronologic and VecNoChronologic, which will indicate which ordering scheme has been chosen. Theses classes provide specific implementations for functions like:

  • ListDataStock<>::ChronologicAt(), ListDataStock<>::NoChronologicAt() : Allows to loop in a chronological or non chronological order, whatever the internal policy used.
  • ListDataStock::Order() : re-order the data (done by a call to swap) in a specified order. If the data are initially in the correct order, nothing is done (at compilation time).

By default the storage order is non-chronologic for daily (weekly, monthly) data and chronologic for intantaneous data.

Python/C++ bindings

2 forms of binding between Python and C++ are used:

  • The extension of Python with the C++ model is defined in wrapPyStock.so. The library contains some wrapper functions to the Stock objects and deals with the query and update of the data on the filesystem.
  • The embedding of Python in C++ allows to load Python modules, create objects and call their member functions directly from the C++ application. All functions are implemented in StockwrapPyParser.cpp and declared in Stock.h. Their first usage is to call the parser functionnalities only written in Python.

TA-lib interface

Why the ROOT framework ?

MVC pattern of the GUI


Related

Wiki: Usage