equilibria-mcp-server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/LICENSE +21 -0
  3. package/README.md +240 -0
  4. package/dist/builders/YAMLBuilder.d.ts +77 -0
  5. package/dist/builders/YAMLBuilder.d.ts.map +1 -0
  6. package/dist/builders/YAMLBuilder.js +251 -0
  7. package/dist/builders/YAMLBuilder.js.map +1 -0
  8. package/dist/economics/constants.d.ts +39 -0
  9. package/dist/economics/constants.d.ts.map +1 -0
  10. package/dist/economics/constants.js +46 -0
  11. package/dist/economics/constants.js.map +1 -0
  12. package/dist/economics/formulas.d.ts +19 -0
  13. package/dist/economics/formulas.d.ts.map +1 -0
  14. package/dist/economics/formulas.js +260 -0
  15. package/dist/economics/formulas.js.map +1 -0
  16. package/dist/economics/index.d.ts +9 -0
  17. package/dist/economics/index.d.ts.map +1 -0
  18. package/dist/economics/index.js +9 -0
  19. package/dist/economics/index.js.map +1 -0
  20. package/dist/economics/validators.d.ts +18 -0
  21. package/dist/economics/validators.d.ts.map +1 -0
  22. package/dist/economics/validators.js +111 -0
  23. package/dist/economics/validators.js.map +1 -0
  24. package/dist/errors/index.d.ts +172 -0
  25. package/dist/errors/index.d.ts.map +1 -0
  26. package/dist/errors/index.js +313 -0
  27. package/dist/errors/index.js.map +1 -0
  28. package/dist/formatters/index.d.ts +8 -0
  29. package/dist/formatters/index.d.ts.map +1 -0
  30. package/dist/formatters/index.js +8 -0
  31. package/dist/formatters/index.js.map +1 -0
  32. package/dist/formatters/redux.d.ts +15 -0
  33. package/dist/formatters/redux.d.ts.map +1 -0
  34. package/dist/formatters/redux.js +35 -0
  35. package/dist/formatters/redux.js.map +1 -0
  36. package/dist/formatters/yaml.d.ts +18 -0
  37. package/dist/formatters/yaml.d.ts.map +1 -0
  38. package/dist/formatters/yaml.js +40 -0
  39. package/dist/formatters/yaml.js.map +1 -0
  40. package/dist/index.d.ts +11 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +19 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/server.d.ts +14 -0
  45. package/dist/server.d.ts.map +1 -0
  46. package/dist/server.js +86 -0
  47. package/dist/server.js.map +1 -0
  48. package/dist/templates/advancedMicro.d.ts +8 -0
  49. package/dist/templates/advancedMicro.d.ts.map +1 -0
  50. package/dist/templates/advancedMicro.js +834 -0
  51. package/dist/templates/advancedMicro.js.map +1 -0
  52. package/dist/templates/consumer.d.ts +12 -0
  53. package/dist/templates/consumer.d.ts.map +1 -0
  54. package/dist/templates/consumer.js +1978 -0
  55. package/dist/templates/consumer.js.map +1 -0
  56. package/dist/templates/elasticity.d.ts +8 -0
  57. package/dist/templates/elasticity.d.ts.map +1 -0
  58. package/dist/templates/elasticity.js +500 -0
  59. package/dist/templates/elasticity.js.map +1 -0
  60. package/dist/templates/externalities.d.ts +11 -0
  61. package/dist/templates/externalities.d.ts.map +1 -0
  62. package/dist/templates/externalities.js +997 -0
  63. package/dist/templates/externalities.js.map +1 -0
  64. package/dist/templates/financeBehavioral.d.ts +8 -0
  65. package/dist/templates/financeBehavioral.d.ts.map +1 -0
  66. package/dist/templates/financeBehavioral.js +860 -0
  67. package/dist/templates/financeBehavioral.js.map +1 -0
  68. package/dist/templates/growth.d.ts +8 -0
  69. package/dist/templates/growth.d.ts.map +1 -0
  70. package/dist/templates/growth.js +740 -0
  71. package/dist/templates/growth.js.map +1 -0
  72. package/dist/templates/index.d.ts +31 -0
  73. package/dist/templates/index.d.ts.map +1 -0
  74. package/dist/templates/index.js +91 -0
  75. package/dist/templates/index.js.map +1 -0
  76. package/dist/templates/inequality.d.ts +8 -0
  77. package/dist/templates/inequality.d.ts.map +1 -0
  78. package/dist/templates/inequality.js +562 -0
  79. package/dist/templates/inequality.js.map +1 -0
  80. package/dist/templates/intertemporalMacro.d.ts +8 -0
  81. package/dist/templates/intertemporalMacro.d.ts.map +1 -0
  82. package/dist/templates/intertemporalMacro.js +550 -0
  83. package/dist/templates/intertemporalMacro.js.map +1 -0
  84. package/dist/templates/isLM.d.ts +8 -0
  85. package/dist/templates/isLM.d.ts.map +1 -0
  86. package/dist/templates/isLM.js +747 -0
  87. package/dist/templates/isLM.js.map +1 -0
  88. package/dist/templates/macro.d.ts +8 -0
  89. package/dist/templates/macro.d.ts.map +1 -0
  90. package/dist/templates/macro.js +600 -0
  91. package/dist/templates/macro.js.map +1 -0
  92. package/dist/templates/marketStructures.d.ts +11 -0
  93. package/dist/templates/marketStructures.d.ts.map +1 -0
  94. package/dist/templates/marketStructures.js +1135 -0
  95. package/dist/templates/marketStructures.js.map +1 -0
  96. package/dist/templates/newKeynesian.d.ts +8 -0
  97. package/dist/templates/newKeynesian.d.ts.map +1 -0
  98. package/dist/templates/newKeynesian.js +633 -0
  99. package/dist/templates/newKeynesian.js.map +1 -0
  100. package/dist/templates/oligopoly.d.ts +11 -0
  101. package/dist/templates/oligopoly.d.ts.map +1 -0
  102. package/dist/templates/oligopoly.js +1113 -0
  103. package/dist/templates/oligopoly.js.map +1 -0
  104. package/dist/templates/ppf.d.ts +8 -0
  105. package/dist/templates/ppf.d.ts.map +1 -0
  106. package/dist/templates/ppf.js +439 -0
  107. package/dist/templates/ppf.js.map +1 -0
  108. package/dist/templates/producer.d.ts +11 -0
  109. package/dist/templates/producer.d.ts.map +1 -0
  110. package/dist/templates/producer.js +979 -0
  111. package/dist/templates/producer.js.map +1 -0
  112. package/dist/templates/production.d.ts +8 -0
  113. package/dist/templates/production.d.ts.map +1 -0
  114. package/dist/templates/production.js +574 -0
  115. package/dist/templates/production.js.map +1 -0
  116. package/dist/templates/supplyDemand.d.ts +8 -0
  117. package/dist/templates/supplyDemand.d.ts.map +1 -0
  118. package/dist/templates/supplyDemand.js +1282 -0
  119. package/dist/templates/supplyDemand.js.map +1 -0
  120. package/dist/templates/tradeGrowth.d.ts +8 -0
  121. package/dist/templates/tradeGrowth.d.ts.map +1 -0
  122. package/dist/templates/tradeGrowth.js +637 -0
  123. package/dist/templates/tradeGrowth.js.map +1 -0
  124. package/dist/tools/index.d.ts +25 -0
  125. package/dist/tools/index.d.ts.map +1 -0
  126. package/dist/tools/index.js +54 -0
  127. package/dist/tools/index.js.map +1 -0
  128. package/dist/tools/models.d.ts +8 -0
  129. package/dist/tools/models.d.ts.map +1 -0
  130. package/dist/tools/models.js +828 -0
  131. package/dist/tools/models.js.map +1 -0
  132. package/dist/tools/output.d.ts +8 -0
  133. package/dist/tools/output.d.ts.map +1 -0
  134. package/dist/tools/output.js +236 -0
  135. package/dist/tools/output.js.map +1 -0
  136. package/dist/tools/templates.d.ts +8 -0
  137. package/dist/tools/templates.d.ts.map +1 -0
  138. package/dist/tools/templates.js +247 -0
  139. package/dist/tools/templates.js.map +1 -0
  140. package/dist/tools/validation.d.ts +8 -0
  141. package/dist/tools/validation.d.ts.map +1 -0
  142. package/dist/tools/validation.js +181 -0
  143. package/dist/tools/validation.js.map +1 -0
  144. package/dist/types/index.d.ts +187 -0
  145. package/dist/types/index.d.ts.map +1 -0
  146. package/dist/types/index.js +7 -0
  147. package/dist/types/index.js.map +1 -0
  148. package/dist/utils/cache.d.ts +99 -0
  149. package/dist/utils/cache.d.ts.map +1 -0
  150. package/dist/utils/cache.js +192 -0
  151. package/dist/utils/cache.js.map +1 -0
  152. package/dist/utils/index.d.ts +8 -0
  153. package/dist/utils/index.d.ts.map +1 -0
  154. package/dist/utils/index.js +8 -0
  155. package/dist/utils/index.js.map +1 -0
  156. package/dist/utils/logger.d.ts +128 -0
  157. package/dist/utils/logger.d.ts.map +1 -0
  158. package/dist/utils/logger.js +251 -0
  159. package/dist/utils/logger.js.map +1 -0
  160. package/dist/validation/index.d.ts +42 -0
  161. package/dist/validation/index.d.ts.map +1 -0
  162. package/dist/validation/index.js +282 -0
  163. package/dist/validation/index.js.map +1 -0
  164. package/package.json +73 -0
