Python wrapper for TA-LIB providing 175+ technical analysis indicators for financial market data
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Functions that transform OHLC data into standardized price representations for further analysis. These transformations combine multiple price points into single representative values, providing different perspectives on price action.
Calculates the arithmetic mean of open, high, low, and close prices, providing a balanced representation of price activity.
def AVGPRICE(open, high, low, close):
"""
Average Price
Formula: (open + high + low + close) / 4
Parameters:
- open: array-like, open prices
- high: array-like, high prices
- low: array-like, low prices
- close: array-like, close prices
Returns:
numpy.ndarray: Average price values
"""Calculates the midpoint between high and low prices, representing the middle of the trading range.
def MEDPRICE(high, low):
"""
Median Price
Formula: (high + low) / 2
Parameters:
- high: array-like, high prices
- low: array-like, low prices
Returns:
numpy.ndarray: Median price values (midpoint of range)
"""Calculates the average of high, low, and close prices, giving equal weight to the three key price points.
def TYPPRICE(high, low, close):
"""
Typical Price
Formula: (high + low + close) / 3
Parameters:
- high: array-like, high prices
- low: array-like, low prices
- close: array-like, close prices
Returns:
numpy.ndarray: Typical price values
"""Calculates a weighted average emphasizing the close price, which is often considered the most important price of the period.
def WCLPRICE(high, low, close):
"""
Weighted Close Price
Formula: (high + low + 2*close) / 4
Parameters:
- high: array-like, high prices
- low: array-like, low prices
- close: array-like, close prices
Returns:
numpy.ndarray: Weighted close price values
"""import talib
import numpy as np
# Sample OHLC data
open_prices = np.array([100.0, 101.0, 102.0, 101.5, 103.0])
high_prices = np.array([100.8, 102.2, 102.5, 102.0, 103.5])
low_prices = np.array([99.2, 100.5, 101.0, 100.8, 102.5])
close_prices = np.array([100.5, 101.8, 101.2, 102.2, 103.2])
# Calculate different price transforms
avg_price = talib.AVGPRICE(open_prices, high_prices, low_prices, close_prices)
med_price = talib.MEDPRICE(high_prices, low_prices)
typ_price = talib.TYPPRICE(high_prices, low_prices, close_prices)
wcl_price = talib.WCLPRICE(high_prices, low_prices, close_prices)
print("Latest prices:")
print(f"Average Price: {avg_price[-1]:.2f}")
print(f"Median Price: {med_price[-1]:.2f}")
print(f"Typical Price: {typ_price[-1]:.2f}")
print(f"Weighted Close Price: {wcl_price[-1]:.2f}")
# These transformed prices are commonly used as:
# - Input to other technical indicators instead of close price
# - Basis for pivot point calculations
# - Representative price for volume-weighted calculations
# - Smoothed price series for trend analysis