Skip to main content

No project description provided

Project description

Stockula

Python 3.13+ License: MIT codecov

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.

โœจ 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

  1. Install uv (if not already installed):

    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  2. 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

๐Ÿ“– User Guide

๐Ÿ”ง API Reference

๐Ÿ› ๏ธ Development

  • Testing - Test suite and coverage
    • Guide - Guide for writing and running tests for Stockula
    • Strategies - Strategy testing best practices
  • CI/CD - Continuous integration and deployment with GitHub Actions

๐Ÿ” Help

๐Ÿ—๏ธ 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
  • 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/amd64 and linux/arm64/v8
    • Publishes to GitHub Container Registry

Commit Guidelines

This project uses Conventional Commits:

  • feat: New features
  • fix: Bug fixes
  • chore: Maintenance tasks
  • docs: Documentation updates
  • test: Test additions or changes

๐Ÿ”— Links

๐Ÿ“ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

Contributions are welcome! Please see our Contributing Guide for development setup and guidelines.

Development Setup

  1. Install pre-commit hooks:

    uv run pre-commit install
    
  2. 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
    
  3. Manual pre-commit run:

    uv run pre-commit run --all-files
    

This project uses:


๐Ÿ“š For detailed documentation, examples, and API references, visit our comprehensive documentation site.

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

stockula-0.4.0.tar.gz (400.1 kB view details)

Uploaded Source

Built Distribution

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

stockula-0.4.0-py3-none-any.whl (95.1 kB view details)

Uploaded Python 3

File details

Details for the file stockula-0.4.0.tar.gz.

File metadata

  • Download URL: stockula-0.4.0.tar.gz
  • Upload date:
  • Size: 400.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for stockula-0.4.0.tar.gz
Algorithm Hash digest
SHA256 c948045dadd82c8d4270cb1afa4a16501ec0cb4375c96ba0ab4e03336b5ea73b
MD5 2fbc4e2aada63992b4dbd088707b01dc
BLAKE2b-256 acfee402a5864557b63c34a7a879a8ff30fb9b9628827ba1156d040fb40c64cb

See more details on using hashes here.

File details

Details for the file stockula-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: stockula-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 95.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for stockula-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aab497dd4ab6205e998d79845271ed82049cb114c27bedbdf3cdd67be861ff58
MD5 8a03745a5e9906474cbd97162c46a569
BLAKE2b-256 8600041b7d884039865787ca23deb096e1e3470ea37630ba2c1f81ddefae03cd

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