Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
fenwick_tree_example.cc File Reference

Fenwick trees applied to trading and sports betting. More...

#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <tpl_fenwick_tree.H>
Include dependency graph for fenwick_tree_example.cc:

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 ()
 

Detailed Description

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.

SCENARIO 1 — Order Book Depth (Fenwick_Tree + find_kth)

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.

SCENARIO 2 — Intraday P&L Dashboard (Gen_Fenwick_Tree)

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).

SCENARIO 3 — Betting Exchange Dividends (Range_Fenwick_Tree)

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.

COMPILE & RUN:

g++ -std=c++20 -I.. -o fenwick_tree_example fenwick_tree_example.cc ./fenwick_tree_example

Definition in file fenwick_tree_example.cc.

Function Documentation

◆ bar()

static void bar ( int  val,
int  scale = 1 
)
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().

◆ main()

◆ scenario_betting_promos()

static void scenario_betting_promos ( )
static

Definition at line 299 of file fenwick_tree_example.cc.

References bar(), Aleph::DynList< T >::get(), and Aleph::maps().

Referenced by main().

◆ scenario_order_book()

static void scenario_order_book ( )
static

Definition at line 115 of file fenwick_tree_example.cc.

References bar(), Aleph::DynList< T >::get(), Aleph::maps(), and w.

Referenced by main().

◆ scenario_pnl_dashboard()

static void scenario_pnl_dashboard ( )
static

Definition at line 209 of file fenwick_tree_example.cc.

References h, and Aleph::maps().

Referenced by main().