A python project for analyzing stocks and building machine learning models to predict price movements for swing trading (2-3 months) and long-term investing (1-3 years).
- Swing Trading: Identify stocks with 10%+ potential gains over 2-3 months
- Long-term Investing: Find fundamentally strong stocks for 1-3 year holds
- Risk Management: Lower-risk approach compared to day trading
- ML-Powered: Use machine learning to identify patterns in historical data
market-analysis/
├── src/ # Reusable Python modules
│ ├── __init__.py
│ ├── indicators.py # Technical indicators (RSI, MACD, etc.)
│ ├── features.py # Feature engineering for ML
│ ├── data_fetcher.py # Download stock data
│ ├── models.py # ML model classes
│ └── signals.py # Buy/sell signal generation
│
├── notebooks/ # Jupyter notebooks for analysis
│ ├── 01_swing_trading.ipynb
│ ├── 02_position_trading.ipynb
│ ├── 03_longterm_investing.ipynb
│ └── 04_backtesting.ipynb
│
├── data/ # Stock data storage
│ ├── raw/ # Original downloaded data
│ └── processed/ # Cleaned & featured data
│
├── models/ # Saved ML models
│ └── swing_model_v1.pkl
│
├── results/ # Charts, reports, backtest results
│ └── analysis_charts/
│
├── requirements.txt # Python dependencies
├── README.md # This file
└── Logbook.md
- Moving Averages: SMA, EMA (20, 50, 200-day)
- Momentum: RSI, MACD, Stochastic
- Volatility: Bollinger Bands, ATR
- Volume: OBV, Volume trends
- Trend: ADX, Ichimoku Cloud
- Random Forest Classifier
- XGBoost
- LightGBM
- Feature importance analysis
- Walk-forward validation
- Swing Trading (2-3 months): Technical pattern recognition
- Position Trading (6-12 months): Momentum + technical
- Long-term Investing (2-3 years): Fundamentals + growth
- Fetch data for 5-10 stocks
- Calculate technical indicators
- Visualize patterns
- Understand correlations
- Create lagged features
- Add technical indicators
- Engineer price-based features
- Analyze feature importance
- Logistic Regression baseline
- Random Forest classification
- Compare performances
- Feature selection
- Walk-forward validation
- Calculate returns
- Risk metrics (Sharpe ratio)
- Identify weaknesses
- Try ensemble methods
- Add fundamental data
- Multi-stock screening
- Portfolio optimization
Core packages:
yfinance- Download stock data from Yahoo Financepandas- Data manipulationnumpy- Numerical computingscikit-learn- Machine learning modelsxgboost- Gradient boostinglightgbm- Fast gradient boostingmatplotlib- Plottingseaborn- Statistical visualizationplotly- Interactive chartsjupyter- Interactive notebooks
See requirements.txt for full list with versions.
Primary: Yahoo Finance (via yfinance)
- Free, no API key needed
- historical data going back decades
- OHLCV data (Open, High, Low, Close, Volume)
- Adjusted for splits and dividends
- ~15 minute delay on real-time data
- Timeframe: 2-6 months
- Target Return: 10-20%
- Risk Level: Medium
- Analysis: 70% technical, 30% fundamental
- Time Commitment: Few hours per week
- Timeframe: 6-12 months
- Target Return: 20-40%
- Risk Level: Medium-Low
- Analysis: 50% technical, 50% fundamental
- Time Commitment: Monthly review
- Timeframe: 2-3+ years
- Target Return: 50-200%+
- Risk Level: Lower (if fundamentally sound)
- Analysis: 80% fundamental, 20% technical
- Time Commitment: Quarterly review
- Investopedia - Financial education
- QuantInsti Blog - Algorithmic trading
- Machine Learning for Trading - Course
- Yahoo Finance - Market data
- TradingView - Charting platform
- Add fundamental data integration
- Build portfolio optimizer
- Create stock screener with rankings
- Add sentiment analysis (news, Twitter)
- Implement automated backtesting
- Add risk metrics dashboard
- Create alerting system
- Support multiple data sources
- Add options analysis
- Build web dashboard
This is a personal learning project, but suggestions are welcome!
MIT License - Feel free to use and modify for your own learning.
Created by Jasper Valk - Stock Market Analysis Project