ohlc: open-high-low-close types and tools
Project description
Ohlc: Types + Tools for Open-High-Low-Close Values
Ohlc provides Ohlc
, a namedtuple
for storing and efficiently processing
open-high-low-close data, used for financial charts and calculations.
It also provides tools for processing, generating, and visualizing lists of Ohlc
values in the console.
Installation
pip install ohlc
Using the Data Type
from ohlc import Ohlc
o = Ohlc.from_values([2,5,4,7,11,7,2,9,5]) # Ohlc(open=2, high=11, low=2, close=5)
o.spread() # 9
o = Ohlc(3,4,1,2) # Ohlc(open=3, high=4, low=1, close=2)
o == (3,4,1,2) # True -- Yeay! It is a regular tuple!
o1 = Ohlc.from_values(range(5,15)) # Ohlc(open=5, high=14, low=5, close=14)
o2 = Ohlc.from_values(range(14,3,-1), prev=o1) # Ohlc(open=14, high=14, low=4, close=4)
o3 = Ohlc.from_values(range(5,20), prev=o2) # Ohlc(open=5, high=19, low=5, close=19)
o3.heikin() # compute Heikin-Ashi candle from Ohlc chain
# Ohlc(open=9.0, high=19, low=5, close=12.0)
Formatting Values
for o in [o1,o2,o3]: print(o.format()) # 5.000000 14.000000 5.000000 14.000000
# 14.000000 14.000000 4.000000 4.000000
# 5.000000 19.000000 5.000000 19.000000
print(o.format(sep=',')) # 5.000000,19.000000,5.000000,19.000000
print(o.format(sep='', fmt='{:d}\n')) # 5
# 19
# 5
# 19
Transformation + Aggregation
o1 # Ohlc(open=5, high=14, low=5, close=14)
o1.transform(scale=1.25, offset=1) # Ohlc(open=7.5, high=18.75, low=7.5, close=18.75)]
agg = o.from_ohlc_list([o1,o2,o3]) # Ohlc(open=5, high=19, low=4, close=19)
Ohlc Plotting
For plotting, the class ohlc.candles.CandleCanvas
provides raw colored console output
using terminal colors, but also supports styled output for embedding in
urwid console apps.
A simpe plotter (powered by urwid + widdy widgets)
can be started using the provided ohlc
command.
# start the ohlc candlestick visualization using random values, heikin-ashi candles,
# price action bars (colors), and the chart title: 'Candles'
ohlc --pab --ha --random --title 'Candles'
Omitting most options produces classic candle stick charts.
ohlc --random --title 'Classic Candles'
To plot input data do not use /dev/stdin
(this is already used by urwid).
Use a file or file descriptor as the positional input
argument to ohlc
.
# plot some input data
ohlc <(echo -e "8 11 7 4 5\n5 4 8 6\n6\n6 5\n5 6 1 4") --title "Input"
Tools
The command ohlc-input
computes an Ohlc
tuple for each input line and pipes out the four values.
ohlc-input <(echo 3 4 1 6; echo 6 1 6 2; echo 1 3 8 2)
# 3.000000 6.000000 1.000000 6.000000
# 6.000000 6.000000 1.000000 2.000000
# 1.000000 8.000000 1.000000 2.000000
The command ohlc-random
generates and prints random Ohlc
values.
ohlc-random --data_rate 1
# 0.100000 0.100000 0.073059 0.076472
# 0.076472 0.106526 0.073043 0.104767
# 0.104767 0.146023 0.098335 0.142284
# 0.142284 0.169882 0.118809 0.162817
# 0.162817 0.164071 0.131635 0.140002
# 0.140002 0.140246 0.111727 0.124778
Development
First clone/fork the repo.
git clone https://github.com/ubunatic/ohlc
cd ohlc
Then install the cloned version and install any missing tools.
make # clean and run all tests
make install # install the checked-out dev version
make build # transpile Py3 to Py2
You may need to install some tools and modules, i.e., flake8
, pytest
, twine
, urwid
,
and maybe others.
Do not customize project.mk
. This is fancy cross-project Makefile inclusion to handle
building, packaging, publishing, and testing in general.
Pull requests are welcome!
Open Issues (by priority)
- bug: try detect unicode support and fallback to ASCII (e.g., in default iTerm2 on OSX)
- example: BTC Ticker or Custom Symbol Ticker
- usability: react on urwid resizing events
- musthave: add or allow adding
datetime
toOhlc
tuples - feature: draw correct time axis
- feature: set candle interval (5m 15m 30m 1h 4h, 6h, 1d, 3d, 1w, 1M, etc.)
- feature: add axis labels
- feature: support for bright color scheme
- feature: scrolling over all cached data
- feature: interactively shrink/grow the canvas (adjust top/bottom padding)
- feature: allow setting the cache size
- feature: allow seeking over input files
- feature: monitor CPU usage and reduce redraw (big + fast charts are still very expensive)
- example: Iteractive Ticker
- example: MultiChart App
- example: MultiChart Tickers
- example: Interactive MultiChart Tickers
- feature: indiator overlays (RSI, EMA12, EMA26, etc.)
- feature: indicators bars below chart (price action colored volume bars)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.