Skip to main content

A pandas DataFrame extension for technical analysis.

Project description

Rhoa Logo

Development Status PyPI version Documentation License Python versions

Rhoa is a Python package providing pandas DataFrame extension accessors for technical analysis and machine learning in financial markets.


🎯 Features

  • 📊 13 Technical Indicators - Professional-grade indicators accessible via pandas Series extension

    • Moving averages (SMA, EWMA)
    • Momentum oscillators (RSI, MACD, Stochastic, Williams %R, CCI)
    • Volatility indicators (ATR, Bollinger Bands, EWMSTD)
    • Trend indicators (ADX, Parabolic SAR)
  • 🤖 ML Target Generation - Intelligent binary target generation for machine learning

    • Auto mode with Pareto optimization
    • Manual mode with elbow method
    • 8 different target calculation methods
    • Optimal threshold detection
  • 📈 Visualization - Professional charting for prediction analysis

    • Price charts with buy signals
    • Confusion matrices
    • Color-coded performance markers
    • Publication-quality output
  • 🔗 Pandas Integration - Seamless integration with pandas workflows

    • Native DataFrame/Series accessors
    • Method chaining support
    • Type hints throughout

🚀 Quick Start

Installation

pip install rhoa

Basic Usage

import pandas as pd
import rhoa

# Load your price data
df = pd.read_csv('stock_prices.csv')

# Calculate technical indicators using Series accessor
df['SMA_20'] = df['Close'].indicators.sma(window_size=20)
df['RSI_14'] = df['Close'].indicators.rsi(window_size=14)

# Calculate MACD
macd_data = df['Close'].indicators.macd()
df['MACD'] = macd_data['macd']
df['Signal'] = macd_data['signal']

# Calculate Bollinger Bands
bb = df['Close'].indicators.bollinger_bands(window_size=20, num_std=2.0)
df['BB_Upper'] = bb['upper_band']
df['BB_Lower'] = bb['lower_band']

Generate ML Targets

from rhoa.targets import generate_target_combinations

# Generate optimized binary targets with Pareto optimization
targets, metadata = generate_target_combinations(
    df,
    mode='auto',
    target_class_balance=0.5  # Aim for 50% positive instances
)

# Check what parameters were found optimal
print(metadata['method_7'])
# {'period': 6, 'threshold': 4.0, 'instances': 249, 'pct_of_max': 8.9}

# Combine with features for ML pipeline
ml_data = pd.concat([df, targets], axis=1)

Visualize Predictions

# After training your model and getting predictions
predictions = model.predict(X_test)

# Plot with confusion matrix
fig = df.plots.signal(
    y_pred=predictions,
    y_true=y_test,
    date_col='Date',
    price_col='Close'
)

📚 Documentation

Full documentation is available at https://nainajnaho.github.io/Rhoa/

💡 Examples

Example 1: Find Overbought Conditions

import pandas as pd
import rhoa

df = pd.read_csv('prices.csv')

# Calculate RSI
rsi = df['Close'].indicators.rsi(window_size=14)

# Find overbought periods (RSI > 70)
overbought = df[rsi > 70]
print(f"Found {len(overbought)} overbought periods")

Example 2: Detect MACD Crossovers

# Calculate MACD
macd_data = df['Close'].indicators.macd()
macd = macd_data['macd']
signal = macd_data['signal']

# Find bullish crossovers
bullish = (macd > signal) & (macd.shift(1) <= signal.shift(1))
print(f"Bullish crossovers: {bullish.sum()}")

Example 3: Complete ML Pipeline

from rhoa.targets import generate_target_combinations
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split

# Generate features
df['SMA_20'] = df['Close'].indicators.sma(20)
df['RSI_14'] = df['Close'].indicators.rsi(14)
df['ATR_14'] = df['Close'].indicators.atr(df['High'], df['Low'], 14)

# Generate targets
targets, meta = generate_target_combinations(df, mode='auto')

# Prepare data
X = df[['SMA_20', 'RSI_14', 'ATR_14']].dropna()
y = targets['Target_7'].loc[X.index]

# Train model
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)

print(f"Accuracy: {model.score(X_test, y_test):.2%}")

🛠️ Development Status

Rhoa is currently in pre-alpha development (v0.1.7). The API may change between versions.

Roadmap

  • Core technical indicators (In progress...)
  • ML target generation (In progress...)
  • Visualization tools (In progress...)
  • Strategy framework
  • Advanced preprocessing utilities
  • Backtesting engine

📋 Requirements

  • Python >= 3.9
  • pandas >= 1.3
  • numpy >= 1.21

Optional dependencies for specific features:

  • kneed - For elbow method in target generation
  • paretoset - For Pareto optimization
  • scikit-learn - For confusion matrices
  • matplotlib - For visualization
  • seaborn - For enhanced plotting

📄 License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

🔗 Links

📊 Project Status

GitHub last commit GitHub issues


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

rhoa-0.1.9.tar.gz (60.5 kB view details)

Uploaded Source

Built Distribution

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

rhoa-0.1.9-py3-none-any.whl (55.2 kB view details)

Uploaded Python 3

File details

Details for the file rhoa-0.1.9.tar.gz.

File metadata

  • Download URL: rhoa-0.1.9.tar.gz
  • Upload date:
  • Size: 60.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for rhoa-0.1.9.tar.gz
Algorithm Hash digest
SHA256 f26f52ef3e7c79955e8003a57cbd6f719a45e5659f37878eb500605bd5070c28
MD5 e0d3744b6c401a0820f767cbe624ac0d
BLAKE2b-256 49db074ad8c654c69e43d4f53f4a06a7f37841d79432cc9bf53fce55d3f3b1f8

See more details on using hashes here.

File details

Details for the file rhoa-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: rhoa-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 55.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for rhoa-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 7c39e5640fe99fed017158cdbc23356017fbad424121d4e7339eaa1129a40d7f
MD5 ae51b3acd64109a2e0b3ab82e7c9e9f7
BLAKE2b-256 f0e16fc024959ccc147a9b7159c90f5777de53df7aadbd9958a14dbccd533824

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