feat: wavelets

This commit is contained in:
OpenSquared
2026-07-24 20:22:21 +02:00
parent 32f2d27782
commit 67d27eaeb6
5 changed files with 99 additions and 31 deletions

View File

@@ -25,6 +25,18 @@ from typing import Dict, List, Optional
logger = logging.getLogger(__name__)
# Watchlist ticker -> a real yfinance symbol, for the fallback fetch when this instrument
# has no saxo_quote_symbol link (or its Saxo fetch fails) — mirrors
# instrument_service.py's _WAVELET_UNDERLYING_ALIASES (reverse direction: that one maps a
# yfinance/futures id back to the Watchlist ticker for cache lookups, this one maps the
# Watchlist ticker forward to a fetchable yfinance symbol).
_FRIENDLY_TO_YFINANCE = {
"GOLD": "GC=F", "SILVER": "SI=F", "COPPER": "HG=F", "PLATINUM": "PL=F",
"CRUDE": "CL=F", "BRENT": "BZ=F", "NATGAS": "NG=F",
"WHEAT": "ZW=F", "CORN": "ZC=F", "SOYBEANS": "ZS=F",
"SP500": "^GSPC", "NASDAQ": "^NDX", "DOW": "^DJI", "RUSSELL2000": "^RUT",
}
def _compute_slope(series: List[float]) -> List[float]:
n = len(series)
@@ -256,12 +268,15 @@ def _fetch_close_series(ticker: str, saxo_symbol: Optional[str]):
from services.data_fetcher import get_historical
yf_ticker = ticker.upper()
# Bare 6-letter FX pairs (EURUSD, GBPUSD...) are a common Watchlist ticker convention
# here but not a real yfinance symbol (needs the "=X" suffix) — without this, any
# Saxo-linked FX pair whose Saxo fetch fails falls through to a yfinance call that's
# guaranteed to return nothing, permanently keeping it out of the wavelet cache no
# matter how many refreshes run.
if len(yf_ticker) == 6 and yf_ticker.isalpha():
if yf_ticker in _FRIENDLY_TO_YFINANCE:
# GOLD/CRUDE/BRENT/SP500... aren't real yfinance symbols either — without this, any
# Saxo-linked commodity/index whose Saxo fetch fails falls through to a yfinance call
# that's guaranteed to return nothing, permanently keeping it out of the wavelet
# cache no matter how many refreshes run.
yf_ticker = _FRIENDLY_TO_YFINANCE[yf_ticker]
elif len(yf_ticker) == 6 and yf_ticker.isalpha():
# Bare 6-letter FX pairs (EURUSD, GBPUSD...) are a common Watchlist ticker
# convention here but not a real yfinance symbol (needs the "=X" suffix).
yf_ticker += "=X"
hist = get_historical(yf_ticker, period="1y", interval="1d")
return [h["close"] for h in hist], [h["date"] for h in hist]