ohlcutils
ohlcutils is a Python library designed for financial data analysis, focusing on OHLC (Open-High-Low-Close) data. It provides a comprehensive set of tools for calculating indicators, resampling data, and performing advanced market data transformations.
Features
- Indicators: A wide range of technical indicators, including moving averages, beta calculations, trend analysis, and support/resistance levels.
- Data Resampling: Flexible utilities for changing timeframes and aligning data.
- Support and Resistance: Tools for identifying key levels in market data.
- Beta and Ratio Adjustments: Functions for adjusting OHLC data based on benchmarks or beta values.
- Supertrend and VWAP: Built-in implementations of popular trading indicators.
- Charting: Interactive candlestick charts with support for multiple indicators and custom layouts using Plotly.
Installation
Clone the repository and install the required dependencies:
git clone https://github.com/your-repo/ohlcutils.git
cd ohlcutils
pip install -r requirements.txt
Modules Overview
Below is a list of available functions in each module. For detailed usage, use the help(function_name) command in Python.
indicators Module
align_dataframes_on_common_dates(dataframes)calculate_beta(md, md_benchmark, columns={"close": "asettle"}, window=252)calculate_ratio_bars(md, md_benchmark, columns={"open": "aopen", "high": "ahigh", "low": "alow", "close": "asettle"})calculate_beta_adjusted_bars(md, md_benchmark, beta_days=252, columns={"open": "aopen", "high": "ahigh", "low": "alow", "close": "asettle"})get_heikin_ashi(md, len2_ha=10)degree_slope(md, window, columns=["asettle"], prefix="deg", method="simple")average_band(md, size=100, ema=9, columns={"high": "ahigh", "low": "alow", "close": "asettle"})trend(md, bars=1, columns={"high": "ahigh", "low": "alow"})range_filter(md, per=100, mult=3, columns={"close": "asettle"})t3ma(md, len=5, volume_factor=0.7, columns={"close": "asettle"})bextrender(md, short_period=5, long_period=20, rsi_period=15, t3_ma_len=5, t3_ma_volume_factor=0.7, columns={"close": "asettle"})vwap(md, periods=21, columns={"close": "asettle", "volume": "avolume"})calc_rolling(x, periods, indicator, column_name="rolling")hilega_milega(md, rsi_days=9, ma_days=21, ema_days=3, columns={"close": "asettle"})supertrend(md, atr_period=14, multiplier=3.0, columns={"high": "ahigh", "low": "alow", "close": "asettle"})calc_sr(md, columns={"high": "ahigh", "low": "alow"})srt(md, days=124, columns={"close": "asettle"})
data Module
get_linked_symbols(short_symbol, complete=False)get_split_info(short_symbol)load_symbol(symbol, **kwargs)change_timeframe(md, dest_bar_size, bar_start_time_in_min="15min", exchange="NSE", label="left", fill="ffill", ...)
charting Module
plot(df_list, candle_stick_columns, indicator_columns=None, ta_indicators=None, title="", max_x_labels=10, separate_y_axes=None)- Description: Plots an interactive candlestick chart using Plotly.
- Features:
- Supports multiple DataFrames and overlays.
- Customizable indicators using
pandas-ta. - Separate y-axes for specific indicators.
- Simplified x-axis labels for better readability.
Example Usage
Calculate Beta
from ohlcutils.indicators import calculate_beta
import pandas as pd
# Load market data
md = pd.read_csv("market_data.csv", parse_dates=["date"], index_col="date")
md_benchmark = pd.read_csv("benchmark_data.csv", parse_dates=["date"], index_col="date")
# Calculate rolling beta
beta = calculate_beta(md, md_benchmark, columns={"close": "asettle"}, window=252)
print(beta)
Resample Data
from ohlcutils.data import change_timeframe
# Resample market data to 1-hour bars
resampled_data = change_timeframe(md, dest_bar_size="1H", exchange="NSE", label="left", fill="ffill")
print(resampled_data)
Plot Candlestick Chart
from ohlcutils.charting import plot
import pandas as pd
# Load market data
md = pd.read_csv("market_data.csv", parse_dates=["date"], index_col="date")
# Plot candlestick chart with indicators
plot(
[md],
candle_stick_columns={"open": "open", "high": "high", "low": "low", "close": "close", "volume": "volume"},
ta_indicators=[
{"name": "ema", "kwargs": {"length": 20}, "column_name": "ema_20", "target_column": "close"}
],
title="Market Data Chart",
separate_y_axes=["ema_20"],
)
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for ohlcutils 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ohlcutils-0.2.0.tar.gz | 37.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ohlcutils-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 75.4 kB
Release files / ohlcutils-0.2.0.tar.gz
| Download URL | ohlcutils-0.2.0.tar.gz |
|---|---|
| Size | 37.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2aa45842599365d28209e0f36710c29978acfa6bc31d9313700ce7b8d43ab0f7
|
|
BLAKE2b-256 checksum How to use checksums |
7f7a77b7841b07f2b5aacd7e1b80a9d171e20f4b7314f680298da8b7c108a3f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / ohlcutils-0.2.0-py3-none-any.whl
| Download URL | ohlcutils-0.2.0-py3-none-any.whl |
|---|---|
| Size | 37.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a68aab74025bccf3af706753ff23695b5245944ea5dee96ffd868a1c63383881
|
|
BLAKE2b-256 checksum How to use checksums |
c0c6629dc765aae6827edfcc5f2387923531c1ac44ca9b14c53d6bfaccc4e815
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|