|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Fenwick trees applied to trading and sports betting. More...
#include <cstdio>#include <iostream>#include <iomanip>#include <string>#include <tpl_fenwick_tree.H>Go to the source code of this file.
Functions | |
| static void | bar (int val, int scale=1) |
| static void | scenario_order_book () |
| static void | scenario_pnl_dashboard () |
| static void | scenario_betting_promos () |
| int | main () |
Fenwick trees applied to trading and sports betting.
This example demonstrates the three Fenwick tree variants through realistic scenarios from quantitative finance and betting exchanges.
A stock exchange order book tracks how many shares are available to buy at each price tick. A trader placing a market order of size K needs to know: "what is the worst price I will pay?" That is exactly find_kth(K) — the lowest price tick whose cumulative volume reaches K.
A trading desk records the profit/loss of each executed trade by the minute-bucket in which it occurred. The risk dashboard needs real-time answers to "what was the P&L between 10:15 and 11:30?" — a range query that the classic Fenwick tree answers in O(log n).
A betting exchange distributes daily dividends to participants. Each promotion covers a contiguous span of days and adds a fixed bonus per day. Promotions overlap freely. The accounting team needs both "total paid on day d" and "total cost over days [l, r]". This is the textbook use-case for range-update / range-query.
g++ -std=c++20 -I.. -o fenwick_tree_example fenwick_tree_example.cc ./fenwick_tree_example
Definition in file fenwick_tree_example.cc.
|
static |
Definition at line 80 of file fenwick_tree_example.cc.
References Aleph::maps(), and w.
Referenced by demo_practical(), scenario_betting_promos(), and scenario_order_book().
| int main | ( | ) |
Definition at line 379 of file fenwick_tree_example.cc.
References Aleph::maps(), scenario_betting_promos(), scenario_order_book(), and scenario_pnl_dashboard().
|
static |
Definition at line 299 of file fenwick_tree_example.cc.
References bar(), Aleph::DynList< T >::get(), and Aleph::maps().
Referenced by main().
|
static |
Definition at line 115 of file fenwick_tree_example.cc.
References bar(), Aleph::DynList< T >::get(), Aleph::maps(), and w.
Referenced by main().
|
static |
Definition at line 209 of file fenwick_tree_example.cc.
References h, and Aleph::maps().
Referenced by main().