downtrend-duration-analyzer

Analyze historical downtrend durations and generate interactive HTML histograms showing typical correction lengths by sector and market cap.

By tradermonty · 1,884 installs

npx skills add tradermonty/claude-trading-skills --skill downtrend-duration-analyzer

Source repository · Upstream listing

Downtrend Duration Analyzer Overview Analyze historical price data to identify downtrend periods (peak to trough) and build statistical distributions of correction durations. Generate interactive HTML visualizations with histograms segmented by sector and market cap to help traders understand typical recovery timeframes and set realistic expectations for mean reversion strategies. When to Use Trader asks about typical correction lengths for a sector or market cap tier User wants to understand historical drawdown recovery times Building mean reversion or pullback strategies that need realistic holding period estimates Comparing correction behavior across different market segments Setting stop loss timeouts or position holding period limits Prerequisites Python 3.9+ FMP API key (set FMP API KEY environment variable or use api key ) Required packages: requests , pandas , numpy (standard data analysis stack) Workflow Step 1: Fetch Historical Price Data Run the analysis script to fetch OHLC data for a universe of stocks and identify downtrend periods. Step 2: Analyze Downtrend Durations The script automatically: 1. Identifies local peaks and troughs using rolling window analysis 2. Calculates duration (trading days) and depth (% decline) for each downtrend 3. Segments results by sector and market cap tier (Mega, Large, Mid, Small) 4. Computes summary statistics (median, mean, percentiles) Step 3: Generate Interactive HTML Visualization This creates an interactive HTML file with: Histogram of downtrend durations Filters for sector and market cap Hover tooltips with percentile information Summary statistics table Step 4: Review Distribution Insights Load the generated markdown report to interpret the findings: Short corrections (5 15 days) : Typical pullbacks within uptrends Medium corrections (15 40 days) : Standard sector rotations Extended corrections (40+ days) : Trend changes or bear markets Output Format JSON Report Markdown Report HTML Visualization Interactive histogram saved to reports/downtrend histogram YYYY MM DD.html with: Plotly.js based interactive charts Sector and market cap dropdown filters Duration distribution with bin controls Percentile markers (P25, P50, P75, P90) Reports are saved to reports/ with filenames: downtrend analysis YYYY MM DD HHMMSS.json downtrend analysis YYYY MM DD HHMMSS.md downtrend histogram YYYY MM DD HHMMSS.html Resources scripts/analyze downtrends.py Main analysis script for fetching data and computing downtrend durations scripts/generate histogram html.py HTML visualization generator with interactive histograms references/downtrend methodology.md Peak/trough detection algorithms and market cap tier definitions Key Principles 1. Statistical Rigor : Use robust peak/trough detection to avoid noise induced false signals 2. Segmentation Matters : Always analyze by sector and market cap; averages hide important differences 3. Realistic Expectations : Use percentiles (not just means) to understand the full distribution of outcomes