A comprehensive Python trading system framework that provides building blocks for algorithmic trading, market analysis, and portfolio management. This project attempts to consolidate and refactor functionality from some of my old repositories into something more reusable and modular, while still serving as my main trading/investing repository for ongoing research, tooling, and execution.
# Clone the repository
git clone https://github.com/yourusername/pynance.git
cd pynance
# Set up conda environment
conda env create -f envs/pynance-v2.0.yml
conda activate pynance-v2.0
# Run the trading dashboard
python dashboard.pypynance/
βββ π data/ # Market data and data processing utilities
βββ π¬ research/ # Market research and analysis tools
βββ π ibkr/ # Interactive Brokers integration
βββ π± oanda/ # OANDA forex broker integration
βββ π alpaca/ # Alpaca trading platform integration
βββ π§ finviz/ # Finviz data scraping utilities
βββ πΉ forexutils/ # Forex-specific utility functions
βββ π yfinance/ # Yahoo Finance data utilities
βββ π indicators/ # Custom technical indicators
βββ π° moneymanagement/ # Position sizing and risk management
βββ π― signals/ # Entry and exit signal generation
βββ π backtrader/ # Backtesting strategies
βββ π dashboard.py # Main trading dashboard GUI
βββ β° time_utils.py # Time and market hours utilities
A comprehensive GUI application (dashboard.py) that provides:
- Order Entry: Place trades with risk management
- Market Scanner: Real-time volume breakout detection
- Risk Management: Portfolio risk monitoring
- Research Tools: Market analysis and signal generation
- Data Collection: Automated market data fetching
Advanced market research capabilities in the research/ directory:
- Regime Detection: NYSE cumulative AD z-score analysis
- Breakout Statistics: Historical gap and breakout analysis
- Signal Generation: Multi-timeframe momentum signals
- Market Visualization: Interactive charts and plots
- Backtesting: Strategy performance evaluation
- IbkrTrader: Core trading interface with order management
- Order Types: Bracket orders, trailing stops, limit orders
- Data Retrieval: Historical and real-time market data
- Position Management: Portfolio tracking and risk calculation
- Account Management: Multi-account support with allocation
- OandaTrader: Live forex trading execution
- OandaClerk: Market data and account information
- Order Management: Market, limit, and stop orders
- Position Tracking: Real-time P&L monitoring
- Position Tracking: Portfolio position management
- Paper Trading: Risk-free strategy testing
Sophisticated position sizing algorithms in moneymanagement/:
- Martingale Systems: Traditional and reverse martingale
- Kelly Criterion: Optimal position sizing
- Fixed Fractional: Percentage-based risk management
- Account Risk Modulator: Dynamic risk adjustment
- Streak Management: Win/loss streak handling
Advanced signal processing in signals/:
- EntryEngine: Multi-timeframe entry signal detection
- ExitEngine: Risk management and profit-taking signals
- Signal Types: Momentum, mean reversion, breakout signals
- Confirmation Logic: Multi-factor signal validation
Custom indicators in indicators/:
- KAMA: Kaufman Adaptive Moving Average
- Custom Implementations: Specialized technical analysis tools
Specialized forex tools in forexutils/:
- Pip Calculations: Price to pip conversion utilities
- Cross Pair Analysis: Multi-currency pair calculations
- Spread Management: Dynamic spread threshold monitoring
- Market Hours: Forex market session detection
- Currency Dictionaries: Major currency pair mappings
Comprehensive data handling in data/:
- Market Data: SPX, VIX, bonds, commodities
- Data Fetching: Automated data collection scripts
- Data Processing: Cleaning and formatting utilities
- Symbol Management: Dynamic symbol list generation
- Python 3.8+
- Conda or Miniconda
- Interactive Brokers TWS/Gateway (for IBKR features)
- OANDA account (for forex features)
# Create conda environment
conda env create -f envs/pynance-v2.0.yml
conda activate pynance-v2.0
# Install additional dependencies
pip install -r requirements.txt- Copy
config/dashboard-config.ini.exampletoconfig/dashboard-config.ini - Update configuration with your broker credentials and paths
- Ensure data directory contains required CSV files
python dashboard.py# Fetch latest market data
python data/fetch_data.py
# Get recent gainers from Finviz
python data/finvizConsolidateRecentGainers.py# Generate SPX regime analysis
python research/combined-research.py
# Run breakout statistics
python research/getBreakoutStats.py SPY 2024-01-15# Check risk and orders
python ibkr/checkRiskAndOrders.py
# Run volume breakout scanner
python ibkr/longVolBreakouts.pyEdit config/dashboard-config.ini:
[paths]
repo_root = /path/to/pynance
[environment]
conda_env = pynance-v2.0- IBKR: Configure TWS/Gateway connection settings
- OANDA: Set API credentials in environment variables
- Alpaca: Configure API keys in environment variables
- Equities: US stocks and ETFs
- Forex: Major and minor currency pairs
- Futures: Commodity and index futures
- Options: Options trading support
- Live Data: Real-time market data feeds
- Signal Generation: Continuous signal monitoring
- Risk Management: Real-time portfolio risk assessment
- Order Management: Automated order execution
- Regime Detection: Market regime identification
- Signal Confirmation: Multi-factor signal validation
- Performance Tracking: Strategy performance monitoring
- Risk Metrics: Comprehensive risk analysis
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This software is for educational and research purposes only. Trading involves substantial risk of loss and is not suitable for all investors. Past performance is not indicative of future results. Always consult with a qualified financial advisor before making investment decisions.
For questions, issues, or contributions:
- Create an issue on GitHub
- Check the documentation in the
docs/directory - Review the configuration examples
Happy Trading! π