CoolFace
Apppublic

shaibu01/Titan-Engine

sourceHugging Faceupdated 2d agoView on Hugging Face
0likes
App README

Titan Engine

Independent multi-horizon algorithmic engine for the Titan stack.

Titan-Engine is the second system beside Syndicate. It is designed to run its own research, signal ranking, brain-style horizon selection, portfolio sizing, and cloud execution preflight while staying light enough for Hugging Face CPU Basic. Live trading is disabled by default and requires explicit environment gates.

What This Demonstrates

  • —Research app: Streamlit dashboard with a reproducible Titan research cycle.
  • —Backtest engine: formulaic signals, transaction costs, slippage, turnover, paper trade targets, and volatility-targeted sizing.
  • —Walk-forward validation: purged train/OOS folds with fold-level edge, Sharpe, activity, and selected-asset reporting.
  • —Multiple-testing controls: deflated Sharpe probability, probability of backtest overfitting, permutation-null Z-score, tail ratio, and drawdown gates.
  • —Portfolio construction: QUBO-style optimizer that limits exposure to a small selected subset instead of spreading risk across every available asset.
  • —Regime model: multi-asset HMM-style overlay for risk-on, risk-off, inflation shock, and dollar-squeeze priors.
  • —Brain controller: global-workspace scoring, sparse MoE expert routing, hippocampus-style diagnostic memory, horizon routing, and overfit vetoes.
  • —Cloud preflight: quote freshness, account telemetry freshness, spread, margin, duplicate-order, expected-fulfillment, and failover checks.

Titan Research Cycle

The portfolio_research_lab.py module is the engine's reproducible research harness. The default offline run uses deterministic multi-regime market data so the system can boot without paid feeds, and it can be extended to cached/live public data sources. The default run produces:

  • —A multi-asset price panel.
  • —Six formulaic signal families: trend momentum, mean reversion, breakout pressure, volatility compression, cross-asset residual, and carry quality.
  • —Walk-forward signal weighting based only on each training fold.
  • —A QUBO-style allocator that caps the number of active assets.
  • —A paper trade blotter, target allocation table, and volatility-target scalar.
  • —A robustness gate table with pass/fail evidence.

Titan Brain System

titan_brain_system.py is the brain-style controller around the research and risk layers.

  • —Global workspace: broadcasts only the strongest current evidence.
  • —Hippocampus memory: stores selected assets, failed gates, robustness, and overfit pressure for the next decision loop.
  • —Basal ganglia selector: chooses whether to arm a paper trade or hold research.
  • —Cerebellum predictor: penalizes cost drag, drawdown, and uncertainty before a horizon is selected.
  • —Sparse MoE cortex: keeps a larger expert pool available while activating only the number of expert clusters the CPU/RAM budget can support.
  • —Horizon router: evaluates tactical, swing, and position/long-hold plays from the same evidence set instead of forcing one universal timeframe.
  • —Data-source lattice: scores price, quote, macro, filings, positioning, event, crypto, and local-memory sources by reliability, coverage, resource cost, and overfit risk.

Cloud Beast

titan_cloud_beast.py provides the cloud-native multi-asset preflight brain.

  • —30 cross-asset desks for FX, rates, curve, real yields, credit, liquidity, index, commodity, crypto, news, earnings, and event impulses.
  • —40 alternative-data signal slots, including consumer stress, freight, labor, housing, credit, weather, and recession proxies.
  • —Lightweight multi-asset regime prior.
  • —Direct-trade packet construction with order-state memory, duplicate-order checks, quote freshness, account telemetry freshness, margin checks, spread limits, and expected time-to-fulfillment.
  • —Market execution is preferred when spread and fulfillment formulas agree. Stop orders are selected only when the formulas call for a cleaner trigger.

Independent Provider Fabric

Titan-Engine owns its market state. Syndicate packets may be displayed as optional external context, but they never populate cloud account, quote, bar, position, or execution state.

The shared relay defaults to 34.174.41.227 with separate ingress lanes:

bash
TITAN_ZMQ_HUB_HOST=34.174.41.227
TITAN_HUB_IN_PORT=5555
TITAN_HUB_OUT_PORT=5556
TITAN_HUB_EXEC_IN_PORT=5557

Market/account packets enter on 5555, execution and refresh commands enter on 5557, and subscribers receive the unified ordered stream on 5556. gcp_zmq_relay/ contains the Ubuntu systemd deployment. Public deployments should enable CURVE keys or otherwise restrict network access; never expose an unauthenticated execution relay to the internet.

