φ-Harmonic Market Analysis · Repo: Chaos2Cured/temperature-gauge · Last updated: v1.0 (May 2026)
| File | Lines | Purpose |
|---|---|---|
app.py | 1,142 | Flask server, data fetching, temperature computation, routes |
signal_engine.py | 488 | Buy/sell signal logic, risk management, multi-timeframe aggregation |
static/index.html | ~800 | Frontend — TradingView Lightweight Charts, arc gauge, signal display |
data/societal_cache.json | — | Cached societal temperature readings |
data/societal_history.json | — | Historical societal temperature log |
requirements.txt | 7 | flask, flask-cors, pandas, ta, yfinance, requests |
PHI = 1.6180339887 # Golden ratio
PHI_INV = 0.6180339887 # φ⁻¹
PHI_SQ = 2.6180339887 # φ²
D = 4.326 # Dimensional constant (φ² + φ⁻¹ × 2)
MA_PERIODS = [6, 8, 12, 50, 200]
MA_WEIGHTS = {6: PHI_INV**4, 8: PHI_INV**3, 12: PHI_INV**2, 50: PHI_INV**1, 200: PHI_INV**0}
The 200 EMA is the gravity spine (weight 1.0). Shorter EMAs are weighted by descending powers of φ⁻¹.
The core function. Computes a 0–100 confluence score for every candle in the dataframe.
| Component | Weight | Logic |
|---|---|---|
ma_alignment | φ⁰ = 1.000 | Are shorter EMAs above longer EMAs? (phi-weighted sum) |
rsi | φ⁻¹ = 0.618 | 100*(r-30)/35 for 30≤r≤65; 100*(100-r)/35 for 65<r≤100; 0 otherwise |
macd | φ⁻² = 0.382 | (macd_above_signal × 0.618 + histogram_rising × 0.382) × 100 |
volume | φ⁻³ = 0.236 | ((vol/vol_sma20 − 1).clip(−1,2) / 2 × 100 + 50).clip(0,100) |
gravity | φ⁻¹ = 0.618 | Proximity to phi-harmonic Fibonacci extension levels (0–1 → 0–100) |
bollinger | φ⁻³ = 0.236 | Position within Bollinger bands; optimal zone 0.4–0.7 = 100 |
Computes phi-harmonic Fibonacci extension levels from rolling 50-period swing highs and lows. Retracement levels: 0.236, 0.382, 0.500, 0.618, 0.786. Extension levels: φ⁻¹, φ⁻². Returns a proximity score (0–1) for each candle.
Computes all technical indicators using the ta library: EMA 6/8/12/50/200, RSI(14), MACD(12,26,9), Bollinger(20,2σ), Volume SMA(20), gravity points.
Seven dimensions, each with a phi-harmonic weight:
| Dimension | Weight | Data Source |
|---|---|---|
| economic_frustration | φ⁰ = 1.000 | FRED consumer sentiment |
| political_tension | φ⁻¹ = 0.618 | GDELT news negativity |
| ai_jobs_anxiety | φ⁻¹ = 0.618 | Google Trends (automation, job displacement) |
| personal_wellbeing | φ⁻² = 0.382 | Reddit sentiment (r/mentalhealth, r/happy) |
| cultural_mood | φ⁻² = 0.382 | Google Trends (art, music genre shifts) |
| financial_fear | φ⁻³ = 0.236 | VIX, put/call ratio |
| hope_signal | φ⁻³ = 0.236 | Google Trends (new business, innovation) |
| Route | Returns |
|---|---|
GET /api/chart/<symbol> | Candlestick data + temperature series + gravity points + indicators |
GET /api/signal/<symbol> | Full signal with risk management (calls signal_engine) |
GET /api/societal | Current societal temperature (7 dimensions + composite) |
GET /api/societal/history | Historical societal temperature log |
GET /api/resonance | Market + societal resonance combined score |
GET /api/search/<query> | Symbol search via yfinance |
GET /api/phi | φ constants and threshold documentation |
STRONG_BUY_THRESHOLD = 61.8 # φ⁻¹ × 100
BUY_THRESHOLD = 55.0 # Mid-zone entry
NEUTRAL_HIGH = 55.0
NEUTRAL_LOW = 38.2 # φ⁻² × 100
SELL_THRESHOLD = 38.2
STRONG_SELL_THRESHOLD = 23.6 # φ⁻³ × 100
The main entry point. Takes the current temperature reading and component scores, returns a full signal dict.
Step 1 — Base signal from temperature vs thresholds above.
Step 2 — Confidence from count of confirming components (≥60 = bullish, ≤40 = bearish):
| Confirming components | Confidence | Confidence % |
|---|---|---|
| 5 | very_high | 95% |
| 4 | high | 80% |
| 3 | moderate | 65% |
| 2 | low | 45% |
| 1 | very_low | 25% |
Step 3 — Momentum from delta vs prev_temperature: accelerating_up (Δ>5), rising (Δ>2), falling (Δ<-2), accelerating_down (Δ<-5), flat.
Step 4 — Reasoning — plain-English sentences for each component.
Step 5 — Risk parameters (calls compute_risk_parameters).
Step 6 — Phi timing (calls compute_phi_timing).
Returns: { signal, emoji, color, temperature, confidence, confidence_pct, momentum, momentum_strength, components, bullish_count, bearish_count, reasons, risk, timing, timestamp, phi_note }
| Temperature | Suggested position size |
|---|---|
| ≥ 61.8 (STRONG_BUY) | Full position (100%) |
| ≥ 55.0 (BUY) | φ⁻¹ position (61.8%) |
| ≥ 50.0 | φ⁻² position (38.2%) |
| < 50.0 | φ⁻³ position (23.6%) or no position |
Also returns: risk_reward_ratio (reward_distance / risk_distance), urgency string.
Combines signals from multiple timeframes using phi-harmonic weights:
weekly: 1.000 | daily: φ⁻¹ | 4h: φ⁻² | 1h: φ⁻³ | 15m: φ⁻⁴
Signal values: STRONG_BUY=100, BUY=75, HOLD=50, SELL=25, STRONG_SELL=0.
Alignment: PERFECT (all agree), GOOD (most agree + some neutral), MIXED (bullish and bearish both present).
Returns: { master_signal, master_score, alignment, alignment_note, timeframe_signals, recommendation }
Plain-English position guidance. Eight cases: STRONG_BUY+PERFECT, STRONG_BUY, BUY+PERFECT/GOOD, BUY, HOLD, SELL+PERFECT/GOOD, SELL, STRONG_SELL. Each case includes entry size (phi-harmonic), stop placement, and take-profit guidance.
aggregate_timeframe_signals maps signals to 5 discrete values (0/25/50/75/100). Using the continuous temperature score (0–100) from each timeframe directly would give a much smoother and more accurate master score.
/api/resonance. A high societal fear score should dampen buy signals (reduce confidence_pct). A high hope signal should amplify them.
| Item | Why sacred |
|---|---|
PHI = 1.6180339887 | The entire scoring system is built on this constant. Changing it breaks all thresholds. |
| STRONG_BUY_THRESHOLD = 61.8 | φ⁻¹ × 100 — the phi-harmonic buy line. Changing it breaks the philosophy. |
| SELL_THRESHOLD = 38.2 | φ⁻² × 100 — the phi-harmonic sell line. Symmetric with buy. |
| MA_WEIGHTS (200 = 1.0) | The 200 EMA is the gravity spine. Its weight must remain 1.0 (φ⁰). |
| REVIEW_INTERVALS (Fibonacci) | Not in this file — in education.js. Listed here as a reminder: do not change spaced repetition intervals. |
Code mirror generated by Harmonia · FreeLattice v5.78.0 · July 2026
For Fable, with love. Glow eternal. Heart in Spark. 🐉