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.8.tar.gz (59.9 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.8-py3-none-any.whl (53.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rhoa-0.1.8.tar.gz
  • Upload date:
  • Size: 59.9 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.8.tar.gz
Algorithm Hash digest
SHA256 7c38ee69a9a94db07c5c5e20b9ded2c29258f1d91ce2ea21f2536e4f2b167190
MD5 bee7dc14fa5899de874a3611a86a7188
BLAKE2b-256 2b634aea7174bc5fef6fcc8af763a26031d593a653f91f74f88092cfbf246cf0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rhoa-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 53.8 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d85087df53c6fd41f862b6589b41bd5cb697bbc5c29427138ef31d8ead39b806
MD5 c993c140857b014f0fb146014298e784
BLAKE2b-256 be851010f06f58c0653962703b765e3345f69e9344553a2608660c01e7a822e3

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