Quickstart

Usage

Defining the financial instruments and formats You can use the dxlib.Schema and dxlib.SecurityManager classes to define the financial instruments and formats.

import dxlib as dx

tickers = ['AAPL', 'GOOG', 'MSFT']

security_manager = dx.SecurityManager.from_list(tickers)
print(security_manager)

schema = dx.Schema(
    levels=[dx.SchemaLevel.SECURITY],
    fields=['price'],
    security_manager=security_manager
)
print(schema)
SecurityManager(3)
Schema(levels=[<SchemaLevel.SECURITY: 'security'>], fields=['price'], security_manager=SecurityManager(3))

Creating a history of prices You can use the dxlib.History class to store the history of a stock.

import dxlib as dx
import datetime

data = {
    (datetime.datetime(2015, 1, 1), 'AAPL'): {'open': 100, 'high': 105, 'low': 95, 'close': 100, 'volume': 1000000},
    (datetime.datetime(2015, 1, 2), 'AAPL'): {'open': 100, 'high': 105, 'low': 95, 'close': 100, 'volume': 1000000},
}

schema = dx.Schema(
    levels=[dx.SchemaLevel.DATE, dx.SchemaLevel.SECURITY],
    fields=['open', 'high', 'low', 'close', 'volume'],
    security_manager=dx.SecurityManager.from_list(['AAPL'])
)

history = dx.History(data, schema)
print(history)
                          open  high  low  close   volume
date       security                                      
2015-01-01 AAPL (equity)   100   105   95    100  1000000
2015-01-02 AAPL (equity)   100   105   95    100  1000000

Executing a strategy

import dxlib as dx

strategy = dx.strategies.RsiStrategy()

tickers = ['AAPL', 'GOOG', 'MSFT']
security_manager = dx.SecurityManager.from_list(tickers)

schema = dx.Schema(
    levels=[dx.SchemaLevel.DATE, dx.SchemaLevel.SECURITY],
    fields=['open', 'high', 'low', 'close', 'volume'],
    security_manager=security_manager
)