SPB Git

Repository Public

event-study.tsx 5.9 KB 89 lines tsx

1import type { Locale } from "@/schema";2import { createRng } from "../core";3import { numberOption, param, type SimConfig, type SimDef } from "../types";4import { Chart, chartSpec } from "../ui/Chart";5import { fmt, fmtInt } from "../ui/format";6import { Readouts } from "../ui/Readouts";78export interface EventStudyModel {9  events: number; window: number; jump: number; drift: number; sigma: number;10  /** Event time −W … W. */11  t: number[];12  /** Cross-sectional mean abnormal return and its standard error, per event day (percent). */13  ar: number[]; arSe: number[];14  /** Mean cumulative abnormal return from −W and its standard error (percent). */15  car: number[]; carSe: number[];16  /** Expected CAR at the end of the window: jump + W × drift. */17  expectedCar: number;18  /** t statistic of the mean abnormal return on the event day. */19  tEvent: number;20}2122export function computeEventStudy(p: Readonly<Record<string, number>>, seed: number, config: SimConfig): EventStudyModel {23  const N = Math.round(p.events), W = Math.round(numberOption(config, "window", 10, 3, 20));24  const T = 2 * W + 1;25  const rng = createRng(seed, "event");26  const s1 = new Array<number>(T).fill(0), s2 = new Array<number>(T).fill(0), c1 = new Array<number>(T).fill(0), c2 = new Array<number>(T).fill(0);27  for (let i = 0; i < N; i++) {28    let cum = 0;29    for (let k = 0; k < T; k++) {30      const t = k - W;31      const ar = p.sigma * rng.normal() + (t === 0 ? p.jump : 0) + (t > 0 ? p.drift : 0);32      cum += ar;33      s1[k] += ar; s2[k] += ar * ar; c1[k] += cum; c2[k] += cum * cum;34    }35  }36  const stats = (a: number[], b: number[]) => {37    const m = a.map((v) => v / N);38    const se = m.map((mu, k) => Math.sqrt(Math.max(0, (b[k] - N * mu * mu) / (N - 1)) / N));39    return [m, se] as const;40  };41  const [ar, arSe] = stats(s1, s2), [car, carSe] = stats(c1, c2);42  return { events: N, window: W, jump: p.jump, drift: p.drift, sigma: p.sigma, t: Array.from({ length: T }, (_, k) => k - W), ar, arSe, car, carSe, expectedCar: p.jump + W * p.drift, tEvent: ar[W] / arSe[W] };43}4445const TXT = {46  fr: { ar: "Rendement anormal moyen (AR)", car: "Rendement anormal cumulé moyen (CAR)", t: "Jour relatif à l'événement", ary: "AR moyen (%)", cary: "CAR moyen (%)", ev: "événement", ar0: "AR moyen au jour 0", tstat: "Statistique t au jour 0", carEnd: "CAR à la fin de la fenêtre", exp: "CAR attendu (saut + dérive)", n: "Événements" },47  en: { ar: "Mean abnormal return (AR)", car: "Mean cumulative abnormal return (CAR)", t: "Day relative to the event", ary: "Mean AR (%)", cary: "Mean CAR (%)", ev: "event", ar0: "Mean AR on day 0", tstat: "t statistic on day 0", carEnd: "CAR at the end of the window", exp: "Expected CAR (jump + drift)", n: "Events" },48} as const;4950function EventStudyView({ model: m, locale, idPrefix }: { model: EventStudyModel; locale: Locale; idPrefix: string }) {51  const L = TXT[locale];52  const band = (y: number[], se: number[]) => m.t.map((t, k) => ({ x: t, y: y[k], lo: y[k] - 1.96 * se[k], hi: y[k] + 1.96 * se[k] }));53  const last = m.t.length - 1;54  const pm = (v: number, se: number) => `${fmt(locale, v, 2)} ± ${fmt(locale, 1.96 * se, 2)} %`;55  return (56    <>57      <Chart locale={locale} idPrefix={`${idPrefix}-ar`} height={240} chart={chartSpec({ kind: "line", dataKind: "synthetic", title: L.ar, xLabel: L.t, yLabel: L.ary, series: [{ name: `${L.ar} ± ${fmt(locale, 1.96, 2)} SE`, tone: "blue", points: band(m.ar, m.arSe) }], annotations: [{ x: 0, label: L.ev }] })} />58      <Chart locale={locale} idPrefix={`${idPrefix}-car`} height={260} chart={chartSpec({ kind: "line", dataKind: "synthetic", title: L.car, xLabel: L.t, yLabel: L.cary, series: [{ name: `${L.car} ± ${fmt(locale, 1.96, 2)} SE`, tone: "teal", points: band(m.car, m.carSe) }], annotations: [{ x: 0, label: L.ev }] })} />59      <Readouts items={[60        { label: L.ar0, value: pm(m.ar[m.window], m.arSe[m.window]), tone: "blue" },61        { label: L.tstat, value: fmt(locale, m.tEvent, 2) },62        { label: L.carEnd, value: pm(m.car[last], m.carSe[last]), tone: "teal" },63        { label: L.exp, value: `${fmt(locale, m.expectedCar, 2)} %` },64        { label: L.n, value: fmtInt(locale, m.events) },65      ]} />66    </>67  );68}6970export const eventStudy: SimDef<EventStudyModel> = {71  kind: "event-study",72  title: { fr: "Étude d'événement : AR et CAR", en: "Event study: AR and CAR" },73  description: {74    fr: "Pour $N$ événements, le rendement anormal du jour $t$ est un bruit $\\mathcal{N}(0, \\sigma^2)$ auquel s'ajoutent un saut au jour 0 et une dérive quotidienne après l'événement. On trace la moyenne transversale (AR), son cumul depuis le début de la fenêtre (CAR) et une bande ± 1,96 erreur type calculée entre événements. Simplification : rendements anormaux indépendants entre titres et entre jours, sans erreur d'estimation du modèle de marché.",75    en: "For $N$ events, the abnormal return on day $t$ is $\\mathcal{N}(0, \\sigma^2)$ noise plus a jump on day 0 and a daily drift after the event. The chart shows the cross-sectional mean (AR), its cumulative sum from the start of the window (CAR) and a ± 1.96 standard-error band computed across events. Simplification: abnormal returns are independent across firms and days, with no market-model estimation error.",76  },77  params: [78    param("jump", "Saut au jour 0", "Jump on day 0", -5, 5, 0.1, 2, "%"),79    param("drift", "Dérive après l'événement", "Post-event drift", -0.5, 0.5, 0.01, 0.1, "%"),80    param("sigma", "Volatilité quotidienne σ", "Daily volatility σ", 0.5, 5, 0.1, 2, "%"),81    param("events", "Événements N", "Events N", 5, 200, 5, 50),82  ],83  stochastic: true,84  configKeys: ["window"],85  validateConfig: (c) => (c.window === undefined || (typeof c.window === "number" && Number.isInteger(c.window) && c.window >= 3 && c.window <= 20) ? [] : ["config.window: expected an integer from 3 to 20 (days on each side of the event)"]),86  compute: computeEventStudy,87  View: EventStudyView,88};89
Files main
Menu

Theme