Spaces:
Running
Running
File size: 8,654 Bytes
da0ce7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | #!/usr/bin/env python3
"""Map the ENTIRE global financial market as one energy field."""
import sys, io, os, time, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
import numpy as np
import requests
from aureon.harmonic.aureon_market_energy_field import MarketEnergyField
for l in open(os.path.join(os.path.dirname(__file__), '..', '..', '.env')):
l = l.strip()
if l and not l.startswith('#') and '=' in l:
k, _, v = l.partition('=')
os.environ.setdefault(k.strip(), v.strip())
print("GLOBAL ENERGY MAP — Every market that costs energy to move")
print("=" * 60)
field = MarketEnergyField()
total_mapped = 0
# 1. CRYPTO — Top 20
print("\n[CRYPTO] Top 20 by market cap...")
try:
r = requests.get("https://api.coingecko.com/api/v3/coins/markets",
params={"vs_currency": "usd", "order": "market_cap_desc", "per_page": 20,
"page": 1, "sparkline": "true"}, timeout=15)
if r.status_code == 200:
for coin in r.json():
sym = coin.get("symbol", "?").upper()
sparkline = coin.get("sparkline_in_7d", {}).get("price", [])
vol = coin.get("total_volume", 0)
price = coin.get("current_price", 0)
for i, p in enumerate(sparkline):
field.ingest_price(sym, p, vol / max(1, len(sparkline)),
time.time() - (len(sparkline) - i) * 3600)
sig = field.compute_signature(sym)
if sig:
total_mapped += 1
print(f" {sym:6s} ${price:>10,.0f} f={sig.dominant_frequency_hz:.4f} "
f"{sig.energy_state:13s} bot={sig.bot_activity:.2f} "
f"whale={sig.whale_presence:.2f} phi={sig.phi_alignment:.2f}")
except Exception as e:
print(f" Crypto: {e}")
# 2. US STOCKS
print("\n[US STOCKS] Tech + Finance + Healthcare...")
try:
import yfinance as yf
tickers = ["SPY", "QQQ", "AAPL", "MSFT", "TSLA", "NVDA", "GOOGL", "AMZN",
"META", "JPM", "V", "JNJ", "WMT", "PG", "UNH"]
data = yf.download(tickers, period="7d", interval="1h", progress=False)
for sym in tickers:
try:
prices = data["Close"][sym].dropna().values
vols = data["Volume"][sym].dropna().values
for i, p in enumerate(prices):
v = float(vols[i]) if i < len(vols) else 0
field.ingest_price(sym, float(p), v, time.time() - (len(prices) - i) * 3600)
sig = field.compute_signature(sym)
if sig:
total_mapped += 1
print(f" {sym:6s} ${prices[-1]:>10,.2f} f={sig.dominant_frequency_hz:.4f} "
f"{sig.energy_state:13s} bot={sig.bot_activity:.2f} phi={sig.phi_alignment:.2f}")
except Exception:
pass
except Exception as e:
print(f" Stocks: {e}")
# 3. FOREX
print("\n[FOREX] Major + Emerging...")
try:
fx = ["EURUSD=X", "GBPUSD=X", "USDJPY=X", "AUDUSD=X", "USDCAD=X",
"NZDUSD=X", "USDCHF=X", "EURGBP=X", "USDINR=X", "USDCNY=X"]
data = yf.download(fx, period="7d", interval="1h", progress=False)
for sym in fx:
try:
label = sym.replace("=X", "")
prices = data["Close"][sym].dropna().values
for i, p in enumerate(prices):
field.ingest_price(label, float(p), 0, time.time() - (len(prices) - i) * 3600)
sig = field.compute_signature(label)
if sig:
total_mapped += 1
print(f" {label:8s} {prices[-1]:>10.4f} f={sig.dominant_frequency_hz:.4f} "
f"{sig.energy_state:13s} bot={sig.bot_activity:.2f}")
except Exception:
pass
except Exception as e:
print(f" Forex: {e}")
# 4. COMMODITIES
print("\n[COMMODITIES] Metals + Energy + Agriculture...")
try:
cmd = {"GC=F": "GOLD", "SI=F": "SILVER", "CL=F": "OIL", "NG=F": "NATGAS",
"HG=F": "COPPER", "PL=F": "PLATINUM", "ZW=F": "WHEAT", "ZC=F": "CORN"}
data = yf.download(list(cmd.keys()), period="7d", interval="1h", progress=False)
for sym, label in cmd.items():
try:
prices = data["Close"][sym].dropna().values
for i, p in enumerate(prices):
field.ingest_price(label, float(p), 0, time.time() - (len(prices) - i) * 3600)
sig = field.compute_signature(label)
if sig:
total_mapped += 1
print(f" {label:8s} ${prices[-1]:>10,.2f} f={sig.dominant_frequency_hz:.4f} "
f"{sig.energy_state:13s} bot={sig.bot_activity:.2f}")
except Exception:
pass
except Exception as e:
print(f" Commodities: {e}")
# 5. GLOBAL INDICES
print("\n[INDICES] Global markets...")
try:
idx = {"^GSPC": "SP500", "^DJI": "DOW", "^IXIC": "NASDAQ", "^FTSE": "FTSE",
"^N225": "NIKKEI", "^GDAXI": "DAX", "^HSI": "HANGSENG", "^BVSP": "BOVESPA"}
data = yf.download(list(idx.keys()), period="7d", interval="1h", progress=False)
for sym, label in idx.items():
try:
prices = data["Close"][sym].dropna().values
for i, p in enumerate(prices):
field.ingest_price(label, float(p), 0, time.time() - (len(prices) - i) * 3600)
sig = field.compute_signature(label)
if sig:
total_mapped += 1
print(f" {label:8s} {prices[-1]:>10,.0f} f={sig.dominant_frequency_hz:.4f} "
f"{sig.energy_state:13s} bot={sig.bot_activity:.2f}")
except Exception:
pass
except Exception as e:
print(f" Indices: {e}")
# 6. ETFs (sector energy flows)
print("\n[ETFs] Sector energy flows...")
try:
etfs = {"XLF": "FINANCE", "XLE": "ENERGY", "XLK": "TECH", "XLV": "HEALTH",
"GLD": "GOLDETF", "TLT": "BONDS", "IWM": "SMALLCAP", "EEM": "EMERGING"}
data = yf.download(list(etfs.keys()), period="7d", interval="1h", progress=False)
for sym, label in etfs.items():
try:
prices = data["Close"][sym].dropna().values
for i, p in enumerate(prices):
field.ingest_price(label, float(p), 0, time.time() - (len(prices) - i) * 3600)
sig = field.compute_signature(label)
if sig:
total_mapped += 1
print(f" {label:8s} ${prices[-1]:>10,.2f} f={sig.dominant_frequency_hz:.4f} "
f"{sig.energy_state:13s} bot={sig.bot_activity:.2f}")
except Exception:
pass
except Exception as e:
print(f" ETFs: {e}")
# COMPUTE FULL FIELD
state = field.compute_field()
n = len(state.instruments)
acc = sum(1 for s in state.instruments.values() if s.energy_state == "accumulating")
dist = sum(1 for s in state.instruments.values() if s.energy_state == "distributing")
neut = n - acc - dist
print(f"\n{'='*60}")
print(f" GLOBAL ENERGY FIELD: {n} instruments mapped")
print(f" Categories: Crypto + Stocks + Forex + Commodities + Indices + ETFs")
print(f" Accumulating: {acc} | Distributing: {dist} | Neutral: {neut}")
print(f" Total energy: {state.total_energy:.4f}")
print(f" Net flow: {'INFLOW' if state.net_flow > 0 else 'OUTFLOW'}")
print(f" Coherence: {state.coherence:.3f}")
print(f" Dominant freq: {state.dominant_frequency:.4f}")
print(f" Extraction: {'ACTIVE' if state.extraction_active else 'quiet'}")
# SIGNALS
signals = field.get_trading_signals()
print(f"\n TRADING SIGNALS ({len(signals)}):")
for s in signals[:10]:
print(f" {s['action']:4s} {s['symbol']:8s} conf={s['confidence']:.2f} -- {s['reason']}")
# PHI-ALIGNED instruments
phi_aligned = [(sym, sig) for sym, sig in state.instruments.items() if sig.phi_alignment > 0.2]
if phi_aligned:
print(f"\n PHI-ALIGNED INSTRUMENTS ({len(phi_aligned)}):")
for sym, sig in sorted(phi_aligned, key=lambda x: -x[1].phi_alignment):
print(f" {sym:8s} phi={sig.phi_alignment:.2f} f={sig.dominant_frequency_hz:.4f}")
print(f"{'='*60}")
# Save
json.dump({
"instruments": n, "accumulating": acc, "distributing": dist, "neutral": neut,
"total_energy": state.total_energy, "coherence": state.coherence,
"signals": signals[:10], "phi_aligned": [(s, sig.phi_alignment) for s, sig in phi_aligned],
"timestamp": time.time(),
}, open("state/global_energy_field.json", "w"), indent=2, default=str)
|