Trademan
A Python library and CLI tool for gathering market data and generating optimal portfolios using modern portfolio theory.
Features
- 📊 Market Data Collection: Automated downloading and caching of S&P 500 and ETF data via yfinance
- 🎯 Portfolio Optimization: Multiple optimization strategies (Sharpe ratio, minimum volatility, etc.)
- 📈 Visualization: Generate beautiful portfolio allocation charts
- 🚀 CLI Interface: Easy-to-use command-line tools for quick analysis
- 🐍 Python API: Full programmatic access for custom workflows
- 💾 Smart Caching: Intelligent data caching to minimize API calls
Installation
Install from PyPI:
pip install trademan
Install from source:
pip install git+https://github.com/ottermatics/trademan.git
Quick Start
CLI Usage
- Download Market Data:
market_dl # Downloads S&P 500 and ETF data
- Generate a Portfolio:
# Create a Sharpe-optimized portfolio with $10,000 allocation
trademan -cls stocks -alloc 10000 -opt sharpe
# Minimum volatility ETF portfolio
trademan -cls etfs -opt min_volatility -alloc 100000 -in QQQ,SPY,VTI
Python API
import trademan
# Get stock data for specific tickers
data = trademan.get_tickers(['AAPL', 'MSFT', 'GOOGL'])
# Create optimized portfolio
weights = trademan.make_portfolio(
data,
opt='sharpe', # Optimization method
risk='ledoit_wolf', # Risk model
allocate_amount=10000 # Dollar amount
)
# Visualize the portfolio
fig, ax = trademan.plot_portfolio(weights)
CLI Options
| Option | Description | Default |
|---|---|---|
-cls |
Asset class: etfs, stocks, all |
all |
-opt |
Optimization: sharpe, min_volatility, eff_return, eff_risk |
sharpe |
-risk |
Risk model: covariance, ledoit_wolf |
ledoit_wolf |
-alloc |
Amount to allocate (shows share counts) | None |
-gamma |
Weight regularization (higher = more diversified) | 2 |
-in |
Include specific tickers (comma-separated) | None |
-ex |
Exclude specific tickers (comma-separated) | None |
-min-wght |
Minimum weight threshold for assets | 0.01 |
-max-wght |
Maximum weight limit per asset | None |
Configuration
Set environment variables to customize data storage:
export TRADEMAN_DATA_DIR="/path/to/data" # Market data cache
export TRADEMAN_MEDIA_DIR="/path/to/charts" # Generated charts
Examples
1. Best Performing S&P 500 Stocks
Create a portfolio favoring established companies with cycle penalties:
trademan -cls stocks -gamma 1 -alloc 10000 -cycl-err 10 -max-wght 0.2
2. Low Volatility ETF Portfolio
Generate a conservative ETF allocation:
trademan -cls etfs -gamma 0.1 -alloc 100000 \
-in QQQ,SCHG,VGT,SLV,VIG,SPY,VOO,VUG,IAU,PAVE \
-opt min_volatility
How It Works
- Data Collection: Downloads historical price data using yfinance
- Risk Modeling: Calculates covariance matrices with Ledoit-Wolf shrinkage
- Return Estimation: Uses mean historical returns with optional adjustments
- Optimization: Applies modern portfolio theory via PyPortfolioOpt
- Allocation: Converts weights to discrete share quantities
- Visualization: Creates publication-ready portfolio charts
Dependencies
- PyPortfolioOpt: Portfolio optimization algorithms
- yfinance: Market data source
- pandas/numpy: Data manipulation
- matplotlib: Visualization
- diskcache: Data caching
- scikit-learn: Additional analytics
Development
Install development dependencies:
pip install -e .[dev]
Run tests:
pytest
License
MIT License - see LICENSE for details.
Contributing
Contributions welcome! Please read CONTRIBUTING.rst for guidelines.
Metadata
Release files for trademan 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| trademan-0.1.0.tar.gz | 139.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| trademan-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 274.7 kB
Release files / trademan-0.1.0.tar.gz
| Download URL | trademan-0.1.0.tar.gz |
|---|---|
| Size | 139.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f773e3fe2c3ed6df6cd6d53b3163dcc50038d82264d2c8eb946900b532f94bef
|
|
BLAKE2b-256 checksum How to use checksums |
65364ebed777c8852baf8678e43498fd66ddeaa37a46866475c4b9b6b9b8a551
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Sep 9, 2025.
Transparency logRelease files / trademan-0.1.0-py3-none-any.whl
| Download URL | trademan-0.1.0-py3-none-any.whl |
|---|---|
| Size | 135.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f077c62280e55b19c99e0b5aeae02ddff5c1c44786922ed1a0703a0dc05b99e4
|
|
BLAKE2b-256 checksum How to use checksums |
fe9b66e1213b8d3767ab4f413327bf0affb4d9be6a21005de5ae4a407bddf80d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Sep 9, 2025.
Transparency log