Add multi-base chain modelling, fix price-band-aware demand/supply, tranche-split sell tool
- puga/network.py + tools/network.py: model a multi-base chain (e.g. mine LST at one base, ship it, consume it at another). Simulates each base independently, nets a transferred material's producer-surplus against consumer-need, charges real freight only on what's moved, cm_free for a founding covered by a Core Module Kit. Worked example in plans/chains/. - puga/saturation.py: real price-band filtering. FIO's order_book NarrowPriceBandLow/High and WidePriceBandLow/High match APEX's own displayed Price Band exactly (verified live) - an order outside it is a stale artifact, not just uncompetitive. Added in_band() and effective_demand(); effective_supply() gained the same hard band filter alongside its existing soft vwap-proximity filter (renamed that param mult to free up `band`). Wired into tools/scan.py stage 2 in place of the raw, unfiltered demand figure. Was flagged as an unimplemented refinement in saturation-design.md since the original design review. - tools/sell.py: self-contained tranche split (aggressive tranche capped at a volume quantile, median normally or 80th pct with --tight when a payment is imminent and stockout risk outweighs margin; patient tranche priced under the next competitor tier). Instant-bid comparison moved behind --show-bid (off by default). - Docs and roadmap updated accordingly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
spec = importlib.util.spec_from_file_location("sell", Path(__file__).resolve().parent.parent / "tools" / "sell.py")
|
||||
sell = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(sell)
|
||||
|
||||
TRADES = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] # evenly spaced: median 25, 80th pct 40
|
||||
|
||||
|
||||
def test_quantile_median_and_80th():
|
||||
assert sell.quantile(TRADES, 0.5) == 25
|
||||
assert sell.quantile(TRADES, 0.8) == 40
|
||||
assert sell.quantile([], 0.5) == 0.0
|
||||
|
||||
|
||||
def test_tranche_split_caps_aggressive_at_quantile_not_full_stock():
|
||||
aggr, patient = sell.tranche_split(60, TRADES, tight=False)
|
||||
assert aggr == 25 and patient == 35 # median cap
|
||||
|
||||
|
||||
def test_tranche_split_tight_uses_higher_quantile():
|
||||
aggr, patient = sell.tranche_split(60, TRADES, tight=True)
|
||||
assert aggr == 40 and patient == 20 # 80th pct cap, bigger aggressive tranche than non-tight
|
||||
|
||||
|
||||
def test_tranche_split_no_split_when_stock_below_quantile():
|
||||
aggr, patient = sell.tranche_split(11, TRADES, tight=False)
|
||||
assert aggr == 11 and patient == 0 # whole stock fits under the median, nothing held back
|
||||
|
||||
|
||||
def test_tranche_split_falls_back_to_full_qty_with_no_history():
|
||||
aggr, patient = sell.tranche_split(8, [], tight=False)
|
||||
assert aggr == 8 and patient == 0
|
||||
Reference in New Issue
Block a user