Skip to main content

Modular-Trader: A Flexible Algorithmic Trading Framework

Python Badge

Important Note: This project is currently undergoing substantial updates. Significant changes to existing functions and classes are anticipated, and compatibility with the current version may be affected.

logo

About The Project

flow

Modular Trader is a Python-based framework for algorithmic trading, designed with a strong emphasis on modularity and flexibility. It provides a comprehensive solution as a set of building blocks for the live deployment of algorithmic trading strategies.

The framework is organized into five core modules, each addressing a critical aspect of the trading process:

  • Asset Selection: Identifies and selects the assets to include in the trading universe.
  • Signal Generation: Produces trading signals based on various strategies and indicators.
  • Portfolio Construction: Allocates portfolio weights based on the generated signals.
  • Risk Management: Adjusts portfolio allocations to mitigate and manage risk effectively
  • Order Execution: Manages the execution of buy/sell orders in the market.

Built-in Models

Asset Selection

  • Manual

Signal Generation

  • Constant

Portfolio Builder

  • EqualWeight
  • ThresholdDeviation

Order Execution

  • Instant

Risk Management

  • FixedStopLoss

Supported Brokerages

Important Note: We are not affiliated, associated, authorized, endorsed by, or in any way officially connected with Alpaca Securities LLC, or any of its subsidiaries or its affiliates. The official Alpaca Securities LLC website can be found at https://alpaca.markets/.

Getting Started

Installation

pip install modular-trader

Usage

from dotenv import load_dotenv
from modular_trader.common.enums import TradingMode
from modular_trader.engine import AlpacaEngine
from modular_trader.framework import FrameworkCollection
from modular_trader.framework.asset_selection import ManualAssetSelection
from modular_trader.framework.order_execution import InstantOrderExecution
from modular_trader.framework.portfolio_construction import EqualWeightPortfolioConstruction
from modular_trader.framework.risk_management import NullRiskManagement
from modular_trader.framework.signal_generation import ConstantSignalGeneration
from modular_trader.trader import AlpacaTrader

# set Alpaca Token  as environment variable
# create `.env` file then add
# ALPACA_API_KEY=xxxxxxxx
# ALPACA_SECRET_KEY=xxxxxxx
load_dotenv()

# Equally weighted portfolio
# with Instant rebalancing
symbols = ["SPY", "QQQ", "GLD"]
framework = FrameworkCollection(
    asset_selection=ManualAssetSelection(symbols=symbols),
    signal_generation=ConstantSignalGeneration(),
    portfolio_construction=EqualWeightPortfolioConstruction(),
    order_execution=InstantOrderExecution(),
    risk_management=NullRiskManagement(),
)

# using Paper portfolio
engine = AlpacaEngine(mode=TradingMode.PAPER)

trader = AlpacaTrader(
    engine=engine,
    framework=framework,
    subscription_symbols=symbols,
)

trader.run()

License

Distributed under the MIT License. See LICENSE for more information.

Maintainers

Modular Trader is currently maintained by kfuangsung (kachain.f@outlook.com).

Important Note: We do not provide technical support, or consulting and do not answer personal questions via email.

Acknowledgments

  • alpaca-py: An official Python SDK for Alpaca APIs.

Disclaimer

Authors and contributors of Modular-Trader cannot be held responsible for possible losses or other damage. Consequently, no claims for damages can be asserted. Please also note that trading has a certain addictive potential. If you find yourself at risk, please seek professional help.

Metadata

Release files for modular-trader 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modular-trader 0.0.3
File Size Uploaded
modular_trader-0.0.3.tar.gz 64.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for modular-trader 0.0.3
File Interpreter ABI Platform
modular_trader-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 109.1 kB

Release files / modular_trader-0.0.3.tar.gz

Download URL modular_trader-0.0.3.tar.gz
Size 64.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a1f12c4c0ccdc3f33f73ed36620cdf638571723d4dc69b2721510502b6d45882
BLAKE2b-256 checksum
How to use checksums
6d36f40733517e3110ac4d37f2a105cc5603a87e7375fe46ea41b9d97d8497fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 4, 2025.

Transparency log

Release files / modular_trader-0.0.3-py3-none-any.whl

Download URL modular_trader-0.0.3-py3-none-any.whl
Size 44.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e12fffcf30ab27b2885248b52729e56835ad38d9e855d344041da864ba07616
BLAKE2b-256 checksum
How to use checksums
d79980a1de4a0f225e7ff24e61517ee87ce67978767657dda4af581680864e3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 4, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page