viewof c0 = Inputs.range([0, 50], {value: 20, step: 1, label: html`autonomous consumption ${math`c_0`}`})
viewof c1 = Inputs.range([0.1, 0.95], {value: 0.7, step: 0.05, label: html`MPC ${math`c_1`}`})
viewof i0 = Inputs.range([0, 50], {value: 25, step: 1, label: html`autonomous investment ${math`i_0`}`})
viewof i1 = Inputs.range([10, 200], {value: 50, step: 5, label: html`interest sensitivity ${math`i_1`}`})
viewof G = Inputs.range([0, 100], {value: 50, step: 5, label: html`government purchases ${math`G`}`})
viewof T = Inputs.range([0, 100], {value: 30, step: 5, label: html`taxes ${math`T`}`})
viewof overlay = Inputs.select(["None", "Higher G (+20)", "Lower T (-15)", "Investment shock (i0 -15)"], {value: "None", label: "overlay shift"})
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) ---
mpc = Math.min(Math.max(c1, 0.01), 0.99) // clip MPC to (0, 1)
A0 = c0 - mpc * T + i0 + G // autonomous expenditure
multiplier = 1 / (1 - mpc) // Keynesian multiplier
isData = {
const pts = [];
for (let j = 0; j < 200; j++) {
const r = 0.25 * j / 199; // r from 0% to 25%
pts.push({Y: multiplier * (A0 - i1 * r), r: r * 100});
}
return pts;
}
A0shift = overlay === "Higher G (+20)" ? A0 + 20
: overlay === "Lower T (-15)" ? A0 + mpc * 15
: overlay === "Investment shock (i0 -15)" ? A0 - 15
: null
shiftData = {
if (A0shift === null) return null;
const pts = [];
for (let j = 0; j < 200; j++) {
const r = 0.25 * j / 199;
pts.push({Y: multiplier * (A0shift - i1 * r), r: r * 100});
}
return pts;
}
Yex = multiplier * (A0 - i1 * 0.05) // marked point at r = 5%
YexShift = A0shift === null ? null : multiplier * (A0shift - i1 * 0.05)
{
const base = pinned("is_curve_model-1", {isData, Yex}, pinA);
return mathSvg(Plot.plot({
marginLeft: 50,
x: {label: "output $Y$ →"},
y: {label: "real interest rate $r$ (%)", grid: true},
marks: [
Plot.ruleY([5], {stroke: "var(--im-sim)", strokeDasharray: "2 4", strokeOpacity: 0.6}),
Plot.line(base.isData, {x: "Y", y: "r", ...ghost}),
Plot.dot([{Y: base.Yex, r: 5}], {x: "Y", y: "r", stroke: "var(--im-fg-muted)", fill: "none", r: 4}),
...(shiftData ? [Plot.line(shiftData, {x: "Y", y: "r", stroke: "var(--im-sim)", strokeWidth: 2, strokeDasharray: "6 4"})] : []),
Plot.line(isData, {x: "Y", y: "r", stroke: "var(--im-accent)", strokeWidth: 2.5}),
Plot.dot([{Y: Yex, r: 5}], {x: "Y", y: "r", fill: "var(--im-accent)"}),
Plot.text([{Y: Yex, r: 5}], {x: "Y", y: "r", text: () => `$Y$ = ${Yex.toFixed(1)} at $r$ = 5%`, dx: 8, dy: -10, textAnchor: "start", fill: "var(--im-accent)"}),
...(YexShift !== null ? [
Plot.dot([{Y: YexShift, r: 5}], {x: "Y", y: "r", fill: "var(--im-sim)"}),
Plot.text([{Y: YexShift, r: 5}], {x: "Y", y: "r", text: () => `$Y'$ = ${YexShift.toFixed(1)}`, dx: 8, dy: 12, textAnchor: "start", fill: "var(--im-sim)"})
] : [])
]
}));
}