Skip to main content

High-performance vectorized Pine Script indicators for ML and backtesting

Project description

PythonPine v2.0 - High-Performance Technical Indicators

Vectorized Pine Script indicators for machine learning and algorithmic trading. 10-100x faster than loop-based implementations.

Features

  • NumPy/Pandas Vectorization - Millions of bars in seconds
  • 🧠 ML Alpha Module - Z-score, percentile rank, fractional differentiation
  • 📊 50+ Indicators - RSI, MACD, ATR, Bollinger, SuperTrend, Ichimoku...
  • 🔄 Pine Script Parity - Same signatures, same math
  • 📈 Price Action - Vectorized pattern detection

Installation

pip install pythonpine

Quick Start

import numpy as np
from pythonpine import rsi, macd, atr, zscore

# Your price data
close = np.random.randn(10000).cumsum() + 100
high = close + np.abs(np.random.randn(10000)) * 0.5
low = close - np.abs(np.random.randn(10000)) * 0.5

# Calculate indicators (returns NumPy arrays)
rsi_values = rsi(close, 14)
macd_line, signal, hist = macd(close)
atr_values = atr(high, low, close, 14)

# ML preprocessing
rsi_zscore = zscore(rsi_values, 20)  # Normalized for ML

ML Alpha Module

from pythonpine import zscore, percentile_rank, log_returns, fractional_diff

# Stationarity transforms
returns = log_returns(close)
frac_diff = fractional_diff(close, d=0.4)  # López de Prado method

# Feature engineering
rsi_z = zscore(rsi(close), 50)  # Z-score normalized RSI
rsi_rank = percentile_rank(rsi(close), 100)  # Percentile rank

Benchmarks

Indicator Legacy (loop) V2 (vectorized) Speedup
RSI 1.2s 0.01s 120x
MACD 0.8s 0.008s 100x
ATR 0.5s 0.005s 100x
Bollinger 0.9s 0.007s 130x

Tested on 1M bars

Indicator Reference

Momentum

  • rsi(close, 14) - Relative Strength Index
  • macd(close, 12, 26, 9) - MACD line, signal, histogram
  • stochastic(close, high, low) - Stochastic Oscillator
  • adx(high, low, close) - Average Directional Index
  • cci(close, high, low) - Commodity Channel Index

Volatility

  • atr(high, low, close, 14) - Average True Range
  • bollinger_bands(close, 20, 2) - Upper, lower, middle
  • keltner_channel(high, low, close) - Keltner bands
  • historical_volatility(close, 20) - HV annualized

Trend

  • sma(close, 20) - Simple Moving Average
  • ema(close, 20) - Exponential MA
  • supertrend(high, low, close) - Trend direction + line
  • ichimoku(high, low, close) - Full cloud

Price Action

  • engulfing(o, h, l, c) - Returns +1 (bullish), -1 (bearish), 0
  • doji(o, h, l, c) - Doji detection
  • support_resistance_zones(h, l, c, v) - Volume-based S/R

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pythonpine-2.0.0.tar.gz (38.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pythonpine-2.0.0-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

Details for the file pythonpine-2.0.0.tar.gz.

File metadata

  • Download URL: pythonpine-2.0.0.tar.gz
  • Upload date:
  • Size: 38.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pythonpine-2.0.0.tar.gz
Algorithm Hash digest
SHA256 ddec84d5b7049d50aed65d5c44ef71c2342429447a92ce9d8d705f609ce08b05
MD5 5d9aab0a96f653393d1049cab7755737
BLAKE2b-256 19cb449801440339320a9a321e2d8305ccc78cd90c13fe8e107735434449517c

See more details on using hashes here.

File details

Details for the file pythonpine-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pythonpine-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 43.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pythonpine-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e966c1a24e5acaddda4a7e431117c012a76103374c49b9f15843891036a6264
MD5 cba45da44edab20594127af37d6f52b2
BLAKE2b-256 4b50dcedf212fc37557785d7ff773a2fd115b0ad5deb0dbf3d04ac1e4aa7ae21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page