Firewall deployment is explicit and two-layered. From authenticated Cloud Shell, run gcp_zmq_relay/configure_gcp_firewall.sh with TITAN_ZMQ_SOURCE_RANGES set to trusted client CIDRs. On the VM, run gcp_zmq_relay/configure_host_firewall.sh with the same value. Both scripts open only TCP 5555-5557 for Titan traffic; SSH remains separate on TCP 22. Public 0.0.0.0/0 ZMQ ingress is rejected unless TITAN_ALLOW_PUBLIC_ZMQ=1 is deliberately supplied. If broad ingress is unavoidable, run gcp_zmq_relay/generate_curve_keys.py, append the server fragment only to /etc/titan-zmq-relay.env, and install the client fragment as private environment secrets on every authorized client.

  • —ALPACA and PU_PRIME_MT5 are independent primary providers.
  • —Alpaca orders execute directly through Alpaca; PU Prime CFD orders execute through the MT5 ZMQ adapter.
  • —Quotes, bars, accounts, positions, and health are keyed by provider and symbol, so one provider can never satisfy another provider's execution gate.
  • —Either provider can operate alone. Dual-provider mode retains both account and price identities and selects a route using provider health, instrument compatibility, quote freshness, and spread quality.
  • —Alpaca REST access uses one shared rolling request budget with single-provider backoff after 429 responses. The defaults avoid busy polling while keeping the direct feed current:
bash
TITAN_ALPACA_REQUESTS_PER_MINUTE=180
TITAN_ALPACA_MIN_REQUEST_INTERVAL_SEC=0.20
TITAN_CLOUD_ALPACA_QUOTE_SEC=1
TITAN_CLOUD_ALPACA_BAR_SEC=30
TITAN_CLOUD_ALPACA_ACCOUNT_SEC=15

The dashboard's provider table is authoritative for cloud-owned connectivity. Automatic Syndicate-heartbeat failover is off by default; set TITAN_CLOUD_FAILOVER_AUTORUN=1 only when that explicit external-control mode is required.

Live-Trading Safety

Live cloud execution arms automatically when ALPACA_ENV=LIVE and the Space has ALPACA_KEY_ID, ALPACA_SECRET_KEY, and ALPACA_BASE_URL. To force simulation, set TITAN_CLOUD_FORCE_DRY_RUN=1. The legacy double-confirm gates still work, and can be required by setting TITAN_CLOUD_REQUIRE_EXTRA_LIVE_FLAGS=1:

bash
TITAN_CLOUD_LIVE_TRADING=1
TITAN_ALLOW_CLOUD_EXECUTION=1

Cloud failover execution additionally requires:

bash
TITAN_CLOUD_FAILOVER_EXECUTION=1

Without those flags the Space displays dry-run packets and paper targets only. The Docker entrypoint is space_supervisor.py. It owns titan_core.py and the alt-data process independently of Streamlit, so provider telemetry, Alpaca direct feed, ZMQ packets, execution supervision, and exits continue when no browser session is attached. The supervisor injects TITAN_ENABLE_BACKGROUND_CORE=0 into Streamlit to prevent duplicate cores; that value does not disable the container-supervised autonomous engine.

Strict neural process locking is disabled by default. Set TITAN_STRICT_NEURAL_BOOT_LOCK=1 only when you want the Space to pause titan_core.py until the full neural swarm has been restored or forged. Provider data, risk, and execution gates remain active while the neural forge warms. Set TITAN_REQUIRE_NEURAL_FOR_ENTRIES=1 only when a complete expert swarm must be mandatory for every new entry.

Local Run

bash
pip install -r requirements.txt
streamlit run app.py

Run the test suite:

bash
python3 -m unittest -q

Key Files

  • —app.py: Streamlit dashboard.
  • —portfolio_research_lab.py: research/backtest/gate/optimizer lab.
  • —titan_brain_system.py: sparse brain controller and horizon router.
  • —titan_cloud_beast.py: cloud preflight engine and failover guardian.
  • —quant_gatekeeper.py: neural ensemble inference shell.
  • —quant_hidden_markov.py: persisted regime model support.
  • —risk_engine.py: desk-level Kelly, drawdown, VaR/CVaR, and risk sizing.
  • —test_portfolio_research_lab.py: research lab regression tests.
  • —test_titan_cloud_beast.py: cloud preflight and failover tests.

Assumptions And Limits

  • —The offline research cycle uses deterministic data unless a live/cached data adapter is attached.
  • —Reported paper trades are research outputs, not financial advice.
  • —Costs and slippage are configurable and included in the default gate report.
  • —Results are meant to demonstrate reproducible process quality, not guarantee future profitability.
  • —Syndicate remains a separate system; Titan-Engine has its own brain and timeframe stack.

<!-- CLOUDLIVEBYALPACAENVPATCHV1 -->