@@ -0,0 +1,834 @@
1
+ /**
2
+ * Advanced Microeconomic Theory Templates
3
+ *
4
+ * Postgraduate-level templates for general equilibrium, contract theory, and consumer theory.
5
+ */
6
+ /**
7
+ * Edgeworth Box
8
+ * General equilibrium with two consumers and two goods
9
+ */
10
+ const edgeworthBox = {
11
+ id: 'edgeworth_box',
12
+ name: 'Edgeworth Box',
13
+ description: 'Two-person, two-good exchange economy showing the contract curve and Pareto efficient allocations.',
14
+ category: 'consumer_theory',
15
+ level: 'postgraduate',
16
+ tags: ['general equilibrium', 'Edgeworth box', 'Pareto efficiency', 'exchange economy'],
17
+ parameters: {
18
+ totalX: {
19
+ type: 'number',
20
+ default: 10,
21
+ description: 'Total endowment of good X',
22
+ },
23
+ totalY: {
24
+ type: 'number',
25
+ default: 10,
26
+ description: 'Total endowment of good Y',
27
+ },
28
+ alphaA: {
29
+ type: 'number',
30
+ default: 0.5,
31
+ description: 'Consumer A preference for X (Cobb-Douglas)',
32
+ },
33
+ alphaB: {
34
+ type: 'number',
35
+ default: 0.5,
36
+ description: 'Consumer B preference for X (Cobb-Douglas)',
37
+ },
38
+ },
39
+ generate: (params) => {
40
+ const Tx = params.totalX ?? 10;
41
+ const Ty = params.totalY ?? 10;
42
+ const alphaA = params.alphaA ?? 0.5;
43
+ const alphaB = params.alphaB ?? 0.5;
44
+ return {
45
+ metadata: {
46
+ specVersion: '1.3',
47
+ title: 'Edgeworth Box',
48
+ description: 'Two-consumer exchange economy',
49
+ },
50
+ parameters: {
51
+ Tx: { value: Tx, label: 'Total X', min: 5, max: 20 },
52
+ Ty: { value: Ty, label: 'Total Y', min: 5, max: 20 },
53
+ alphaA: { value: alphaA, label: 'A preference (α)', min: 0.2, max: 0.8, step: 0.1 },
54
+ alphaB: { value: alphaB, label: 'B preference (β)', min: 0.2, max: 0.8, step: 0.1 },
55
+ // Initial endowment
56
+ omegaAx: { value: 3, label: 'A initial X' },
57
+ omegaAy: { value: 7, label: 'A initial Y' },
58
+ // B's endowment is residual
59
+ omegaBx: {
60
+ expression: 'Tx - omegaAx',
61
+ label: 'B initial X',
62
+ readonly: true,
63
+ },
64
+ omegaBy: {
65
+ expression: 'Ty - omegaAy',
66
+ label: 'B initial Y',
67
+ readonly: true,
68
+ },
69
+ // Current allocation for A
70
+ xA: { value: 5, label: 'A current X', min: 0.5, max: 9.5 },
71
+ yA: { value: 5, label: 'A current Y', min: 0.5, max: 9.5 },
72
+ // B's allocation is residual
73
+ xB: {
74
+ expression: 'Tx - xA',
75
+ label: 'B current X',
76
+ readonly: true,
77
+ },
78
+ yB: {
79
+ expression: 'Ty - yA',
80
+ label: 'B current Y',
81
+ readonly: true,
82
+ },
83
+ // MRS for each consumer
84
+ mrsA: {
85
+ expression: '(alphaA * yA) / ((1 - alphaA) * xA)',
86
+ label: 'MRS_A',
87
+ readonly: true,
88
+ },
89
+ mrsB: {
90
+ expression: '(alphaB * yB) / ((1 - alphaB) * xB)',
91
+ label: 'MRS_B',
92
+ readonly: true,
93
+ },
94
+ },
95
+ charts: [
96
+ {
97
+ id: 'box',
98
+ title: 'Edgeworth Box',
99
+ xAxis: { label: 'Good X (A origin at left)', min: 0, max: 'Tx' },
100
+ yAxis: { label: 'Good Y (A origin at bottom)', min: 0, max: 'Ty' },
101
+ elements: [
102
+ // Box boundary (right side for B's origin)
103
+ {
104
+ id: 'right-boundary',
105
+ type: 'verticalLine',
106
+ x: 'Tx',
107
+ color: '#6B7280',
108
+ strokeWidth: 2,
109
+ },
110
+ {
111
+ id: 'top-boundary',
112
+ type: 'horizontalLine',
113
+ y: 'Ty',
114
+ color: '#6B7280',
115
+ strokeWidth: 2,
116
+ },
117
+ // Contract curve (locus of tangencies)
118
+ // For Cobb-Douglas: yA = (αA(1-αB)/αB(1-αA)) * (Ty/Tx) * xA
119
+ {
120
+ id: 'contract-curve',
121
+ type: 'line',
122
+ equation: '(alphaA * (1 - alphaB) / (alphaB * (1 - alphaA))) * (Ty / Tx) * x',
123
+ color: '#16A34A',
124
+ strokeWidth: 3,
125
+ label: 'Contract Curve',
126
+ },
127
+ // A's indifference curve through current allocation
128
+ // Cobb-Douglas: yA = (uA / xA^αA)^(1/(1-αA))
129
+ {
130
+ id: 'ic-A',
131
+ type: 'line',
132
+ equation: '((xA^alphaA * yA^(1-alphaA)) / x^alphaA)^(1/(1-alphaA))',
133
+ color: '#2563EB',
134
+ strokeWidth: 2,
135
+ lineStyle: 'dashed',
136
+ label: 'IC_A',
137
+ },
138
+ // B's indifference curve (from B's origin at top-right)
139
+ // Need to invert: plot in A's coordinates
140
+ {
141
+ id: 'ic-B',
142
+ type: 'line',
143
+ equation: 'Ty - ((xB^alphaB * yB^(1-alphaB)) / (Tx - x)^alphaB)^(1/(1-alphaB))',
144
+ color: '#DC2626',
145
+ strokeWidth: 2,
146
+ lineStyle: 'dashed',
147
+ label: 'IC_B',
148
+ },
149
+ // Initial endowment
150
+ {
151
+ id: 'endowment',
152
+ type: 'point',
153
+ x: 'omegaAx',
154
+ y: 'omegaAy',
155
+ color: '#6B7280',
156
+ size: 10,
157
+ label: 'ω (Endowment)',
158
+ },
159
+ // Current allocation
160
+ {
161
+ id: 'current',
162
+ type: 'point',
163
+ x: 'xA',
164
+ y: 'yA',
165
+ color: '#7C3AED',
166
+ size: 12,
167
+ label: 'Allocation',
168
+ draggable: true,
169
+ dragConfig: {
170
+ mode: 'expression',
171
+ parameters: { expressions: { xA: 'x', yA: 'y' } },
172
+ constraints: { bounds: { minX: 0.5, maxX: 9.5, minY: 0.5, maxY: 9.5 } },
173
+ },
174
+ },
175
+ ],
176
+ annotations: [
177
+ {
178
+ id: 'A-origin',
179
+ text: 'A',
180
+ x: 0.5,
181
+ y: 0.5,
182
+ color: '#2563EB',
183
+ },
184
+ {
185
+ id: 'B-origin',
186
+ text: 'B',
187
+ x: 'Tx - 0.5',
188
+ y: 'Ty - 0.5',
189
+ color: '#DC2626',
190
+ },
191
+ {
192
+ id: 'pareto-label',
193
+ text: 'Contract Curve (Pareto Set)',
194
+ x: 'Tx * 0.6',
195
+ y: '(alphaA * (1 - alphaB) / (alphaB * (1 - alphaA))) * (Ty / Tx) * Tx * 0.6 + 0.5',
196
+ color: '#16A34A',
197
+ },
198
+ {
199
+ id: 'mrs-comparison',
200
+ text: 'MRS_A = ${mrsA:.2f}, MRS_B = ${mrsB:.2f}',
201
+ x: 'Tx * 0.5',
202
+ y: 1,
203
+ color: '#7C3AED',
204
+ },
205
+ ],
206
+ },
207
+ ],
208
+ };
209
+ },
210
+ };
211
+ /**
212
+ * Slutsky Equation Decomposition
213
+ * Income and substitution effects
214
+ */
215
+ const slutskyEquation = {
216
+ id: 'slutsky_equation',
217
+ name: 'Slutsky Decomposition',
218
+ description: 'Decomposes the total effect of a price change into substitution and income effects.',
219
+ category: 'consumer_theory',
220
+ level: 'postgraduate',
221
+ tags: ['Slutsky', 'income effect', 'substitution effect', 'consumer theory', 'demand'],
222
+ parameters: {
223
+ initialPx: {
224
+ type: 'number',
225
+ default: 2,
226
+ description: 'Initial price of X',
227
+ },
228
+ newPx: {
229
+ type: 'number',
230
+ default: 4,
231
+ description: 'New price of X',
232
+ },
233
+ income: {
234
+ type: 'number',
235
+ default: 100,
236
+ description: 'Consumer income',
237
+ },
238
+ alpha: {
239
+ type: 'number',
240
+ default: 0.5,
241
+ description: 'Preference for X (Cobb-Douglas)',
242
+ },
243
+ },
244
+ generate: (params) => {
245
+ const px0 = params.initialPx ?? 2;
246
+ const px1 = params.newPx ?? 4;
247
+ const M = params.income ?? 100;
248
+ const alpha = params.alpha ?? 0.5;
249
+ return {
250
+ metadata: {
251
+ specVersion: '1.3',
252
+ title: 'Slutsky Decomposition',
253
+ description: 'Income and substitution effects of price change',
254
+ },
255
+ parameters: {
256
+ px0: { value: px0, label: 'Initial P_X', min: 1, max: 5, step: 0.5 },
257
+ px1: { value: px1, label: 'New P_X', min: 1, max: 8, step: 0.5 },
258
+ py: { value: 1, label: 'P_Y (fixed)' },
259
+ M: { value: M, label: 'Income', min: 50, max: 200 },
260
+ alpha: { value: alpha, label: 'α', min: 0.3, max: 0.7, step: 0.05 },
261
+ // Initial optimal bundle
262
+ x0: {
263
+ expression: 'alpha * M / px0',
264
+ label: 'Initial X',
265
+ readonly: true,
266
+ },
267
+ y0: {
268
+ expression: '(1 - alpha) * M / py',
269
+ label: 'Initial Y',
270
+ readonly: true,
271
+ },
272
+ // Final optimal bundle
273
+ x1: {
274
+ expression: 'alpha * M / px1',
275
+ label: 'Final X',
276
+ readonly: true,
277
+ },
278
+ y1: {
279
+ expression: '(1 - alpha) * M / py',
280
+ label: 'Final Y',
281
+ readonly: true,
282
+ },
283
+ // Compensated income (Slutsky)
284
+ M_comp: {
285
+ expression: 'px1 * x0 + py * y0',
286
+ label: 'Compensated Income',
287
+ readonly: true,
288
+ },
289
+ // Compensated bundle (on new budget, afford old bundle)
290
+ x_comp: {
291
+ expression: 'alpha * M_comp / px1',
292
+ label: 'Compensated X',
293
+ readonly: true,
294
+ },
295
+ y_comp: {
296
+ expression: '(1 - alpha) * M_comp / py',
297
+ label: 'Compensated Y',
298
+ readonly: true,
299
+ },
300
+ // Effects
301
+ totalEffect: {
302
+ expression: 'x1 - x0',
303
+ label: 'Total Effect',
304
+ readonly: true,
305
+ },
306
+ substitutionEffect: {
307
+ expression: 'x_comp - x0',
308
+ label: 'Substitution Effect',
309
+ readonly: true,
310
+ },
311
+ incomeEffect: {
312
+ expression: 'x1 - x_comp',
313
+ label: 'Income Effect',
314
+ readonly: true,
315
+ },
316
+ },
317
+ charts: [
318
+ {
319
+ id: 'main',
320
+ title: 'Slutsky Decomposition',
321
+ xAxis: { label: 'Good X', min: 0, max: 'max(x0, M/px1) * 1.3' },
322
+ yAxis: { label: 'Good Y', min: 0, max: 'M / py * 1.3' },
323
+ elements: [
324
+ // Initial budget line
325
+ {
326
+ id: 'budget0',
327
+ type: 'line',
328
+ equation: 'M / py - (px0 / py) * x',
329
+ color: '#2563EB',
330
+ strokeWidth: 2,
331
+ label: 'Initial Budget',
332
+ curveLabel: { text: 'BL₀', x: 'M / px0 * 0.9', position: 'below' },
333
+ },
334
+ // New budget line
335
+ {
336
+ id: 'budget1',
337
+ type: 'line',
338
+ equation: 'M / py - (px1 / py) * x',
339
+ color: '#DC2626',
340
+ strokeWidth: 2,
341
+ label: 'New Budget',
342
+ curveLabel: { text: 'BL₁', x: 'M / px1 * 0.9', position: 'below' },
343
+ },
344
+ // Compensated budget line (parallel to new, through old bundle)
345
+ {
346
+ id: 'budget-comp',
347
+ type: 'line',
348
+ equation: 'M_comp / py - (px1 / py) * x',
349
+ color: '#F59E0B',
350
+ strokeWidth: 2,
351
+ lineStyle: 'dashed',
352
+ label: 'Compensated Budget',
353
+ },
354
+ // Initial indifference curve
355
+ {
356
+ id: 'ic0',
357
+ type: 'line',
358
+ equation: '((x0^alpha * y0^(1-alpha)) / x^alpha)^(1/(1-alpha))',
359
+ color: '#93C5FD',
360
+ strokeWidth: 2,
361
+ label: 'IC₀',
362
+ },
363
+ // Final indifference curve
364
+ {
365
+ id: 'ic1',
366
+ type: 'line',
367
+ equation: '((x1^alpha * y1^(1-alpha)) / x^alpha)^(1/(1-alpha))',
368
+ color: '#FCA5A5',
369
+ strokeWidth: 2,
370
+ label: 'IC₁',
371
+ },
372
+ // Initial bundle (A)
373
+ {
374
+ id: 'bundleA',
375
+ type: 'point',
376
+ x: 'x0',
377
+ y: 'y0',
378
+ color: '#2563EB',
379
+ size: 10,
380
+ label: 'A (Initial)',
381
+ },
382
+ // Compensated bundle (B)
383
+ {
384
+ id: 'bundleB',
385
+ type: 'point',
386
+ x: 'x_comp',
387
+ y: 'y_comp',
388
+ color: '#F59E0B',
389
+ size: 10,
390
+ label: 'B (Compensated)',
391
+ },
392
+ // Final bundle (C)
393
+ {
394
+ id: 'bundleC',
395
+ type: 'point',
396
+ x: 'x1',
397
+ y: 'y1',
398
+ color: '#DC2626',
399
+ size: 10,
400
+ label: 'C (Final)',
401
+ droplines: { x: true, y: true },
402
+ },
403
+ ],
404
+ annotations: [
405
+ {
406
+ id: 'sub-effect',
407
+ text: 'SE = ${substitutionEffect:.2f} (A→B)',
408
+ x: '(x0 + x_comp) / 2',
409
+ y: 'max(y0, y_comp) + 5',
410
+ color: '#F59E0B',
411
+ },
412
+ {
413
+ id: 'inc-effect',
414
+ text: 'IE = ${incomeEffect:.2f} (B→C)',
415
+ x: '(x_comp + x1) / 2',
416
+ y: 'min(y_comp, y1) - 5',
417
+ color: '#7C3AED',
418
+ },
419
+ {
420
+ id: 'total-effect',
421
+ text: 'Total = ${totalEffect:.2f}',
422
+ x: 5,
423
+ y: 'M / py * 1.1',
424
+ color: '#6B7280',
425
+ },
426
+ ],
427
+ },
428
+ ],
429
+ };
430
+ },
431
+ };
432
+ /**
433
+ * Principal-Agent Model
434
+ * Moral hazard with hidden action
435
+ */
436
+ const principalAgent = {
437
+ id: 'principal_agent',
438
+ name: 'Principal-Agent Model',
439
+ description: 'Shows optimal contracting under moral hazard with effort incentives and participation constraints.',
440
+ category: 'market_structures',
441
+ level: 'postgraduate',
442
+ tags: ['principal-agent', 'moral hazard', 'incentives', 'contract theory', 'hidden action'],
443
+ parameters: {
444
+ highOutput: {
445
+ type: 'number',
446
+ default: 100,
447
+ description: 'Output if successful (Q_H)',
448
+ },
449
+ lowOutput: {
450
+ type: 'number',
451
+ default: 20,
452
+ description: 'Output if unsuccessful (Q_L)',
453
+ },
454
+ effortCost: {
455
+ type: 'number',
456
+ default: 10,
457
+ description: 'Cost of high effort (c)',
458
+ },
459
+ probHighEffort: {
460
+ type: 'number',
461
+ default: 0.8,
462
+ description: 'P(success | high effort)',
463
+ },
464
+ probLowEffort: {
465
+ type: 'number',
466
+ default: 0.3,
467
+ description: 'P(success | low effort)',
468
+ },
469
+ reservation: {
470
+ type: 'number',
471
+ default: 5,
472
+ description: 'Agent reservation utility',
473
+ },
474
+ },
475
+ generate: (params) => {
476
+ const QH = params.highOutput ?? 100;
477
+ const QL = params.lowOutput ?? 20;
478
+ const c = params.effortCost ?? 10;
479
+ const pH = params.probHighEffort ?? 0.8;
480
+ const pL = params.probLowEffort ?? 0.3;
481
+ const uBar = params.reservation ?? 5;
482
+ return {
483
+ metadata: {
484
+ specVersion: '1.3',
485
+ title: 'Principal-Agent Problem',
486
+ description: 'Optimal incentive contract under moral hazard',
487
+ },
488
+ parameters: {
489
+ QH: { value: QH, label: 'High Output (Q_H)', min: 50, max: 200 },
490
+ QL: { value: QL, label: 'Low Output (Q_L)', min: 0, max: 50 },
491
+ c: { value: c, label: 'Effort Cost (c)', min: 1, max: 30 },
492
+ pH: { value: pH, label: 'P(H|effort)', min: 0.5, max: 0.95, step: 0.05 },
493
+ pL: { value: pL, label: 'P(H|shirk)', min: 0.1, max: 0.5, step: 0.05 },
494
+ uBar: { value: uBar, label: 'Reservation Utility', min: 0, max: 20 },
495
+ // Likelihood ratio
496
+ LR: {
497
+ expression: '(pH - pL) / pL',
498
+ label: 'Likelihood Ratio',
499
+ readonly: true,
500
+ },
501
+ // First-best wage (observable effort)
502
+ wFB: {
503
+ expression: '(uBar + c)^2',
504
+ label: 'First-Best Wage',
505
+ readonly: true,
506
+ },
507
+ // Second-best wages (sqrt utility: u = sqrt(w))
508
+ // IC: pH*sqrt(wH) + (1-pH)*sqrt(wL) - c >= pL*sqrt(wH) + (1-pL)*sqrt(wL)
509
+ // PC: pH*sqrt(wH) + (1-pH)*sqrt(wL) - c >= uBar
510
+ // Solution: sqrt(wL) = uBar + c - pH*c/(pH-pL)
511
+ // sqrt(wH) = uBar + c + (1-pH)*c/(pH-pL)
512
+ sqrtWL: {
513
+ expression: 'max(0, uBar + c - pH * c / (pH - pL))',
514
+ label: 'sqrt(w_L)',
515
+ readonly: true,
516
+ },
517
+ sqrtWH: {
518
+ expression: 'uBar + c + (1 - pH) * c / (pH - pL)',
519
+ label: 'sqrt(w_H)',
520
+ readonly: true,
521
+ },
522
+ wL: {
523
+ expression: 'sqrtWL^2',
524
+ label: 'w_L (Low output)',
525
+ readonly: true,
526
+ },
527
+ wH: {
528
+ expression: 'sqrtWH^2',
529
+ label: 'w_H (High output)',
530
+ readonly: true,
531
+ },
532
+ // Expected wage
533
+ expectedWage: {
534
+ expression: 'pH * wH + (1 - pH) * wL',
535
+ label: 'E[wage]',
536
+ readonly: true,
537
+ },
538
+ // Principal's expected profit
539
+ principalProfit: {
540
+ expression: 'pH * (QH - wH) + (1 - pH) * (QL - wL)',
541
+ label: 'E[Profit]',
542
+ readonly: true,
543
+ },
544
+ // Information rent
545
+ infoRent: {
546
+ expression: 'expectedWage - wFB',
547
+ label: 'Information Rent',
548
+ readonly: true,
549
+ },
550
+ },
551
+ charts: [
552
+ {
553
+ id: 'contract',
554
+ title: 'Optimal Contract',
555
+ xAxis: { label: 'Wage if Low Output (w_L)', min: 0, max: 'wH * 1.2' },
556
+ yAxis: { label: 'Wage if High Output (w_H)', min: 0, max: 'wH * 1.5' },
557
+ elements: [
558
+ // IC constraint: (pH-pL)(sqrt(wH) - sqrt(wL)) = c
559
+ // sqrt(wH) = sqrt(wL) + c/(pH-pL)
560
+ {
561
+ id: 'ic',
562
+ type: 'line',
563
+ equation: '(sqrt(x) + c/(pH-pL))^2',
564
+ color: '#DC2626',
565
+ strokeWidth: 2,
566
+ label: 'IC (binding)',
567
+ curveLabel: { text: 'IC', x: 'wL * 0.8', position: 'above' },
568
+ },
569
+ // PC constraint: pH*sqrt(wH) + (1-pH)*sqrt(wL) - c = uBar
570
+ // sqrt(wH) = (uBar + c - (1-pH)*sqrt(wL)) / pH
571
+ {
572
+ id: 'pc',
573
+ type: 'line',
574
+ equation: '((uBar + c - (1-pH)*sqrt(x)) / pH)^2',
575
+ color: '#2563EB',
576
+ strokeWidth: 2,
577
+ label: 'PC (binding)',
578
+ curveLabel: { text: 'PC', x: 'wL * 0.5', position: 'below' },
579
+ },
580
+ // 45-degree line (equal wages)
581
+ {
582
+ id: 'equal',
583
+ type: 'line',
584
+ equation: 'x',
585
+ color: '#6B7280',
586
+ lineStyle: 'dotted',
587
+ strokeWidth: 1,
588
+ },
589
+ // Optimal contract
590
+ {
591
+ id: 'optimal',
592
+ type: 'point',
593
+ x: 'wL',
594
+ y: 'wH',
595
+ color: '#16A34A',
596
+ size: 12,
597
+ label: 'Optimal Contract',
598
+ droplines: { x: 'w_L*', y: 'w_H*' },
599
+ },
600
+ // First-best (equal wages)
601
+ {
602
+ id: 'firstbest',
603
+ type: 'point',
604
+ x: 'wFB',
605
+ y: 'wFB',
606
+ color: '#F59E0B',
607
+ size: 10,
608
+ label: 'First Best',
609
+ },
610
+ ],
611
+ annotations: [
612
+ {
613
+ id: 'contract-values',
614
+ text: 'w_L* = ${wL:.1f}, w_H* = ${wH:.1f}',
615
+ x: 'wL + 5',
616
+ y: 'wH + 10',
617
+ color: '#16A34A',
618
+ },
619
+ {
620
+ id: 'incentive-note',
621
+ text: 'Gap = incentive for effort',
622
+ x: '(wL + wH) / 2',
623
+ y: '(wL + wH) / 2 + 20',
624
+ color: '#7C3AED',
625
+ },
626
+ {
627
+ id: 'profit-label',
628
+ text: 'E[Profit] = ${principalProfit:.1f}',
629
+ x: 5,
630
+ y: 'wH * 1.3',
631
+ color: '#6B7280',
632
+ },
633
+ ],
634
+ },
635
+ ],
636
+ };
637
+ },
638
+ };
639
+ /**
640
+ * Mechanism Design / Revelation Principle
641
+ * Simplified two-type screening model
642
+ */
643
+ const mechanismDesign = {
644
+ id: 'mechanism_design',
645
+ name: 'Mechanism Design',
646
+ description: 'Two-type screening model showing incentive-compatible mechanisms under adverse selection.',
647
+ category: 'market_structures',
648
+ level: 'postgraduate',
649
+ tags: ['mechanism design', 'adverse selection', 'screening', 'revelation principle', 'IC'],
650
+ parameters: {
651
+ thetaH: {
652
+ type: 'number',
653
+ default: 2,
654
+ description: 'High type valuation parameter',
655
+ },
656
+ thetaL: {
657
+ type: 'number',
658
+ default: 1,
659
+ description: 'Low type valuation parameter',
660
+ },
661
+ probHigh: {
662
+ type: 'number',
663
+ default: 0.5,
664
+ description: 'Probability of high type',
665
+ },
666
+ costParam: {
667
+ type: 'number',
668
+ default: 0.5,
669
+ description: 'Quadratic cost parameter',
670
+ },
671
+ },
672
+ generate: (params) => {
673
+ const tH = params.thetaH ?? 2;
674
+ const tL = params.thetaL ?? 1;
675
+ const lambda = params.probHigh ?? 0.5;
676
+ const c = params.costParam ?? 0.5;
677
+ return {
678
+ metadata: {
679
+ specVersion: '1.3',
680
+ title: 'Mechanism Design',
681
+ description: 'Optimal screening with two types',
682
+ },
683
+ parameters: {
684
+ tH: { value: tH, label: 'θ_H', min: 1.5, max: 3, step: 0.1 },
685
+ tL: { value: tL, label: 'θ_L', min: 0.5, max: 1.5, step: 0.1 },
686
+ lambda: { value: lambda, label: 'P(θ_H)', min: 0.2, max: 0.8, step: 0.1 },
687
+ c: { value: c, label: 'Cost param', min: 0.2, max: 1, step: 0.1 },
688
+ // First-best quantities: θ = c*q => q = θ/c
689
+ qFB_H: {
690
+ expression: 'tH / c',
691
+ label: 'q*_H (First Best)',
692
+ readonly: true,
693
+ },
694
+ qFB_L: {
695
+ expression: 'tL / c',
696
+ label: 'q*_L (First Best)',
697
+ readonly: true,
698
+ },
699
+ // Second-best: high type gets first-best, low type distorted down
700
+ qSB_H: {
701
+ expression: 'tH / c',
702
+ label: 'q_H (Second Best)',
703
+ readonly: true,
704
+ },
705
+ qSB_L: {
706
+ expression: 'tL / c - lambda * (tH - tL) / ((1 - lambda) * c)',
707
+ label: 'q_L (Second Best)',
708
+ readonly: true,
709
+ },
710
+ // Surplus calculations
711
+ welfareFirstBest: {
712
+ expression: 'lambda * (tH * qFB_H - 0.5 * c * qFB_H^2) + (1-lambda) * (tL * qFB_L - 0.5 * c * qFB_L^2)',
713
+ label: 'First-Best Welfare',
714
+ readonly: true,
715
+ },
716
+ informationRent: {
717
+ expression: 'lambda * (tH - tL) * max(0, qSB_L)',
718
+ label: 'Information Rent',
719
+ readonly: true,
720
+ },
721
+ },
722
+ charts: [
723
+ {
724
+ id: 'main',
725
+ title: 'Optimal Mechanism',
726
+ xAxis: { label: 'Quantity (q)', min: 0, max: 'qFB_H * 1.3' },
727
+ yAxis: { label: 'Marginal Value / Cost', min: 0, max: 'tH * 1.2' },
728
+ elements: [
729
+ // High type marginal value
730
+ {
731
+ id: 'mv-high',
732
+ type: 'horizontalLine',
733
+ y: 'tH',
734
+ color: '#2563EB',
735
+ strokeWidth: 2,
736
+ label: 'θ_H',
737
+ },
738
+ // Low type marginal value
739
+ {
740
+ id: 'mv-low',
741
+ type: 'horizontalLine',
742
+ y: 'tL',
743
+ color: '#DC2626',
744
+ strokeWidth: 2,
745
+ label: 'θ_L',
746
+ },
747
+ // Marginal cost
748
+ {
749
+ id: 'mc',
750
+ type: 'line',
751
+ equation: 'c * x',
752
+ color: '#16A34A',
753
+ strokeWidth: 2,
754
+ label: 'MC = cq',
755
+ },
756
+ // Virtual marginal value for low type
757
+ {
758
+ id: 'virtual-mv',
759
+ type: 'horizontalLine',
760
+ y: 'tL - lambda * (tH - tL) / (1 - lambda)',
761
+ color: '#F59E0B',
762
+ lineStyle: 'dashed',
763
+ strokeWidth: 2,
764
+ label: 'Virtual MV',
765
+ },
766
+ // First-best high type
767
+ {
768
+ id: 'fb-high',
769
+ type: 'point',
770
+ x: 'qFB_H',
771
+ y: 'tH',
772
+ color: '#2563EB',
773
+ size: 10,
774
+ label: 'FB_H',
775
+ droplines: { x: true, y: false },
776
+ },
777
+ // First-best low type
778
+ {
779
+ id: 'fb-low',
780
+ type: 'point',
781
+ x: 'qFB_L',
782
+ y: 'tL',
783
+ color: '#DC2626',
784
+ size: 10,
785
+ label: 'FB_L',
786
+ droplines: { x: true, y: false },
787
+ },
788
+ // Second-best low type (distorted)
789
+ {
790
+ id: 'sb-low',
791
+ type: 'point',
792
+ x: 'max(0, qSB_L)',
793
+ y: 'tL',
794
+ color: '#F59E0B',
795
+ size: 12,
796
+ label: 'SB_L',
797
+ droplines: { x: true, y: false },
798
+ },
799
+ ],
800
+ annotations: [
801
+ {
802
+ id: 'distortion',
803
+ text: 'Downward distortion',
804
+ x: '(qFB_L + max(0, qSB_L)) / 2',
805
+ y: 'tL + 0.3',
806
+ color: '#F59E0B',
807
+ },
808
+ {
809
+ id: 'no-distortion-top',
810
+ text: 'No distortion at top',
811
+ x: 'qFB_H * 0.7',
812
+ y: 'tH + 0.2',
813
+ color: '#2563EB',
814
+ },
815
+ {
816
+ id: 'rent-label',
817
+ text: 'Info rent = ${informationRent:.2f}',
818
+ x: 'qFB_H * 0.8',
819
+ y: 'tL * 0.5',
820
+ color: '#7C3AED',
821
+ },
822
+ ],
823
+ },
824
+ ],
825
+ };
826
+ },
827
+ };
828
+ export const advancedMicroTemplates = [
829
+ edgeworthBox,
830
+ slutskyEquation,
831
+ principalAgent,
832
+ mechanismDesign,
833
+ ];
834
+ //# sourceMappingURL=advancedMicro.js.map