Skip to content
Agentmart
Submit a tool

downtrend-duration-analyzer

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

Skill by mphinance

IndexedMIT★ 29
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/mphinance-downtrend-duration-analyzer

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

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

Use cases: frontend

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found
Runs as
Python package

Network hosts it talks to 3

  • cdn.plot.ly · found in code
  • codeload.github.com · found in install command
  • financialmodelingprep.com · found in code

Files it touches

  • ~/.claude/skills/downtrend-duration-analyzer

What's inside

Skill name
downtrend-duration-analyzer
Description
Analyze historical downtrend durations and generate interactive HTML histograms showing typical correction lengths by sector and market cap.
License
MIT
Instructions
173 lines in SKILL.md · view on GitHub

Before installing

  • Ships executable scripts

Files (8)

  • README.md
  • SKILL.md
  • downtrend_methodology.md · references/
  • analyze_downtrends.py · scripts/
  • generate_histogram_html.py · scripts/
  • conftest.py · scripts/tests/
  • test_analyze_downtrends.py · scripts/tests/
  • test_generate_histogram_html.py · scripts/tests/

SKILL.md (first lines)

# 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.

```bash
python3 skills/downtrend-duration-analyzer/scripts/analyze_downtrends.py \
  --sector "Technology" \
  --lookback-years 5 \
  --output-dir reports/
```

### 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

```bash
python3 skills/downtrend-duration-analyzer/scripts/generate_histogram_html.py \
  --input reports/downtrend_analysis_*.json \
  --output-dir reports/
```

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

```json
{
  "schema_version": "1.0",
  "analysis_date": "2026-03-28T07:00:00Z",
  "parameters": {
    "lookback_years": 5,
    "sector_filter": "Technology",
    "peak_window": 20,
    "trough_window": 20
  },
  "summary": {
    "total_downtrends": 1234,
    "median_duration_days": 18,
    "mean_duration_days": 24.5,
    "p25_duration_days": 10,
    "p75_duration_days": 32,
    "p90_duration_days": 55
  },
  "by_sector": {
    "Technology": {
      "count": 456,
      "median_days": 15,
      "mean_days": 20.3
    }
  },
  "by_market_cap": {
    "Mega": {"count": 200, "median_days": 12},
    "Large": {"count": 300, "median_days": 16},
    "Mid": {"count": 400, "median_days": 22},
    "Small": {"count": 334, "median_days": 28}
  },
  "downtrends": [
    {
      "symbol": "AAPL",
      "sector": "Technology",
      "market_cap_tier": "Mega",
      "peak_date": "2025-01-15",
      "trough_date": "2025-02-10",
      "duration_days": 18,
      "depth_pct": -12.5
    }
  ]
}
```

### Markdown Report

```markdown
# Downtrend Duration Analysis

**Date**: 2026-03-28
**Lookback**: 5 years
**Sector**: Technology

From mphinance/alpha-skills, MIT.

More from mphinance/alpha-skills

Signals

Stars
29
Forks
6
Open issues
0
Last commit (this folder)
Aug 28, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from mphinance

Cite this page

downtrend-duration-analyzer skill. Agent Mart. https://agentmart.dev/skills/mphinance-downtrend-duration-analyzer (last updated 2026-10-24)