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.
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.
- Manual
- Constant
- EqualWeight
- ThresholdDeviation
- Instant
- FixedStopLoss
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/.
pip install modular-trader
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()
Distributed under the MIT License. See LICENSE
for more information.
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.
- alpaca-py: An official Python SDK for Alpaca APIs.
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.