83 for (
int i = 0; i <
w; ++i)
117 cout <<
"============================================================\n"
118 <<
" SCENARIO 1: Order Book Depth (Fenwick_Tree + find_kth)\n"
119 <<
"============================================================\n\n";
121 const size_t TICKS = 20;
125 cout <<
"Limit SELL orders arrive:\n";
129 { 0, 120,
"$100.00"},
131 { 3, 200,
"$100.03"},
133 { 7, 300,
"$100.07"},
134 {10, 150,
"$100.10"},
135 {15, 400,
"$100.15"},
142 <<
" +" <<
setw(4) <<
o.shares <<
" shares\n";
145 cout <<
"\nOrder book (ask side):\n\n";
146 cout <<
" Tick Price Volume Cumulative\n"
147 <<
" ---- -------- ------ ----------\n";
149 for (
size_t t = 0; t <
TICKS; ++t)
158 <<
" " <<
setw(10) <<
cum <<
" ";
164 int buy_sizes[] = {100, 250, 500, 1000, 1500};
166 cout <<
"\nMarket BUY order fill simulation:\n\n";
167 cout <<
" Order Size Worst Tick Worst Price\n"
168 <<
" ---------- ---------- -----------\n";
174 cout <<
" " <<
setw(10) << sz <<
" INSUFFICIENT LIQUIDITY\n";
183 cout <<
"\n>> Cancel 150 shares at tick 3 ($100.03)\n";
186 cout <<
">> New fill for 250 shares: ";
189 << (100.0 +
w * 0.01)
190 <<
" (tick " <<
w <<
")\n";
211 cout <<
"\n\n============================================================\n"
212 <<
" SCENARIO 2: Intraday P&L Dashboard (Gen_Fenwick_Tree)\n"
213 <<
"============================================================\n\n";
221 { 0, 1200.0,
"Open: initial scalp profit" },
222 { 5, -300.0,
"Stop-loss hit on AAPL" },
223 { 30, 4500.0,
"NVDA earnings beat — long pays off" },
224 { 31, 2200.0,
"Follow-through momentum" },
225 { 60, -800.0,
"Mean reversion loss" },
226 { 120, -1500.0,
"Lunch hour chop" },
227 { 180, 3000.0,
"Afternoon trend resumes" },
228 { 270, 8000.0,
"Fed holds rates — massive rally" },
229 { 271, 5000.0,
"Fed follow-through" },
230 { 330, -2000.0,
"Profit taking" },
231 { 389, 1500.0,
"MOC imbalance capture" },
236 int h = 9 + (
int)(m + 30) / 60;
237 int mm = ((
int)m + 30) % 60;
243 cout <<
"Trades booked:\n\n";
244 cout <<
" Time Minute P&L Event\n"
245 <<
" ----- ------ ---------- ----------------------------\n";
249 pnl.update(t.minute, t.pnl);
251 <<
" " <<
setw(6) << t.minute
253 <<
" " << t.event <<
"\n";
257 cout <<
"\nDashboard queries:\n\n";
267 <<
" Morning session (09:30-11:30): $" <<
setw(10) <<
morning <<
"\n"
268 <<
" Afternoon (11:30-16:00): $" <<
setw(10) <<
afternoon <<
"\n"
269 <<
" ----------------------------------------\n"
273 cout <<
"\n>> Correction: NVDA trade at 10:00 re-priced from "
274 <<
"$4500 to $4000\n";
275 pnl.update(30, -500.0);
276 cout <<
" Adjusted total day P&L: $"
301 cout <<
"\n\n============================================================\n"
302 <<
" SCENARIO 3: Betting Exchange Promotions (Range_Fenwick_Tree)\n"
303 <<
"============================================================\n\n";
305 const size_t DAYS = 14;
310 { 0, 6, 50,
"Welcome Week" },
311 { 3, 9, 30,
"Midweek Boost" },
312 { 5, 5, 100,
"Super Saturday" },
313 { 0, 13, 10,
"Loyalty Baseline" },
316 cout <<
"Promotions applied:\n\n";
317 cout <<
" Promotion Days Bonus/day\n"
318 <<
" ---------------- --------- ---------\n";
322 payouts.update(p.from, p.to, p.bonus);
323 cout <<
" " <<
setw(16) << left << p.name << right
324 <<
" " <<
setw(2) << p.from <<
" - " <<
setw(2) << p.to
325 <<
" " <<
setw(5) << p.bonus <<
"c\n";
330 "Mon W1",
"Tue W1",
"Wed W1",
"Thu W1",
"Fri W1",
"Sat W1",
"Sun W1",
331 "Mon W2",
"Tue W2",
"Wed W2",
"Thu W2",
"Fri W2",
"Sat W2",
"Sun W2"
334 cout <<
"\nDaily payout per user:\n\n"
335 <<
" Day Name Cents Breakdown\n"
336 <<
" --- ------- ----- ---------\n";
338 for (
size_t d = 0; d <
DAYS; ++d)
349 cout <<
"\nAccounting queries:\n\n";
356 cout <<
" Week 1 total (days 0-6): " <<
setw(5) <<
week1 <<
"c\n"
357 <<
" Week 2 total (days 7-13): " <<
setw(5) <<
week2 <<
"c\n"
359 <<
" ----------------------------------\n"
360 <<
" Grand total (14 days): " <<
setw(5) <<
total <<
"c\n";
363 cout <<
"\n>> Retroactive adjustment: 'Apology Bonus' +20c on days 10-13\n";
366 cout <<
" Adjusted week 2 total: " <<
payouts.query(7, 13) <<
"c\n"
367 <<
" Adjusted grand total: " <<
payouts.prefix(13) <<
"c\n";
371 cout <<
"\n>> With " <<
users <<
" users:\n"
372 <<
" Total 14-day cost: $"
Fenwick tree over an arbitrary abelian group.
Fenwick tree supporting range updates and range queries.
static void scenario_pnl_dashboard()
static void scenario_order_book()
static void bar(int val, int scale=1)
static void scenario_betting_promos()
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Fenwick tree for arithmetic types with find_kth support.
Fenwick tree (Binary Indexed Tree) for prefix queries.