Home /Modules/advantage/TRADING.md

TRADING.md

lib/advantage/TRADING.md · 163 line(s) · markdown

Trading — the Advantage™ trading-models subject

The SLeeLa port of the eleven trading models, the rate budget, and the counsel that ranks them. It mirrors the C and C++ module in /advantage (see its SUPPORTED.MODELS.md for what each model is and why it follows from the one before), and every figure here is checked against the same hand-computed anchors.

Directory: trading/ · Demo: trading/trading-demo.sleela (TradingDemo, 93 self-checks)

Everything here is pure computation. Nothing fetches a price, scrapes a page, or places an order. A live operation belongs behind the connect/ medium and its host adapters; the network/ subject already models venues, scouting and cashflow receipts.

How it fits the Advantage™ literature

The Advantage™ idea is to advantage a dividend with respect to a model. The trading subject supplies eleven concrete, quantified models whose result is always the same shape, so they can be compared and ranked:

 inputs (prices, fees, odds, days)
        |
        v
 SLTrading<Model>.evaluate(...)  --->  SLTradingResult
        |                              (cost, expected proceeds, profit,
        |                               return on cost, hold days)
        v
 result.advantage(costOfCapital)       reward minus (cost + opportunity cost)
        |
        v
 SLTradingApproach.addTrade(...)       becomes evidence (per unit of capital)
        |
        v
 SLTradingCounsel.rank(...)            score = mean x confidence x trust

Classes

FileClassPurpose
SLTradingResult.sleelaSLTradingResultCommon result; baseline(rate) and advantage(rate) bridge to the advantage model
SLTradingCheck.sleelaSLTradingCheckShared fail-closed validation and finite bounds
SLTradingArbitrage.sleelaSLTradingArbitrage1 · Same asset, two venues; breakeven(...)
SLTradingMarketMaking.sleelaSLTradingMarketMaking2 · Quote both sides; prices the unfilled case; bid/ask quotes
SLTradingRefurbishment.sleelaSLTradingRefurbishment3 · Improve and sell up-tier; outcome distribution
SLTradingRegional.sleelaSLTradingRegional4 · Buy here, move, sell there; loss and salvage; premium(...)
SLTradingAggregation.sleelaSLTradingAggregation5 · Assemble many items into a set; completion probability
SLTradingAsymmetry.sleelaSLTradingAsymmetry6 · One candidate listing: pay to look, win the race, be right; discount(...)
SLTradingConsignment.sleelaSLTradingConsignment7 · Commission with no inventory; labor and chargeback risk
SLTradingDistressed.sleelaSLTradingDistressed8 · Buy from urgency; win probability, pursuit cost, unsold remainder
SLTradingVirtual.sleelaSLTradingVirtual9 · Sell before sourcing; fulfilment failure and price drift
SLTradingSynthetic.sleelaSLTradingSynthetic10 · One into many, or many into one; waste and fallback value
SLTradingMomentum.sleelaSLTradingMomentum11 · Event-driven entry; exit failure; hypeDecay(...)
SLTradingRateBudget.sleelaSLTradingRateBudgetWait before the next request, from rate-limit numbers
SLTradingApproach.sleelaSLTradingApproachOne approach: evidence, assumptions held/doubted, honest score
SLTradingCounsel.sleelaSLTradingCounselRanks approaches best-first with cautions
trading-demo.sleelaTradingDemoRunnable demo + validation (main)

Run it:

./working-binaries/sleela run lib/advantage/trading/trading-demo.sleela

(run auto-links the sibling classes, so no imports are needed. Expect passed 93, failed 0 and ALL CHECKS PASSED.)

Conventions shared by every model

The advantage bridge

result.advantage(costOfCapital) is the expected proceeds minus the baseline, where the baseline is the total cost plus the opportunity cost of the capital tied up for holdDays at the yearly rate. A rate outside 0 to 10 (or NaN) gives no advantage. SLTradingApproach.addTrade(result, rate, perUnitCost) records it as evidence; with perUnitCost true, reward and baseline are divided by total cost so a large token trade and a small furniture flip compare per unit of capital instead of by size.

Counsel

SLTradingApproach.score(prior) is mean advantage x confidence x trust:

SLTradingCounsel.rank(prior) orders approaches best-first; ties keep insertion order, so the ranking is deterministic. The demo checks parity with the C++ module (Genius 1.2, Source/Spring 0.4714, Kid 0.2286).

The rate budget

SLTradingRateBudget turns what a server reports about its rate limit into a wait: an explicit Retry-After always wins, a reserve is held back, the usable budget is spread evenly over the rest of the window, and a floor interval is kept. A required wait over the caller's cap means stop, not sleep. It respects the limit; it does not evade one.

Honest limit: the SLeeLa String type exposes only concatenation and equality (no character access), so header text cannot be parsed in-language. The caller passes already-parsed numbers (-1.0 means the header was absent); strict string parsing lives in the C layer (rb_parse_nonneg).

Honest limits

Deliberately not built

Authoring notes (verified against the toolchain)