diff --git a/.gitignore b/.gitignore index 60582a6..8ec7f3f 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,6 @@ RELEASE_CHECKLIST.md invoice_template.html AI Business Idea Generation.pdf *.pdf + +# The typeset working paper is a deliverable, not a build artifact. +!docs/working_paper/detection_timing_backtest_2026-07.pdf diff --git a/docs/working_paper/README.md b/docs/working_paper/README.md index 8f3faf4..a033c4f 100644 --- a/docs/working_paper/README.md +++ b/docs/working_paper/README.md @@ -1,19 +1,21 @@ # Working Paper **Detection-Timing Backtest of a Deterministic Downside-Risk Screen Across Three Modern Financial Crises** -Zarif Latif. Revision 2, October 2026 (first version July 2026). +Md. Zarif Latif (BRAC University). Working paper, October 2026. -Revision 2's headline finding: the pipeline flagged all 9 affected names before their formal resolution dates, but **no first flag came before the first headline reporting the stock already falling** (Section 4.5). The paper presents the system as fast, auditable triage, not anticipation. +Headline finding: the pipeline flagged all 9 affected names before their formal resolution dates, but **no first flag came before the first headline reporting the stock already falling** (Section 4.5). The paper presents the system as fast, auditable triage, not anticipation. ## Files - `detection_timing_backtest_2026-07.md` — the paper. Renders on GitHub, Substack, arXiv-style preprint sites. **This is the primary artifact.** +- `detection_timing_backtest_2026-07.pdf` — the typeset PDF (the version posted on SSRN). - `detection_timing_backtest_2026-07.html` — self-contained HTML. Open in any browser. Save-as-PDF via browser print dialog for a shareable attachment. ## Rebuild the HTML ```bash -python scripts/render_working_paper.py +python scripts/render_working_paper.py # HTML only +python scripts/render_working_paper.py --pdf # HTML + typeset PDF (WeasyPrint) ``` The HTML has all CSS inlined and no external assets, so a single file emailed / posted anywhere renders correctly on any modern browser. @@ -49,6 +51,6 @@ pytest aetherius/tests/test_market_reaction_check.py -v ## Posting as a preprint -- **SSRN** (ssrn.com, free): good fit under Financial Economics → Risk Management. Upload a PDF made from the HTML (browser print → Save as PDF). No affiliation is required. +- **SSRN** (ssrn.com, free): good fit under Financial Economics → Risk Management. Upload `detection_timing_backtest_2026-07.pdf` (build it with `python scripts/render_working_paper.py --pdf`). - **arXiv q-fin.RM / q-fin.CP**: a first-time submitter usually needs an endorsement from an existing arXiv author in that category. Ask a professor or a researcher whose work you cite. - In the abstract, keep the Revision 2 framing: triage at the market reaction, not anticipation. diff --git a/docs/working_paper/detection_timing_backtest_2026-07.html b/docs/working_paper/detection_timing_backtest_2026-07.html index 1163199..0cdfd3d 100644 --- a/docs/working_paper/detection_timing_backtest_2026-07.html +++ b/docs/working_paper/detection_timing_backtest_2026-07.html @@ -2,7 +2,7 @@ -Detection-Timing Backtest of a Systematic Downside-Risk Screen Across Three Modern Financial Crises +Detection-Timing Backtest of a Deterministic Downside-Risk Screen Across Three Modern Financial Crises \n" "\n\n" f"{body_html}\n" @@ -76,6 +128,82 @@ def render() -> Path: return OUT_PATH +_DATE_RE = re.compile(r"(\d{4}-\d{2}-\d{2}(?: \d{2}:\d{2}Z)?)") + + +def _print_html(body_html: str) -> str: + """Restructure the rendered Markdown for print: title block, abstract box, + page break before Section 1, references with hanging indents, and dates in + table cells kept on one line.""" + soup = BeautifulSoup(body_html, "html.parser") + h1 = soup.find("h1") + abstract = soup.find("h2", id="abstract") + # Title block: everything between the title and the Abstract heading. + block = soup.new_tag("div", attrs={"class": "titleblock"}) + node = h1.find_next_sibling() + while node is not None and node is not abstract: + nxt = node.find_next_sibling() + block.append(node.extract()) + node = nxt + paras = block.find_all("p") + if paras: + paras[-1]["class"] = "date" + h1.insert_after(block) + # Abstract section: from the Abstract heading to the next h2. + section = soup.new_tag("section", attrs={"class": "abstract"}) + abstract.insert_before(section) + node = abstract + while node is not None and not (node.name == "h2" and node is not abstract): + nxt = node.find_next_sibling() + section.append(node.extract()) + node = nxt + if node is not None: + node["class"] = "first-section" + # References: hanging indents. + refs = soup.find("h2", id="references") + if refs is not None: + rsec = soup.new_tag("section", attrs={"class": "references"}) + refs.insert_before(rsec) + node = refs + while node is not None and not (node.name == "h2" and node is not refs): + nxt = node.find_next_sibling() + rsec.append(node.extract()) + node = nxt + # Dates inside table cells must not break at their hyphens. + for cell in soup.find_all(["td", "th"]): + for text in list(cell.find_all(string=_DATE_RE)): + parts = _DATE_RE.split(str(text)) + new = [] + for i, part in enumerate(parts): + if i % 2: + span = soup.new_tag("span", attrs={"class": "nowrap"}) + span.string = part + new.append(span) + elif part: + new.append(part) + text.replace_with(*new) + return str(soup) + + +def render_pdf() -> Path: + from weasyprint import HTML + + md_text = IN_PATH.read_text(encoding="utf-8") + body_html = markdown.markdown(md_text, extensions=["tables", "fenced_code", "toc"]) + html = ( + "" + f"{TITLE}" + f"" + f"{_print_html(body_html)}" + ) + HTML(string=html, base_url=str(IN_PATH.parent)).write_pdf(PDF_PATH) + return PDF_PATH + + if __name__ == "__main__": + import sys + out = render() print(f"Rendered -> {out}") + if "--pdf" in sys.argv: + print(f"Rendered -> {render_pdf()}") diff --git a/site/index.html b/site/index.html index 5fc6cbb..5be7167 100644 --- a/site/index.html +++ b/site/index.html @@ -130,7 +130,7 @@

Run it yourself

python simulations/backtest/run_backtest.py --event svb-2023

About

-

Built by Zarif Latif as a study in building auditable data systems and evaluating them honestly. Python, FastAPI, PostgreSQL, Celery and GitHub Actions. Feedback, especially critical feedback, is welcome: zarif@aetheriusresearch.tech.

+

Built by Zarif Latif as a study in building auditable data systems and evaluating them honestly. Python, FastAPI, PostgreSQL, Celery and GitHub Actions. Feedback, especially critical feedback, is welcome: zarif.latif.biz@gmail.com.