Python · Indicator Code
Frog (range volatility) in Python
Frog is the population standard deviation of the daily High−Low range over the prior ~30 trading days, a measure of how erratic a symbol's daily bar size has been.
Verified. Python and JavaScript implementations agree to
2.22e-16 on a 60-bar reference high/low series (canonical Python (edge-scan compute_frog_for_date) vs JavaScript (calcFrog30d), comparable positions).Python
import numpy as np
def frog(high, low, n=30):
"""Frog — population standard deviation of the daily (High - Low) range
over the n trading days STRICTLY BEFORE the last bar.
Canonical math from edge-scan eod_indicators._frog_from_window /
compute_frog_for_date. The window is the n ranges preceding the final
bar (the current/target day is excluded — no look-ahead), and the
standard deviation is population (ddof=0).
Args:
high: sequence of daily highs, ascending by date.
low: sequence of daily lows, ascending by date (same length).
n: lookback window in trading days (default 30).
Returns:
float Frog value, or None if fewer than 2 observations in the window.
"""
high = np.asarray(high, dtype=float)
low = np.asarray(low, dtype=float)
ranges = high - low
# Window: up to n bars ending one position before the last bar.
# Excluding the final bar matches the chart-display / for_date convention.
idx = len(ranges) - 1
window = ranges[max(0, idx - n):idx]
if len(window) < 2:
return None
# Population standard deviation (ddof=0).
return float(np.std(window, ddof=0))
Other platforms: JavaScript
← Frog (range volatility) (all platforms) · All indicators · Glossary concept
← Frog (range volatility) (all platforms) · All indicators · Glossary concept
Improve Your Craft Every Morning
A short note from Dr. Ken Long on the craft of trading. One idea to think about and work on that day, drawn from decades of teaching and live trading. Free.
Your email:
Tue–Fri mornings. Unsubscribe anytime. No spam, no hype.