How tanbeng123/is4226_dual_trend_portfolio_strat works
Purpose and Entry Points
This is a quantitative-finance backtest for a long-only EMA-smoothed On-Balance Volume (OBV) strategy across major technology stocks, compared with SPY from 2010–2019. The repository is extremely compact: the primary runnable artifact is likely ema_obv_portfolio; run_backtest.py is the script entry point. README.md documents the intended notebook-oriented workflow.
Strategy Signal Layer
The core strategy generates directional signals by combining:
• cumulative volume-adjusted price moves (raw OBV),
• EMA smoothing of OBV using λ=0.99,
• price and smoothed-OBV directional agreement,
• 50-day and 200-day moving-average trend confirmation.
This layer transforms per-ticker daily OHLCV-style market inputs into trade eligibility or position-direction signals.
Paths: ema_obv_portfolio, README.md
Market Data Boundary
Historical daily price and volume data are expected to come from Yahoo Finance via yfinance, for ten equities plus the SPY benchmark. Data acquisition is an external-service boundary; downstream calculations rely on aligned trading-date indices, adjusted price series, and volume fields.
Paths: run_backtest.py, README.md
Portfolio Construction and Risk Control
Signals are aggregated across the stock universe into a diversified, no-leverage portfolio. The stated design includes volatility targeting at a 20% annual target using a 30-day volatility window, which makes sizing/risk scaling a distinct stage after raw signal generation and before return realization.
Paths: ema_obv_portfolio, README.md
Expanding-Window Backtest Engine
The backtester should process daily observations chronologically, avoid future-data leakage through expanding-window validation, maintain positions/equity over time, and calculate portfolio returns against initial capital of $500,000. The documented academic assumptions are 1x long-only exposure and zero transaction costs.
Paths: run_backtest.py, ema_obv_portfolio
Benchmarking and Analytics
Portfolio equity is evaluated against SPY using cumulative return, CAGR, volatility, Sharpe ratio, alpha/beta, information ratio, drawdown, annual returns, and trade statistics. Attribution isolates ticker-level contribution, while benchmark comparison establishes whether strategy returns exceed market exposure.
Paths: ema_obv_portfolio, README.md
Reporting Outputs and Runtime
The intended runtime is Python with pandas/numpy for time-series processing, yfinance for data retrieval, and matplotlib/seaborn plus Jupyter for charts and dashboards. Expected outputs include equity-versus-SPY, drawdown, annual returns, a metrics dashboard, per-ticker attribution, and trade analysis.
Paths: run_backtest.py, ema_obv_portfolio, README.md
Main entry points: run_backtest.py Aligned OHLCV data · ema_obv_portfolio Long-only signals · README.md Stock universe + SPY
Components 17
Market Data
- Yahoo Finance · Historical daily equity and SPY data via yfinance.
- Aligned OHLCV data · Adjusted prices and volumes aligned by trading date.
run_backtest.py - Stock universe + SPY · Ten technology equities and the SPY benchmark.
README.md
Strategy & Portfolio
- ema_obv_portfolio · Primary strategy and portfolio implementation.
ema_obv_portfolio - Raw OBV · Cumulative volume-adjusted price moves per ticker.
ema_obv_portfolio - EMA-smoothed OBV · OBV smoothing with λ=0.99.
ema_obv_portfolio - Trend confirmation · 50-day and 200-day price trend checks.
ema_obv_portfolio - Long-only signals · Requires price and smoothed-OBV directional agreement with trend confirmation.
ema_obv_portfolio - Volatility targeting · 30-day volatility scaling to a 20% annual target.
ema_obv_portfolio - Diversified positions · No-leverage, 1x long-only stock exposure.
ema_obv_portfolio
Backtest Engine
- run_backtest.py · Runs the backtest workflow.
run_backtest.py - Expanding-window engine · Maintains positions, equity, and leakage-safe daily evaluation.
ema_obv_portfolio - Portfolio returns & equity · Return series and equity curve from $500,000 initial capital.
run_backtest.py
Benchmarking & Reporting
- SPY benchmark returns
ema_obv_portfolio - Performance analytics · Calculates returns, risk, alpha/beta, drawdown, annual results, and trade statistics.
ema_obv_portfolio - Charts & dashboards · Equity comparison, drawdown, annual returns, metrics, attribution, and trade analysis.
README.md
Other components
- README.md · Documents the notebook-oriented workflow and assumptions.
README.md
Connections 21
- README.md → run_backtest.py: documents workflow
- run_backtest.py → Yahoo Finance: requests data
- Stock universe + SPY → Yahoo Finance: selects symbols
- Yahoo Finance → Aligned OHLCV data: daily prices and volume
- Aligned OHLCV data → Raw OBV: price and volume
- Raw OBV → EMA-smoothed OBV: smooths
- Aligned OHLCV data → Trend confirmation: price history
- EMA-smoothed OBV → Long-only signals: OBV direction
- Trend confirmation → Long-only signals: trend filter
- Long-only signals → Volatility targeting: eligible exposures
- Aligned OHLCV data → Volatility targeting: 30-day volatility
- Volatility targeting → Diversified positions: scaled weights
- Diversified positions → Expanding-window engine: daily positions
- Aligned OHLCV data → Expanding-window engine: realized market returns
- Expanding-window engine → Portfolio returns & equity: simulated results
- Aligned OHLCV data → SPY benchmark returns: SPY prices
- Portfolio returns & equity → Performance analytics: strategy performance
- SPY benchmark returns → Performance analytics: comparison series
- Performance analytics → Charts & dashboards: visualizations and tables
- ema_obv_portfolio → Long-only signals: implements
- ema_obv_portfolio → Expanding-window engine: implements