Downtrend Duration Analyzer looks at historical daily prices for a set of US stocks, finds local peaks and troughs with a rolling window, and records the length in trading days and the depth in percent of each decline. It then summarizes the distributions by sector and by market cap tier (Mega, Large, Mid and Small) with median, mean and percentile statistics.
A second script turns the JSON results into an interactive HTML page with a duration histogram, sector and market cap filters and a summary table. The output describes past corrections and is not investment advice.
What You Get
- A JSON report with every detected downtrend: symbol, sector, tier, peak and trough dates, duration and depth
- A Markdown report with summary statistics and tables by market cap tier
- An interactive HTML histogram with sector and market cap filters, percentile markers and tooltips
- A methodology reference covering peak and trough detection and tier definitions
Common Use Cases
- Estimating how long a typical pullback lasts in a sector
- Comparing correction length between large caps and small caps
- Choosing a holding period limit for a mean reversion idea
- Checking the spread of outcomes with percentiles and not only the average
What Makes It Unique
The output is a distribution and not a single average: it reports the 25th, 75th and 90th percentiles beside the median and mean, split by sector and market cap tier. The results come with an interactive HTML page. The FMP client uses only the stable company-screener and historical price endpoints, skips malformed history and never fills in missing prices.
Under The Hood
The agent runs two Python scripts. The first calls the Financial Modeling Prep API over the network with the user’s API key (from the FMP_API_KEY environment variable or a command line option), pacing requests and retrying once on a rate limit, and writes JSON and Markdown files to an output folder (reports/ by default). The second reads the JSON and writes an HTML file; when that page is opened in a browser it loads the Plotly.js charting library from a public CDN. Both scripts create files on disk. The skill asks for the requests, pandas and numpy packages.