ADVERTISING / NOTEBOOK LESSON

48 · A02 · Billing, denominators, and a three-party ledger

Calculate billing and conversion denominators while preserving three-party accounting.

Constructed mechanism / simulationRead-only · saved experiment

Saved outputs come from recorded teaching runs; opening this page does not rerun an experiment. The code and original outputs are preserved; original-language data and annotations may remain.

A02 · Billing, denominators, and a three-party ledger

Prerequisites: foundations 31–34; A01.

Evidence: explicitly constructed mechanism experiments, not real ad logs. This chapter does not claim industrial-system reproduction or online gains.

Learning order: predict → change one variable → run → explain.

English companion. All instructional Markdown is translated. Experiment code, Chinese language examples, execution counts, and saved outputs remain as in the source edition; historical output text may therefore be Chinese. The initial setup cell anchors the working directory and Python import path for this companion's deeper folder; it does not change the experiment. Saved outputs are historical evidence, not a new run. Run from the top after preparing the required data and models.

PYTHON · 01
# English companions live one directory deeper; keep the original experiment code unchanged.
from pathlib import Path as _TranslationPath
import os as _translation_os
import sys as _translation_sys
_translation_root = next((p for p in [_TranslationPath.cwd(), *_TranslationPath.cwd().parents]
                          if (p / "reclab").is_dir()), None)
if _translation_root is None:
    raise RuntimeError("Open this notebook from inside the Search Recommendation Ads Lab checkout.")
_translation_os.chdir(_translation_root)
if str(_translation_root) not in _translation_sys.path:
    _translation_sys.path.insert(0, str(_translation_root))

Problem and input/output contract

Define CTR=clicks/impressions, CVR=conversions/clicks, and CTCVR=conversions/impressions. CTCVR=CTR×CVR requires conversions to belong to the click path. CPM=1000×spend/impressions, CPC=spend/clicks, CPA=spend/conversions. eCPM is expected currency per thousand impressions; for a CPC bid, eCPM=1000×pCTR×CPC. ROAS=attributed revenue/ad spend, not profit margin. This example has no platform fee, so publisher receipts equal advertiser payments.

Before running, predict which result the changed variable will affect and which invariants must hold.

PYTHON · 02
from pathlib import Path
import sys
root=Path.cwd()
if not (root/'reclab').exists(): root=root.parent
if str(root) not in sys.path: sys.path.insert(0,str(root))
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from reclab import ads_curriculum as ac

Run the one-variable comparison

Inputs are small constructed examples visible in source. Output units and constraints are defined above. Run assertions to verify mathematics and accounting.

PYTHON · 03
a=ac.billing(); b=ac.billing(clicks=400)
display(pd.DataFrame([a,b],index=['200 clicks','400 clicks']))
assert abs(a['ctr']*a['cvr']-a['ctcvr'])<1e-12
assert abs(1000*a['ctr']*a['cpc']-a['cpm'])<1e-12
assert a['publisher_receipt']==80
Saved notebook output · not executed on this page
ctr cvr ctcvr cpm cpc cpa roas advertiser_margin publisher_receipt
200 clicks 0.02 0.04 0.0008 8.0 0.4 10.0 3.0 160.0 80.0
400 clicks 0.04 0.02 0.0008 8.0 0.2 10.0 3.0 160.0 80.0

Interpretation and limits

Changing only click count while spend and conversions stay fixed increases CTR, reduces CPC and CVR, and leaves CPA and ROAS unchanged. Higher CTR does not establish higher advertiser profit. Revenue also differs from incremental revenue caused by advertising.

Inspect source, then try an exercise

Add a 10% platform fee and write the conservation equation: advertiser spending=platform revenue+publisher revenue. Change the conversion denominator to impressions and identify the correct metric name.

PYTHON · 04
import inspect
print(inspect.getsource(ac.billing))
Saved notebook output · not executed on this page
def billing(impressions=10000, clicks=200, conversions=8, spend=80., revenue=240.):
    if not 0 < conversions <= clicks <= impressions or spend <= 0:
        raise ValueError('Require positive, nested event counts and spend')
    ctr, cvr = clicks/impressions, conversions/clicks
    return dict(ctr=ctr, cvr=cvr, ctcvr=conversions/impressions,
                cpm=1000*spend/impressions, cpc=spend/clicks,
                cpa=spend/conversions, roas=revenue/spend,
                advertiser_margin=revenue-spend, publisher_receipt=spend)

Sources and next step

A-CCR pp. 33–41; billing and ledger definitions expanded by the Lab. This is an original Lab exercise, not a copy of the complete lecture text.

Chinese GitHub chapter · Authors’ RTB slides. The Chinese deck is not a complete modern advertising-engineering course. Historical descriptions of platforms are not presented as current market facts.

After the exercise, return to the ads learning path and continue to the next semantic unit.

GO TO THE SOURCE

Sources for this lesson

Completion marks are optional and stored only in this browser. Reading a page does not mark it complete.