Skip to main content

A professional Python quantitative trading library

Project description

DeltaFQ

PyPI version Python 3.8+ License: MIT

A professional Python quantitative trading library providing a complete toolkit for quantitative strategy development and research.

Features

  • 📊 Multi-source Data Support - Unified data interface supporting multiple data sources
  • 📈 Rich Technical Indicators - Built-in common technical indicators with custom extension support
  • 🎯 Flexible Strategy Framework - Clean API for rapid trading strategy development
  • Efficient Backtest Engine - Vectorized computation for fast strategy validation
  • 📉 Comprehensive Risk Management - Position management, risk control, and performance analysis
  • 🔧 Parameter Optimization Tools - Multiple optimization algorithms for finding optimal parameters
  • 📱 Live Trading Interface - Unified trading interface for seamless simulation and live trading

Installation

pip install deltafq

Or install from source:

git clone https://github.com/Delta-F/deltafq.git
cd deltafq
pip install -e .

Quick Start

Get Data

import deltafq as dfq

# Get stock data
data = dfq.data.get_stock_daily('000001.SZ', start='2020-01-01', end='2023-12-31')
print(data.head())

Calculate Technical Indicators

# Calculate moving averages
data['ma5'] = dfq.indicators.SMA(data['close'], 5)
data['ma20'] = dfq.indicators.SMA(data['close'], 20)

# Calculate MACD
macd = dfq.indicators.MACD(data['close'])
data = data.join(macd)

Build Trading Strategy

class MAStrategy(dfq.strategy.Strategy):
    """Dual Moving Average Strategy"""
    
    def on_bar(self, bar):
        if bar.ma5 > bar.ma20:
            self.buy()
        elif bar.ma5 < bar.ma20:
            self.sell()

Run Backtest

# Create backtest engine
engine = dfq.backtest.BacktestEngine(
    initial_cash=100000,
    commission=0.0003
)

# Run backtest
result = engine.run(data, MAStrategy())

# View results
print(result.summary())
result.plot()

Module Overview

  • data - Data acquisition and management
  • indicators - Technical indicator calculations
  • strategy - Strategy development framework
  • backtest - Backtest engine
  • risk - Risk management
  • performance - Performance analysis
  • optimization - Parameter optimization
  • trade - Live trading interface
  • utils - Utility functions

Examples

Check the examples/ directory for more example code:

  • ma_strategy.py - Dual Moving Average Strategy
  • macd_strategy.py - MACD Strategy
  • optimization_example.py - Parameter Optimization Example

Documentation

Dependencies

  • Python >= 3.8
  • pandas >= 1.3.0
  • numpy >= 1.21.0

Development

# Clone repository
git clone https://github.com/Delta-F/deltafq.git
cd deltafq

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Code formatting
black deltafq/

# Type checking
mypy deltafq/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Issues and Pull Requests are welcome!

Contact


⚠️ Risk Warning: Quantitative trading involves risk. This library is for educational and research purposes only and does not constitute investment advice. Please exercise caution when trading live, as you bear the risk yourself.

Language Support

This project supports both English and Chinese documentation:

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

deltafq-0.1.1.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

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

deltafq-0.1.1-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file deltafq-0.1.1.tar.gz.

File metadata

  • Download URL: deltafq-0.1.1.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for deltafq-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1698101e00dad97226f803947a980136bec5f82388d6606843204048c1587b0d
MD5 b72e1a70e287726248f581a78bde1c3b
BLAKE2b-256 3d5323989e9c25ac11d78469b347df216259aa33d4e39cbf285e6a6f9d2ab63e

See more details on using hashes here.

File details

Details for the file deltafq-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: deltafq-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for deltafq-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 341fe8fd01401906c7365157c022115af07e278e94be6bc7711a89365c7e7730
MD5 d45a7595b3c9433788ef8015b9d3baa1
BLAKE2b-256 f783cc348658d712928cf0b620b8899998d6c019db5a0b4b2eebf9124d5d1d94

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