viewof a_ax = Inputs.range([80, 150], {value: 120, step: 5, label: html`AD intercept ${math`a`} (demand)`})
viewof b_ax = Inputs.range([1, 30], {value: 10, step: 1, label: html`AD slope ${math`b`}`})
viewof ybar_ax = Inputs.range([80, 120], {value: 100, step: 1, label: html`potential output ${math`\bar{Y}`} (supply)`})
viewof c_ax = Inputs.range([0.5, 20], {value: 8, step: 0.5, label: html`price inertia ${math`c`} (${math`\lambda = 1/c`})`})
viewof p0_ax = Inputs.range([0.5, 3.0], {value: 1.0, step: 0.05, label: html`initial price level ${math`P_0`}`})
viewof T_ax = Inputs.range([5, 50], {value: 20, step: 1, label: html`periods ${math`T`}`})
viewof pinA = Inputs.button("Pin this run for comparison")
import {pinned, ghost, math, mathSvg} from "../theme/im-sim.js"
// --- model (ported 1:1 from the v1 Python notebook) ---
// Y_t = a − b·P_t (AD); P_t = P_{t−1} + (1/c)·(Y_{t−1} − Ȳ) (price adjustment),
// with the notebook's floor P_t ≥ 0 kept intact.
// Adaptations: default c raised 5 → 8 — the v1 default (b=10, c=5) sits exactly on the
// stability boundary |1 − b/c| = 1, so the path oscillates forever without converging;
// c = 8 gives |1 − b/c| = 0.25 (damped). P₀ slider extended to 3.0 for the recession
// exercises. Everything else (equations, ranges, floor) is unchanged.
adasSim_ax = {
const lam = 1.0 / c_ax;
const Y = [], P = [];
P[0] = p0_ax;
Y[0] = a_ax - b_ax * P[0];
for (let t = 1; t < T_ax; t++) {
P[t] = Math.max(P[t - 1] + lam * (Y[t - 1] - ybar_ax), 1e-6);
Y[t] = a_ax - b_ax * P[t];
}
const rows = [];
for (let t = 0; t < T_ax; t++) rows.push({t, Y: Y[t], P: P[t]});
return rows;
}
pstar_ax = (a_ax - ybar_ax) / b_ax
adLine_ax = {
const ps = adasSim_ax.map(d => d.P).concat([pstar_ax, p0_ax]);
const lo = Math.max(Math.min(...ps) * 0.9, 0), hi = Math.max(...ps) * 1.1 + 0.1;
const pts = [];
for (let i = 0; i <= 60; i++) {
const P = lo + (hi - lo) * i / 60;
pts.push({P, Y: a_ax - b_ax * P});
}
return pts;
}
{
const base = pinned("adas_model-1", {adasSim_ax}, pinA);
return mathSvg(Plot.plot({
marginLeft: 50, height: 260,
x: {label: "time (periods) →"},
y: {grid: true, label: "output $Y$"},
marks: [
Plot.ruleY([ybar_ax], {stroke: "#9aa0a6", strokeDasharray: "4 4"}),
Plot.text([{t: T_ax - 1, Y: ybar_ax}], {x: "t", y: "Y", text: () => `$\\bar{Y}$ = ${ybar_ax}`, dy: -8, fill: "#9aa0a6", textAnchor: "end"}),
Plot.line(base.adasSim_ax, {x: "t", y: "Y", ...ghost}),
Plot.line(adasSim_ax, {x: "t", y: "Y", stroke: "var(--im-accent)", strokeWidth: 2}),
Plot.dot(adasSim_ax, {x: "t", y: "Y", r: 2.5, fill: "var(--im-accent)"})
]
}));
}