# Downtrend Duration Analyzer

Analyze historical downtrend durations and generate interactive HTML histograms showing...

- Repository: https://github.com/tradermonty/claude-trading-skills (3536 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: yes, review before use

## Install

Claude Code: `npx skills add tradermonty/claude-trading-skills --skill downtrend-duration-analyzer -g -a claude-code -y`
Codex: `npx skills add tradermonty/claude-trading-skills --skill downtrend-duration-analyzer -g -a codex -y`
Cursor: `npx skills add tradermonty/claude-trading-skills --skill downtrend-duration-analyzer -g -a cursor -y`
Gemini CLI: `npx skills add tradermonty/claude-trading-skills --skill downtrend-duration-analyzer -g -a gemini-cli -y`

## Description

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

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

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

The rest: https://github.com/tradermonty/claude-trading-skills/blob/HEAD/skills/downtrend-duration-analyzer/SKILL.md
