No project description provided
Project description
Stockula
Stockula is a comprehensive Python trading platform that provides tools for technical analysis, backtesting, data fetching, and price forecasting. Built with modern Python practices, it integrates popular financial libraries to offer a complete solution for quantitative trading strategy development.
- Stockula
โจ Features
- ๐ Technical Analysis: 40+ indicators (SMA, EMA, RSI, MACD, Bollinger Bands, etc.)
- ๐ Backtesting: Test trading strategies with realistic broker costs and commission structures
- ๐ Data Fetching: Real-time and historical market data via yfinance with intelligent SQLite caching
- ๐ฎ Price Forecasting: Automated time series forecasting using AutoTS with two modes:
- Future prediction mode: Forecast N days from today
- Historical evaluation mode: Train/test split with accuracy metrics (RMSE, MAE, MAPE)
- ๐จ Rich CLI Interface: Beautiful progress bars, tables, and colored output
- ๐๏ธ Database Caching: Automatic SQLite caching for offline analysis and fast data access
- ๐ Modern Python: Built with uv for fast package management and Pydantic for configuration
๐ Quick Start
Installation
-
Install uv (if not already installed):
curl -LsSf https://astral.sh/uv/install.sh | sh
-
Clone and install:
git clone https://github.com/mkm29/stockula.git cd stockula uv sync
Basic Usage
# Analyze a single stock
uv run python -m stockula.main --ticker AAPL
# Run with configuration file
cp examples/config.simple.yaml .config.yaml
uv run python -m stockula.main
# Run specific analysis modes
uv run python -m stockula.main --ticker GOOGL --mode ta # Technical analysis
uv run python -m stockula.main --ticker MSFT --mode backtest # Backtesting (results sorted by return, highest first)
uv run python -m stockula.main --ticker NVDA --mode forecast # Forecasting (results sorted by return, highest first)
Configuration Example
data:
start_date: "2023-01-01"
end_date: null
portfolio:
initial_capital: 100000
allocation_method: equal_weight
tickers:
- symbol: AAPL
quantity: 10
- symbol: GOOGL
quantity: 5
backtest:
initial_cash: 10000.0
broker_config:
name: "robinhood" # Zero commission + TAF
strategies:
- name: smacross
parameters:
fast_period: 10
slow_period: 20
Forecast Evaluation
When running forecasts in evaluation mode (with train/test split), Stockula provides accuracy metrics:
Portfolio Value
โโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโณโโโโโโโโโโโโโ
โ Metric โ Date โ Value โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Observed Value โ 2025-04-01 โ $20,000.00 โ
โ Predicted Value โ 2025-04-30 โ $20,201.99 โ
โ Accuracy โ 2025-04-30 โ 92.4190% โ
โโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโโโโ
How Accuracy is Calculated:
Portfolio accuracy is calculated as: Accuracy = 100% - MAPE
Where MAPE (Mean Absolute Percentage Error) measures the average percentage difference between predicted and actual prices. For example:
- If a stock's MAPE is 6.11%, its accuracy is 93.89%
- The portfolio accuracy is the average of all individual stock accuracies
This provides an intuitive measure where:
- 100% = Perfect prediction
- 90%+ = Excellent forecast
- 80-90% = Good forecast
- <80% = Consider improving model or data
๐ Documentation
For comprehensive documentation, visit our MkDocs Documentation Site:
๐ Getting Started
- Installation Guide - Detailed setup instructions
- Quick Start - Common workflows and examples
- Configuration - Complete configuration reference
๐ User Guide
- Architecture Overview - System design and data flow
- Data Fetching - Market data and caching system
- Technical Analysis - 40+ indicators and usage
- Backtesting - Strategy testing with realistic costs
- Forecasting - AutoTS time series prediction
- Forecasting Models - Fast & full financial model details
- Rich CLI Features - Enhanced command-line interface
๐ง API Reference
- Strategies API - Built-in and custom trading strategies
- Broker Configuration - TODO Commission structures and fee models
- Data Models - TODO Pydantic models and validation
- Database API - TODO SQLite operations and CLI
๐ ๏ธ Development
- Testing - Comprehensive testing guide, strategy, and coverage
- CI/CD - Continuous integration and deployment with GitHub Actions
๐ Help
- Troubleshooting - Common issues and solutions
๐๏ธ Architecture
graph TB
subgraph "User Interface"
CLI[CLI main.py]
Config[Configuration<br/>.config.yaml]
end
subgraph "Core Domain"
Factory[Domain Factory]
Portfolio[Portfolio]
Asset[Asset]
end
subgraph "Data Layer"
Fetcher[Data Fetcher<br/>yfinance wrapper]
DB[(SQLite Database<br/>stockula.db)]
end
subgraph "Analysis Modules"
TA[Technical Analysis<br/>finta]
BT[Backtesting<br/>strategies]
FC[Forecasting<br/>AutoTS]
end
CLI --> Config
Config --> Factory
Factory --> Portfolio
TA --> Fetcher
BT --> Fetcher
FC --> Fetcher
Fetcher --> DB
style CLI fill:#2196F3,stroke:#1976D2,color:#fff
style Config fill:#4CAF50,stroke:#388E3C,color:#fff
style DB fill:#FF9800,stroke:#F57C00,color:#fff
๐ Requirements
- Python: 3.13 or higher
- Operating System: macOS, Linux, or Windows
- Memory: 8GB RAM recommended
- Storage: 100MB free space
Key Dependencies
- pandas: Data manipulation and analysis
- yfinance: Yahoo Finance data fetching
- finta: Financial technical analysis indicators
- backtesting: Strategy backtesting framework
- autots: Automated time series forecasting
- rich: Enhanced CLI formatting with progress bars and tables
- pydantic: Data validation and settings management
๐จ Rich CLI Examples
Progress Tracking
โ Backtesting SMACROSS on AAPL... โโโโโโโโโโโโโโโโโโโโโโโโโโโโ 85% 0:00:02
Results Tables
Portfolio Composition
โโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโโโโโณโโโโโโโโโโโโโณโโโโโโโโโโโโ
โ Ticker โ Category โ Quantity โ Allocation % โ Value โ Status โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ SPY โ INDEX โ 1.00 โ 0.7% โ $637.10 โ Hold Only โ
โ VOO โ INDEX โ 1.00 โ 0.6% โ $585.58 โ Hold Only โ
โ DFUSX โ INDEX โ 1.00 โ 0.0% โ $42.40 โ Hold Only โ
โ FSKAX โ INDEX โ 1.00 โ 0.2% โ $175.65 โ Hold Only โ
โ FSMDX โ INDEX โ 199.00 โ 7.8% โ $7,279.42 โ Hold Only โ
โ FXAIX โ INDEX โ 1.00 โ 0.2% โ $221.98 โ Hold Only โ
โ NVDA โ MOMENTUM โ 1.00 โ 0.2% โ $173.50 โ Tradeable โ
โ AMD โ MOMENTUM โ 1.00 โ 0.2% โ $166.47 โ Tradeable โ
โ TSM โ MOMENTUM โ 1.00 โ 0.3% โ $245.60 โ Tradeable โ
โ AAPL โ MOMENTUM โ 1.00 โ 0.2% โ $213.88 โ Tradeable โ
โ MSFT โ MOMENTUM โ 1.00 โ 0.5% โ $513.71 โ Tradeable โ
โ GOOGL โ MOMENTUM โ 1.00 โ 0.2% โ $193.18 โ Tradeable โ
โ AMZN โ MOMENTUM โ 1.00 โ 0.2% โ $231.44 โ Tradeable โ
โ META โ MOMENTUM โ 1.00 โ 0.8% โ $712.68 โ Tradeable โ
โ TSLA โ MOMENTUM โ 1.00 โ 0.3% โ $316.06 โ Tradeable โ
โ PLTR โ MOMENTUM โ 469.00 โ 79.7% โ $74,477.20 โ Tradeable โ
โ LIDR โ SPECULATIVE โ 1631.00 โ 7.7% โ $7,233.48 โ Tradeable โ
โ OPEN โ SPECULATIVE โ 1.00 โ 0.0% โ $2.54 โ Tradeable โ
โ SOFI โ SPECULATIVE โ 1.00 โ 0.0% โ $21.20 โ Tradeable โ
โ IONQ โ SPECULATIVE โ 1.00 โ 0.0% โ $43.17 โ Tradeable โ
โโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโโโ
Ticker-Level Backtest Results
Ticker-Level Backtest Results
โโโโโโโโโโณโโโโโโโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโณโโโโโโโโโณโโโโโโโโโโโ
โ Ticker โ Strategy โ Return โ Sharpe Ratio โ Max Drawdown โ Trades โ Win Rate โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ NVDA โ VIDYA โ +27.67% โ 1.50 โ -3.43% โ 0 โ N/A โ
โ NVDA โ SMACROSS โ +44.60% โ 0.64 โ -38.09% โ 9 โ 44.4% โ
โ NVDA โ DOUBLEEMACROSS โ +27.67% โ 1.50 โ -3.43% โ 0 โ N/A โ
โ NVDA โ VAMA โ +41.34% โ 0.59 โ -42.46% โ 9 โ 33.3% โ
โ NVDA โ ER โ +60.37% โ 1.20 โ -14.22% โ 10 โ 40.0% โ
| ... โ ... โ ... โ ... โ ... โ ... โ ... โ
โโโโโโโโโโดโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโโ
Strategy Summaries
Strategy summaries are displayed in descending order by "Return During Period" (highest returns first):
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ STRATEGY: DOUBLEEMACROSS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ
โ Parameters: Default โ
โ Broker: robinhood (zero-commission) โ
โ โ
โ Portfolio Value at Start Date: $19,997.94 โ
โ Portfolio Value at End (Backtest): $30,261.55 โ
โ โ
โ Strategy Performance: โ
โ Average Return: +51.32% โ
โ Winning Stocks: 12 โ
โ Losing Stocks: 2 โ
โ Total Trades: 22 โ
โ โ
โ Return During Period: $10,263.61 (+51.32%) โ
โ โ
โ Detailed report saved to: results/reports/strategy_report_doubleemacross_20250727_221642.json โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
๐ CI/CD
Continuous Integration
Stockula uses GitHub Actions for automated testing and deployment:
-
Testing (
test.yml): Runs on all pull requests and pushes to main- Linting: Code style checks with
ruff - Unit Tests: Fast, isolated tests with coverage reporting
- Integration Tests: Currently disabled, will test with SQLite database
- Linting: Code style checks with
-
Release Management (
release-please.yml): Automated versioning and releases- Monitors commits using Conventional Commits
- Creates release PRs automatically
- Publishes to PyPI on release
-
Docker Builds (
docker-build.yml): Multi-platform container images- Triggers on version tags (
v*) - Builds for
linux/amd64andlinux/arm64/v8 - Publishes to GitHub Container Registry
- Triggers on version tags (
Commit Guidelines
This project uses Conventional Commits:
feat:New featuresfix:Bug fixeschore:Maintenance tasksdocs:Documentation updatestest:Test additions or changes
๐ Links
- ๐ Full Documentation: docs/
- ๐ Issue Tracker: GitHub Issues
- ๐ก Feature Requests: GitHub Discussions
๐ License
MIT License - see LICENSE file for details.
๐ค Contributing
Contributions are welcome! Please see our Contributing Guide for development setup and guidelines.
Development Setup
-
Install pre-commit hooks:
uv run pre-commit install
-
Run tests and linting:
# Run tests uv run pytest # Run linting uv run ruff check src tests # Format code uv run ruff format src tests
-
Manual pre-commit run:
uv run pre-commit run --all-files
This project uses:
- Conventional Commits for commit messages
- Release Please for automated releases
- pre-commit for code quality checks
๐ For detailed documentation, examples, and API references, visit our comprehensive documentation site.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stockula-0.5.1.tar.gz.
File metadata
- Download URL: stockula-0.5.1.tar.gz
- Upload date:
- Size: 370.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa543b7aad9d68a8e8145e2f25016ea94ef8559f3b36c37fa6ab44420c249c00
|
|
| MD5 |
94784b521ca8ff1db50ee2c75d157bfc
|
|
| BLAKE2b-256 |
e8f3111794233f64d481c859362f8f7639ce5189f055256fe72aecb4a9250f6c
|
File details
Details for the file stockula-0.5.1-py3-none-any.whl.
File metadata
- Download URL: stockula-0.5.1-py3-none-any.whl
- Upload date:
- Size: 95.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
280c3304f1a3ad7ea52b8a57746e28fae97319009edab613a675f2ea9bff908b
|
|
| MD5 |
dcb2a3d0f6540f51dd59c4fd6b86cf9d
|
|
| BLAKE2b-256 |
ea2bbe78617487c291da91a585c39443c229120ba6751e26deccc13d0a22f225
|