/stock-prices-storage

Simple storage for stock prices with adjusted prices calculation based on Center for Research in Security Prices (CRSP) standards

Primary LanguagePython

Stock Prices Storage

Stock Prices Storage is a simple storage (Clickhouse is used as a database) for stock prices with adjusted prices calculation (see Center for Research in Security Prices (CRSP) standards and this article for more details).

Storage is managed with make.sh (wrapper around manage.py), run make.sh to see a list of all supported actions. Also, most common actions can be performed with make command (see Makefile for more details).

Clickhouse

Basic versions of Clickhouse server and client can be started with Docker.

Clickhouse server can be started with (it will be started in detached mode):

make clickhouse-server

Clickhouse client can be started with:

make clickhouse-client

Virtual Python environment

Virtual Python environment with all required packages can be created with:

make venv-recreate

Working with storage

Recreating DB schema:

make reset

Importing example Quandl WIKI Prices for Apple (AAPL) and Microsoft (MSFT) from _example/quandl-WIKI-AAPL-MSFT.csv:

make example-quandl-import

Merging imported data into internal tables, duplicates control:

make merge

Recalculating all adjusted prices:

make adjust

Getting calculated adjusted prices and comparing them with original Quandl WIKI Prices:

make example-quandl-get

Output of final make example-quandl-get is shown below. As you can see, calculated adjusted prices are very similar to the adjusted prices from Quandl.

QUANDL DATA:
ticker,date,open,high,low,close,volume,ex-dividend,split_ratio,adj_open,adj_high,adj_low,adj_close,adj_volume
AAPL,1980-12-12,28.75,28.87,28.75,28.75,2093900.0,0.0,1.0,0.42270591588018,0.42447025361603,0.42270591588018,0.42270591588018,117258400.0
MSFT,1986-03-13,25.5,29.25,25.5,28.0,3582600.0,0.0,1.0,0.058941410012893,0.067609264426554,0.058941410012893,0.064719979622,1031788800.0

FOUND:
  - symbol: AAPL
  - date: 1980-12-12
  - open: 28.75
  - high: 28.87
  - low: 28.75
  - close: 28.75
  - adjusted_open: 0.4228
  - adjusted_high: 0.4245
  - adjusted_low: 0.4228
  - adjusted_close: 0.4228

FOUND:
  - symbol: MSFT
  - date: 1986-03-13
  - open: 25.5
  - high: 29.25
  - low: 25.5
  - close: 28
  - adjusted_open: 0.0588
  - adjusted_high: 0.0674
  - adjusted_low: 0.0588
  - adjusted_close: 0.0645