cyberkyne's picture
Upload 22 files
094a5f6 verified
"""utils/config.py β€” reads from HF Spaces Secrets (env vars)."""
import os
from pathlib import Path
TMP = Path("/tmp/quant")
for d in ["pdfs","tick_cache","compiled","exports"]:
(TMP / d).mkdir(parents=True, exist_ok=True)
def get(k, default=""): return os.environ.get(k, default)
ANTHROPIC_API_KEY = get("ANTHROPIC_API_KEY")
HF_TOKEN = get("HF_TOKEN")
HF_DATASET_REPO = get("HF_DATASET_REPO")
HF_TICK_REPO = get("HF_TICK_REPO")
SIMILARITY_THRESHOLD = float(get("SIMILARITY_THRESHOLD", "0.85"))
MAX_TOKENS_PER_CHUNK = int(get("MAX_TOKENS_PER_CHUNK", "3000"))
OCR_DPI = int(get("OCR_DPI", "300"))
INITIAL_EQUITY = float(get("INITIAL_EQUITY", "10000"))
COMMISSION_PCT = float(get("COMMISSION_PCT", "0.0002"))
RISK_PER_TRADE = float(get("RISK_PER_TRADE", "0.01"))
WF_WINDOWS = int(get("WF_WINDOWS", "5"))
WF_IS_RATIO = float(get("WF_IS_RATIO", "0.70"))
MAX_PARAM_COMBOS = int(get("MAX_PARAM_COMBOS", "300"))
MIN_TRADES = int(get("MIN_TRADES", "30"))
MIN_SHARPE = float(get("MIN_SHARPE", "0.5"))
BACKTEST_TFS = get("BACKTEST_TIMEFRAMES", "1h,4h,1d").split(",")
CATEGORIES = [
"Trend Following","Mean Reversion","Statistical Arbitrage",
"Momentum","Breakout","Volatility Trading","Market Making",
"Pattern Recognition","Machine Learning","Options Strategy",
"High Frequency","Pairs Trading","Carry Trade",
"Seasonal / Calendar","Risk Management","Position Sizing",
"Portfolio Construction","Market Microstructure","Other",
]
EXTRACTION_PROMPT = """
You are a quantitative finance knowledge extraction engine.
Extract ALL trading strategies, mathematical formulas, and complete trading systems
from the text below (taken from an algorithmic trading book).
Output ONLY valid JSON β€” no markdown fences, no preamble:
{
"strategies": [{
"name": "string", "category": "string", "description": "string",
"entry_rules": ["string"], "exit_rules": ["string"],
"filters": ["string"], "timeframes": ["string"], "instruments": ["string"],
"parameters": {"name": "description with typical value"},
"mathematical_basis": "string", "source_context": "string"
}],
"formulas": [{
"name": "string", "category": "string",
"latex": "LaTeX string", "plain_text": "string",
"variables": {"symbol": "description"},
"purpose": "string", "usage_context": "string", "source_context": "string"
}],
"systems": [{
"name": "string", "components": ["string"],
"entry_system": "string", "exit_system": "string",
"risk_management": "string", "position_sizing": "string",
"backtesting_notes": "string", "source_context": "string"
}]
}
Rules: empty arrays [] if nothing found. Preserve exact math. Include LaTeX.
Source: {source_file} | Pages: {page_start}–{page_end}
--- TEXT ---
{text}
--- END ---
""".strip()
COMPILER_PROMPT = """
You are a Julia algorithmic trading code generator.
Convert the strategy JSON below into executable Julia code.
Output ONLY the Julia code β€” no markdown fences, no explanation, no module/using declarations.
EXACT REQUIRED FORMAT (two functions, nothing else):
function get_param_grid() :: Dict{{String, Vector{{Float64}}}}
return Dict(
"param_name" => [val1, val2, val3],
)
end
function generate_signals(
open_p :: Vector{{Float64}},
high :: Vector{{Float64}},
low :: Vector{{Float64}},
close :: Vector{{Float64}},
volume :: Vector{{Float64}},
params :: Dict{{String, Float64}},
) :: Vector{{Int}}
n = length(close)
signals = zeros(Int, n)
# ... your logic here ...
return signals
end
RULES (CRITICAL β€” violations cause compile failure):
1. NO module, NO using, NO include statements
2. ALWAYS check isnan() before using indicator values
3. Return signals[i] = 0 during indicator warmup period
4. Values: 1=long, -1=short, 0=flat only
5. Get int params: Int(round(get(params, "key", default)))
6. Get float params: get(params, "key", default)
AVAILABLE FUNCTIONS (pre-injected, call directly without prefix):
Trend: sma(s,n) ema(s,n) wma(s,n) tema(s,n) dema(s,n)
Momentum: rsi(c,n) macd(c;fast,slow,sig)->(ml,sl,hist) momentum(s,n) roc(s,n)
Bands: bbands(c,n,k)->(up,mid,lo) keltner(h,l,c,n,k)->(up,mid,lo)
Channel: donchian(h,l,n)->(up,mid,lo) highest(s,n) lowest(s,n)
Volatility: atr(h,l,c,n) std_dev(s,n) zscore(s,n)
Oscillators: stoch(h,l,c;k,d)->(K,D) cci(h,l,c,n) williams_r(h,l,c,n)
Volume: vwap(h,l,c,v) obv(c,v) cmf(h,l,c,v,n)
Trend strength: adx(h,l,c,n)->(adx,pdi,ndi)
Crosses: crossover(a,b)->Bool[] crossunder(a,b)->Bool[]
Math: mean(v) std(v) diff(v) cumsum(v) abs(x) sqrt(x)
Strategy:
{strategy_json}
""".strip()