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.1.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.2.1-py3-none-any.whl (55.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rhoa-0.2.1.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.2.1.tar.gz
Algorithm Hash digest
SHA256 7a5062ba29f1c1f5925f2c55ed1d24d1c8830b9dbad9b950a03098179d6deb97
MD5 65833ee854de8578d76aaf2dfa68aa30
BLAKE2b-256 6013ab0e78e205da4c51a2f9a146633e4595b6aa7d5d80c230221478bb3fa313

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rhoa-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9040fad1438e911ba25a2e3385b88e468f3ae486625211804a20057691f49003
MD5 c2bbd693832f7f07310fe2978f470068
BLAKE2b-256 fd83461ebe3d0a9bb00bd9af6d1a3c2bbeeab1dbbe67c4e0abc2ccf8899d79d7

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