viewof A = Inputs.range([0.5, 3.0], {value: 1.0, step: 0.1, label: html`TFP ${math`A`}`})
viewof alpha = Inputs.range([0.10, 0.80], {value: 0.33, step: 0.01, label: html`capital share ${math`\alpha`}`})
viewof K = Inputs.range([1, 200], {value: 50, step: 1, label: html`current capital ${math`K`}`})
viewof L = Inputs.range([10, 1000], {value: 100, step: 10, label: html`labor ${math`L`} (held fixed)`})
viewof r = Inputs.range([0.00, 0.15], {value: 0.04, step: 0.005, label: html`real interest rate ${math`r`}`})
viewof delta = Inputs.range([0.00, 0.15], {value: 0.06, step: 0.005, label: html`depreciation ${math`\delta`}`})
viewof phi = Inputs.range([0, 50], {value: 10, step: 1, label: html`investment sensitivity ${math`\varphi`}`})
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) ---
userCost = r + delta
mpk = alpha * A * Math.pow(K, alpha - 1) * Math.pow(L, 1 - alpha)
q = userCost > 1e-9 ? mpk / userCost : (mpk > 0 ? Infinity : 0)
Kstar = userCost > 1e-9
? Math.pow(alpha * A * Math.pow(L, 1 - alpha) / userCost, 1 / (1 - alpha))
: NaN
netInvestment = Number.isFinite(q) ? phi * Math.max(0, q - 1) : NaN
grossInvestment = Number.isFinite(netInvestment) ? netInvestment + delta * K : NaN
responseCurve = {
const qMax = Number.isFinite(q) ? Math.max(2.0, q * 1.2) : 2.0;
const pts = [];
const N = 100;
for (let i = 0; i < N; i++) {
const qv = (qMax * i) / (N - 1);
pts.push({q: qv, I: phi * Math.max(0, qv - 1)});
}
return pts;
}
signal = !Number.isFinite(q)
? html`${math`q`} undefined (user cost is zero)`
: Math.abs(q - 1) < 0.005
? html`indifferent: ${math`q \approx 1`}, ${math`K \approx K^*`} = ${Kstar.toFixed(1)}`
: q > 1
? html`invest: ${math`q`} = ${q.toFixed(2)} > 1, ${math`K < K^*`} = ${Kstar.toFixed(1)}`
: html`no net investment: ${math`q`} = ${q.toFixed(2)} < 1, ${math`K > K^*`} = ${Kstar.toFixed(1)}`
{
const base = pinned("tobin_q_model-1", tobinRun, pinA);
return mathSvg(Plot.plot({
marginLeft: 55,
x: {label: "marginal $q = MPK / (r + \\delta)$"},
y: {label: "net investment $I_{net} = \\varphi \\cdot \\max(0, q - 1)$", grid: true},
marks: [
Plot.line(base.responseCurve, {x: "q", y: "I", ...ghost}),
...(Number.isFinite(base.q) ? [
Plot.dot([{q: base.q, I: base.netInvestment}], {x: "q", y: "I", fill: "var(--im-fg-muted)", fillOpacity: 0.5, r: 5}),
Plot.text([{q: base.q, I: base.netInvestment}],
{x: "q", y: "I", text: () => "comparison", dy: 14, fill: "var(--im-fg-muted)"})
] : []),
Plot.ruleY([0], {stroke: "currentColor", strokeOpacity: 0.4}),
Plot.ruleX([1], {stroke: "var(--im-sim)", strokeDasharray: "4 4", strokeWidth: 1.5}),
Plot.text([{q: 1, I: phi > 0 ? phi * Math.max(1.0, (Number.isFinite(q) ? Math.max(2.0, q * 1.2) : 2.0) - 1) * 0.9 : 1}],
{x: "q", y: "I", text: () => "$q = 1$ threshold", fill: "var(--im-sim)", dx: 6, textAnchor: "start"}),
Plot.line(responseCurve, {x: "q", y: "I", stroke: "var(--im-accent)", strokeWidth: 2}),
...(Number.isFinite(q) ? [
Plot.dot([{q, I: netInvestment}], {x: "q", y: "I", fill: "var(--im-accent)", r: 5}),
Plot.text([{q, I: netInvestment}],
{x: "q", y: "I", text: () => `current $q$ = ${q.toFixed(2)}`, dy: -12, fill: "var(--im-accent)"})
] : [])
],
caption: html`MPK = ${mpk.toFixed(4)} · user cost ${math`r + \delta`} = ${userCost.toFixed(3)} · ${signal} · net ${math`I`} = ${Number.isFinite(netInvestment) ? netInvestment.toFixed(2) : "—"} · gross ${math`I = I_{net} + \delta K`} = ${Number.isFinite(grossInvestment) ? grossInvestment.toFixed(2) : "—"}`
}));
}