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 = rhoa.read_csv('stock_prices.csv')

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

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

# Calculate Bollinger Bands
bb = df['Close'].rhoa.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.rhoa.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 = rhoa.read_csv('prices.csv')

# Calculate RSI
rsi = df['Close'].rhoa.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'].rhoa.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'].rhoa.indicators.sma(20)
df['RSI_14'] = df['Close'].rhoa.indicators.rsi(14)
df['ATR_14'] = df['Close'].rhoa.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.2.0.tar.gz (60.4 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.2.0-py3-none-any.whl (55.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for rhoa-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5e3bca000a204bced0ada74494984884693dd2c3ef1b64b9a15b8ec4499b2881
MD5 36d6a3021bb4851a8ee144f087560bc0
BLAKE2b-256 362fe6b84a97afc220c3fe644afa186fcc62c05fdcdc99281dbaf9b041a39935

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rhoa-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 55.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92b10429201ff25b640b03e58b42a85babaf44de03d70e7a4e65cd07ef9f1e73
MD5 dd1e2e732afeb92161765b9d82abb2e9
BLAKE2b-256 d00b9d5946c2e71d1a25cbe90c69ece70464fcea8d8680dfe4a732efae54d0da

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