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,860 @@
1
+ /**
2
+ * Finance & Behavioral Economics Templates
3
+ *
4
+ * Postgraduate-level templates for portfolio theory, asset pricing, and behavioral economics.
5
+ */
6
+ /**
7
+ * Efficient Frontier (Mean-Variance Portfolio)
8
+ * Markowitz portfolio optimization
9
+ */
10
+ const efficientFrontier = {
11
+ id: 'efficient_frontier',
12
+ name: 'Efficient Frontier',
13
+ description: 'Markowitz mean-variance efficient frontier showing optimal risk-return combinations.',
14
+ category: 'finance',
15
+ level: 'postgraduate',
16
+ tags: ['portfolio', 'efficient frontier', 'Markowitz', 'risk-return', 'diversification'],
17
+ parameters: {
18
+ muA: {
19
+ type: 'number',
20
+ default: 0.1,
21
+ description: 'Expected return asset A',
22
+ },
23
+ muB: {
24
+ type: 'number',
25
+ default: 0.15,
26
+ description: 'Expected return asset B',
27
+ },
28
+ sigmaA: {
29
+ type: 'number',
30
+ default: 0.15,
31
+ description: 'Std dev asset A',
32
+ },
33
+ sigmaB: {
34
+ type: 'number',
35
+ default: 0.25,
36
+ description: 'Std dev asset B',
37
+ },
38
+ rho: {
39
+ type: 'number',
40
+ default: 0.3,
41
+ description: 'Correlation between A and B',
42
+ },
43
+ rf: {
44
+ type: 'number',
45
+ default: 0.03,
46
+ description: 'Risk-free rate',
47
+ },
48
+ },
49
+ generate: (params) => {
50
+ const muA = params.muA ?? 0.1;
51
+ const muB = params.muB ?? 0.15;
52
+ const sigmaA = params.sigmaA ?? 0.15;
53
+ const sigmaB = params.sigmaB ?? 0.25;
54
+ const rho = params.rho ?? 0.3;
55
+ const rf = params.rf ?? 0.03;
56
+ return {
57
+ metadata: {
58
+ specVersion: '1.3',
59
+ title: 'Efficient Frontier',
60
+ description: 'Mean-variance portfolio optimization',
61
+ },
62
+ parameters: {
63
+ muA: { value: muA, label: 'E[R_A]', min: 0.05, max: 0.2, step: 0.01 },
64
+ muB: { value: muB, label: 'E[R_B]', min: 0.08, max: 0.25, step: 0.01 },
65
+ sigmaA: { value: sigmaA, label: 'σ_A', min: 0.1, max: 0.3, step: 0.01 },
66
+ sigmaB: { value: sigmaB, label: 'σ_B', min: 0.15, max: 0.4, step: 0.01 },
67
+ rho: { value: rho, label: 'ρ_{AB}', min: -0.5, max: 0.9, step: 0.1 },
68
+ rf: { value: rf, label: 'r_f', min: 0, max: 0.08, step: 0.01 },
69
+ // Weight in A
70
+ wA: { value: 0.5, label: 'Weight in A', min: 0, max: 1, step: 0.05 },
71
+ wB: { expression: '1 - wA', label: 'Weight in B', readonly: true },
72
+ // Portfolio return
73
+ muP: {
74
+ expression: 'wA * muA + (1 - wA) * muB',
75
+ label: 'E[R_P]',
76
+ readonly: true,
77
+ },
78
+ // Portfolio variance
79
+ varP: {
80
+ expression: 'wA^2 * sigmaA^2 + (1-wA)^2 * sigmaB^2 + 2 * wA * (1-wA) * rho * sigmaA * sigmaB',
81
+ label: 'Var(R_P)',
82
+ readonly: true,
83
+ },
84
+ // Portfolio std dev
85
+ sigmaP: {
86
+ expression: 'sqrt(varP)',
87
+ label: 'σ_P',
88
+ readonly: true,
89
+ },
90
+ // Minimum variance portfolio weight
91
+ wMVP: {
92
+ expression: '(sigmaB^2 - rho * sigmaA * sigmaB) / (sigmaA^2 + sigmaB^2 - 2 * rho * sigmaA * sigmaB)',
93
+ label: 'w_MVP',
94
+ readonly: true,
95
+ },
96
+ // MVP return and risk
97
+ muMVP: {
98
+ expression: 'wMVP * muA + (1 - wMVP) * muB',
99
+ label: 'E[R_MVP]',
100
+ readonly: true,
101
+ },
102
+ sigmaMVP: {
103
+ expression: 'sqrt(wMVP^2 * sigmaA^2 + (1-wMVP)^2 * sigmaB^2 + 2 * wMVP * (1-wMVP) * rho * sigmaA * sigmaB)',
104
+ label: 'σ_MVP',
105
+ readonly: true,
106
+ },
107
+ // Sharpe ratio
108
+ sharpeP: {
109
+ expression: '(muP - rf) / sigmaP',
110
+ label: 'Sharpe Ratio',
111
+ readonly: true,
112
+ },
113
+ },
114
+ charts: [
115
+ {
116
+ id: 'frontier',
117
+ title: 'Efficient Frontier',
118
+ xAxis: { label: 'Risk (σ)', min: 0, max: 0.35 },
119
+ yAxis: { label: 'Expected Return E[R]', min: 0, max: 0.2 },
120
+ elements: [
121
+ // Efficient frontier (parametric, approximate with hyperbola)
122
+ // sigma^2 = a + b*mu + c*mu^2
123
+ {
124
+ id: 'frontier-upper',
125
+ type: 'line',
126
+ equation: 'muMVP + (x - sigmaMVP) * (muB - muMVP) / (sigmaB - sigmaMVP)',
127
+ color: '#2563EB',
128
+ strokeWidth: 3,
129
+ label: 'Efficient Frontier',
130
+ },
131
+ // Capital Market Line (CML) from rf through tangency
132
+ {
133
+ id: 'cml',
134
+ type: 'line',
135
+ equation: 'rf + ((muB - rf) / sigmaB) * x',
136
+ color: '#16A34A',
137
+ strokeWidth: 2,
138
+ lineStyle: 'dashed',
139
+ label: 'CML',
140
+ },
141
+ // Asset A
142
+ {
143
+ id: 'assetA',
144
+ type: 'point',
145
+ x: 'sigmaA',
146
+ y: 'muA',
147
+ color: '#DC2626',
148
+ size: 10,
149
+ label: 'Asset A',
150
+ },
151
+ // Asset B
152
+ {
153
+ id: 'assetB',
154
+ type: 'point',
155
+ x: 'sigmaB',
156
+ y: 'muB',
157
+ color: '#F59E0B',
158
+ size: 10,
159
+ label: 'Asset B',
160
+ },
161
+ // Minimum variance portfolio
162
+ {
163
+ id: 'mvp',
164
+ type: 'point',
165
+ x: 'sigmaMVP',
166
+ y: 'muMVP',
167
+ color: '#7C3AED',
168
+ size: 10,
169
+ label: 'MVP',
170
+ },
171
+ // Current portfolio
172
+ {
173
+ id: 'portfolio',
174
+ type: 'point',
175
+ x: 'sigmaP',
176
+ y: 'muP',
177
+ color: '#16A34A',
178
+ size: 12,
179
+ label: 'Portfolio',
180
+ droplines: { x: true, y: true },
181
+ draggable: true,
182
+ dragConfig: {
183
+ mode: 'expression',
184
+ parameters: { expressions: { wA: '0.5 + (y - 0.125) / 0.1' } },
185
+ constraints: { bounds: { minY: 0.05, maxY: 0.2 } },
186
+ },
187
+ },
188
+ // Risk-free rate
189
+ {
190
+ id: 'rf-point',
191
+ type: 'point',
192
+ x: 0,
193
+ y: 'rf',
194
+ color: '#6B7280',
195
+ size: 8,
196
+ label: 'r_f',
197
+ },
198
+ ],
199
+ annotations: [
200
+ {
201
+ id: 'sharpe-label',
202
+ text: 'Sharpe = ${sharpeP:.2f}',
203
+ x: 'sigmaP + 0.02',
204
+ y: 'muP + 0.01',
205
+ color: '#16A34A',
206
+ },
207
+ {
208
+ id: 'correlation-label',
209
+ text: 'ρ = ${rho}',
210
+ x: 0.25,
211
+ y: 0.05,
212
+ color: '#6B7280',
213
+ },
214
+ ],
215
+ },
216
+ ],
217
+ };
218
+ },
219
+ };
220
+ /**
221
+ * CAPM - Security Market Line
222
+ * Capital Asset Pricing Model
223
+ */
224
+ const capm = {
225
+ id: 'capm',
226
+ name: 'CAPM / Security Market Line',
227
+ description: 'Capital Asset Pricing Model showing the relationship between systematic risk (beta) and expected return.',
228
+ category: 'finance',
229
+ level: 'postgraduate',
230
+ tags: ['CAPM', 'SML', 'beta', 'systematic risk', 'market premium'],
231
+ parameters: {
232
+ rf: {
233
+ type: 'number',
234
+ default: 0.03,
235
+ description: 'Risk-free rate',
236
+ },
237
+ marketReturn: {
238
+ type: 'number',
239
+ default: 0.1,
240
+ description: 'Expected market return',
241
+ },
242
+ },
243
+ generate: (params) => {
244
+ const rf = params.rf ?? 0.03;
245
+ const rm = params.marketReturn ?? 0.1;
246
+ return {
247
+ metadata: {
248
+ specVersion: '1.3',
249
+ title: 'CAPM: Security Market Line',
250
+ description: 'Expected return as function of beta',
251
+ },
252
+ parameters: {
253
+ rf: { value: rf, label: 'Risk-free Rate (r_f)', min: 0, max: 0.08, step: 0.005 },
254
+ rm: { value: rm, label: 'Market Return E[R_m]', min: 0.05, max: 0.15, step: 0.01 },
255
+ marketPremium: {
256
+ expression: 'rm - rf',
257
+ label: 'Market Premium',
258
+ readonly: true,
259
+ },
260
+ // Individual asset
261
+ beta: { value: 1.2, label: 'Asset Beta (β)', min: 0, max: 2.5, step: 0.1 },
262
+ expectedReturn: {
263
+ expression: 'rf + beta * (rm - rf)',
264
+ label: 'E[R] from CAPM',
265
+ readonly: true,
266
+ },
267
+ // Sample assets for display
268
+ actualReturn: { value: 0.14, label: 'Actual Return', min: 0, max: 0.25, step: 0.01 },
269
+ alpha: {
270
+ expression: 'actualReturn - expectedReturn',
271
+ label: 'Jensen\'s Alpha',
272
+ readonly: true,
273
+ },
274
+ },
275
+ charts: [
276
+ {
277
+ id: 'sml',
278
+ title: 'Security Market Line',
279
+ xAxis: { label: 'Beta (β)', min: 0, max: 2.5 },
280
+ yAxis: { label: 'Expected Return E[R]', min: 0, max: 0.25 },
281
+ elements: [
282
+ // Security Market Line
283
+ {
284
+ id: 'sml-line',
285
+ type: 'line',
286
+ equation: 'rf + x * (rm - rf)',
287
+ color: '#2563EB',
288
+ strokeWidth: 3,
289
+ label: 'SML',
290
+ curveLabel: { text: 'SML', x: 2.2, position: 'above' },
291
+ },
292
+ // Risk-free asset
293
+ {
294
+ id: 'rf-asset',
295
+ type: 'point',
296
+ x: 0,
297
+ y: 'rf',
298
+ color: '#16A34A',
299
+ size: 10,
300
+ label: 'T-Bill',
301
+ },
302
+ // Market portfolio
303
+ {
304
+ id: 'market',
305
+ type: 'point',
306
+ x: 1,
307
+ y: 'rm',
308
+ color: '#DC2626',
309
+ size: 12,
310
+ label: 'Market (β=1)',
311
+ droplines: { x: true, y: true },
312
+ },
313
+ // Individual asset
314
+ {
315
+ id: 'asset',
316
+ type: 'point',
317
+ x: 'beta',
318
+ y: 'expectedReturn',
319
+ color: '#F59E0B',
320
+ size: 10,
321
+ label: 'CAPM Return',
322
+ },
323
+ // Actual return (may show alpha)
324
+ {
325
+ id: 'actual',
326
+ type: 'point',
327
+ x: 'beta',
328
+ y: 'actualReturn',
329
+ color: '#7C3AED',
330
+ size: 10,
331
+ label: 'Actual',
332
+ draggable: true,
333
+ dragConfig: {
334
+ mode: 'expression',
335
+ parameters: { expressions: { beta: 'x', actualReturn: 'y' } },
336
+ constraints: { bounds: { minX: 0.1, maxX: 2.4, minY: 0.01, maxY: 0.24 } },
337
+ },
338
+ },
339
+ ],
340
+ annotations: [
341
+ {
342
+ id: 'capm-eq',
343
+ text: 'E[R] = r_f + β(E[R_m] - r_f)',
344
+ x: 0.3,
345
+ y: 0.22,
346
+ color: '#2563EB',
347
+ },
348
+ {
349
+ id: 'premium-label',
350
+ text: 'Market Premium = ${marketPremium:.1%}',
351
+ x: 1.5,
352
+ y: 0.05,
353
+ color: '#6B7280',
354
+ },
355
+ {
356
+ id: 'alpha-label',
357
+ text: 'α = ${alpha:.2%}',
358
+ x: 'beta + 0.1',
359
+ y: '(expectedReturn + actualReturn) / 2',
360
+ color: '#7C3AED',
361
+ },
362
+ ],
363
+ },
364
+ ],
365
+ };
366
+ },
367
+ };
368
+ /**
369
+ * Black-Scholes Option Pricing
370
+ * Call/Put option payoff and value
371
+ */
372
+ const blackScholes = {
373
+ id: 'black_scholes',
374
+ name: 'Black-Scholes Option Pricing',
375
+ description: 'Option pricing visualization showing payoff diagrams and the Black-Scholes price as function of stock price.',
376
+ category: 'finance',
377
+ level: 'postgraduate',
378
+ tags: ['options', 'Black-Scholes', 'derivatives', 'call', 'put', 'payoff'],
379
+ parameters: {
380
+ strike: {
381
+ type: 'number',
382
+ default: 100,
383
+ description: 'Strike price (K)',
384
+ },
385
+ premium: {
386
+ type: 'number',
387
+ default: 10,
388
+ description: 'Option premium paid',
389
+ },
390
+ optionType: {
391
+ type: 'string',
392
+ default: 'call',
393
+ description: 'Call or put option',
394
+ },
395
+ },
396
+ generate: (params) => {
397
+ const K = params.strike ?? 100;
398
+ const premium = params.premium ?? 10;
399
+ return {
400
+ metadata: {
401
+ specVersion: '1.3',
402
+ title: 'Option Payoff Diagram',
403
+ description: 'Call and put option payoffs at expiration',
404
+ },
405
+ parameters: {
406
+ K: { value: K, label: 'Strike Price (K)', min: 50, max: 150 },
407
+ premium: { value: premium, label: 'Premium', min: 1, max: 30 },
408
+ S: { value: K, label: 'Stock Price (S)', min: 50, max: 150 },
409
+ // Call payoff
410
+ callPayoff: {
411
+ expression: 'max(0, S - K)',
412
+ label: 'Call Payoff',
413
+ readonly: true,
414
+ },
415
+ // Put payoff
416
+ putPayoff: {
417
+ expression: 'max(0, K - S)',
418
+ label: 'Put Payoff',
419
+ readonly: true,
420
+ },
421
+ // Call profit
422
+ callProfit: {
423
+ expression: 'callPayoff - premium',
424
+ label: 'Call Profit',
425
+ readonly: true,
426
+ },
427
+ // Put profit
428
+ putProfit: {
429
+ expression: 'putPayoff - premium',
430
+ label: 'Put Profit',
431
+ readonly: true,
432
+ },
433
+ // Break-even
434
+ callBreakeven: {
435
+ expression: 'K + premium',
436
+ label: 'Call Break-even',
437
+ readonly: true,
438
+ },
439
+ putBreakeven: {
440
+ expression: 'K - premium',
441
+ label: 'Put Break-even',
442
+ readonly: true,
443
+ },
444
+ },
445
+ charts: [
446
+ {
447
+ id: 'payoff',
448
+ title: 'Option Payoff at Expiration',
449
+ xAxis: { label: 'Stock Price at Expiration (S_T)', min: 50, max: 150 },
450
+ yAxis: { label: 'Profit/Loss', min: -30, max: 50 },
451
+ elements: [
452
+ // Zero line
453
+ {
454
+ id: 'zero',
455
+ type: 'horizontalLine',
456
+ y: 0,
457
+ color: '#6B7280',
458
+ lineStyle: 'dashed',
459
+ strokeWidth: 1,
460
+ },
461
+ // Strike price line
462
+ {
463
+ id: 'strike',
464
+ type: 'verticalLine',
465
+ x: 'K',
466
+ color: '#6B7280',
467
+ lineStyle: 'dotted',
468
+ strokeWidth: 1,
469
+ },
470
+ // Long call profit
471
+ {
472
+ id: 'long-call',
473
+ type: 'line',
474
+ equation: 'max(0, x - K) - premium',
475
+ color: '#16A34A',
476
+ strokeWidth: 3,
477
+ label: 'Long Call',
478
+ },
479
+ // Long put profit
480
+ {
481
+ id: 'long-put',
482
+ type: 'line',
483
+ equation: 'max(0, K - x) - premium',
484
+ color: '#DC2626',
485
+ strokeWidth: 3,
486
+ label: 'Long Put',
487
+ },
488
+ // Call break-even point
489
+ {
490
+ id: 'call-be',
491
+ type: 'point',
492
+ x: 'callBreakeven',
493
+ y: 0,
494
+ color: '#16A34A',
495
+ size: 8,
496
+ label: 'Call BE',
497
+ },
498
+ // Put break-even point
499
+ {
500
+ id: 'put-be',
501
+ type: 'point',
502
+ x: 'putBreakeven',
503
+ y: 0,
504
+ color: '#DC2626',
505
+ size: 8,
506
+ label: 'Put BE',
507
+ },
508
+ // Current price indicator
509
+ {
510
+ id: 'current',
511
+ type: 'point',
512
+ x: 'S',
513
+ y: 'callProfit',
514
+ color: '#2563EB',
515
+ size: 10,
516
+ label: 'Current',
517
+ draggable: true,
518
+ dragConfig: {
519
+ mode: 'expression',
520
+ parameters: { expressions: { S: 'x' } },
521
+ constraints: { bounds: { minX: 51, maxX: 149 } },
522
+ },
523
+ },
524
+ ],
525
+ annotations: [
526
+ {
527
+ id: 'strike-label',
528
+ text: 'K = ${K}',
529
+ x: 'K + 2',
530
+ y: 40,
531
+ color: '#6B7280',
532
+ },
533
+ {
534
+ id: 'premium-label',
535
+ text: 'Premium = ${premium}',
536
+ x: 60,
537
+ y: '-premium - 3',
538
+ color: '#F59E0B',
539
+ },
540
+ {
541
+ id: 'max-loss',
542
+ text: 'Max Loss = -${premium}',
543
+ x: 60,
544
+ y: -25,
545
+ color: '#DC2626',
546
+ },
547
+ ],
548
+ },
549
+ ],
550
+ };
551
+ },
552
+ };
553
+ /**
554
+ * Prospect Theory Value Function
555
+ * Kahneman-Tversky value function
556
+ */
557
+ const prospectTheory = {
558
+ id: 'prospect_theory',
559
+ name: 'Prospect Theory',
560
+ description: 'Kahneman-Tversky value function showing loss aversion and diminishing sensitivity.',
561
+ category: 'behavioral',
562
+ level: 'postgraduate',
563
+ tags: ['prospect theory', 'behavioral', 'loss aversion', 'Kahneman', 'Tversky'],
564
+ parameters: {
565
+ alpha: {
566
+ type: 'number',
567
+ default: 0.88,
568
+ description: 'Sensitivity parameter for gains (α)',
569
+ },
570
+ beta: {
571
+ type: 'number',
572
+ default: 0.88,
573
+ description: 'Sensitivity parameter for losses (β)',
574
+ },
575
+ lambda: {
576
+ type: 'number',
577
+ default: 2.25,
578
+ description: 'Loss aversion coefficient (λ)',
579
+ },
580
+ },
581
+ generate: (params) => {
582
+ const alpha = params.alpha ?? 0.88;
583
+ const beta = params.beta ?? 0.88;
584
+ const lambda = params.lambda ?? 2.25;
585
+ return {
586
+ metadata: {
587
+ specVersion: '1.3',
588
+ title: 'Prospect Theory Value Function',
589
+ description: 'Value function with loss aversion',
590
+ },
591
+ parameters: {
592
+ alpha: { value: alpha, label: 'α (gains)', min: 0.5, max: 1, step: 0.05 },
593
+ beta: { value: beta, label: 'β (losses)', min: 0.5, max: 1, step: 0.05 },
594
+ lambda: { value: lambda, label: 'λ (loss aversion)', min: 1, max: 4, step: 0.25 },
595
+ // Reference point
596
+ ref: { value: 0, label: 'Reference Point' },
597
+ // Current outcome
598
+ x: { value: 50, label: 'Outcome (x)', min: -100, max: 100 },
599
+ // Value
600
+ value: {
601
+ expression: 'x >= 0 ? x^alpha : -lambda * (-x)^beta',
602
+ label: 'v(x)',
603
+ readonly: true,
604
+ },
605
+ // For comparison: expected utility (risk neutral)
606
+ utilityRN: {
607
+ expression: 'x',
608
+ label: 'EU (risk neutral)',
609
+ readonly: true,
610
+ },
611
+ },
612
+ charts: [
613
+ {
614
+ id: 'value',
615
+ title: 'Prospect Theory Value Function',
616
+ xAxis: { label: 'Outcome relative to reference (x)', min: -100, max: 100 },
617
+ yAxis: { label: 'Subjective Value v(x)', min: -150, max: 80 },
618
+ elements: [
619
+ // Axes
620
+ {
621
+ id: 'x-axis',
622
+ type: 'horizontalLine',
623
+ y: 0,
624
+ color: '#6B7280',
625
+ strokeWidth: 1,
626
+ },
627
+ {
628
+ id: 'y-axis',
629
+ type: 'verticalLine',
630
+ x: 0,
631
+ color: '#6B7280',
632
+ strokeWidth: 1,
633
+ },
634
+ // Value function for gains: v(x) = x^α
635
+ {
636
+ id: 'gains',
637
+ type: 'line',
638
+ equation: 'x >= 0 ? x^alpha : 0',
639
+ color: '#16A34A',
640
+ strokeWidth: 3,
641
+ label: 'Gains',
642
+ },
643
+ // Value function for losses: v(x) = -λ(-x)^β
644
+ {
645
+ id: 'losses',
646
+ type: 'line',
647
+ equation: 'x < 0 ? -lambda * (-x)^beta : 0',
648
+ color: '#DC2626',
649
+ strokeWidth: 3,
650
+ label: 'Losses',
651
+ },
652
+ // 45-degree line (risk neutral reference)
653
+ {
654
+ id: 'risk-neutral',
655
+ type: 'line',
656
+ equation: 'x',
657
+ color: '#A5B4FC',
658
+ lineStyle: 'dotted',
659
+ strokeWidth: 1,
660
+ label: 'Risk Neutral',
661
+ },
662
+ // Current point
663
+ {
664
+ id: 'current',
665
+ type: 'point',
666
+ x: 'x',
667
+ y: 'value',
668
+ color: '#7C3AED',
669
+ size: 10,
670
+ label: 'Current',
671
+ draggable: true,
672
+ dragConfig: {
673
+ mode: 'expression',
674
+ parameters: { expressions: { x: 'x' } },
675
+ constraints: { bounds: { minX: -99, maxX: 99 } },
676
+ },
677
+ },
678
+ ],
679
+ annotations: [
680
+ {
681
+ id: 'gains-label',
682
+ text: 'v(x) = x^α for x ≥ 0',
683
+ x: 60,
684
+ y: 60,
685
+ color: '#16A34A',
686
+ },
687
+ {
688
+ id: 'losses-label',
689
+ text: 'v(x) = -λ|x|^β for x < 0',
690
+ x: -80,
691
+ y: -80,
692
+ color: '#DC2626',
693
+ },
694
+ {
695
+ id: 'lambda-label',
696
+ text: 'λ = ${lambda} (loss aversion)',
697
+ x: -80,
698
+ y: 60,
699
+ color: '#6B7280',
700
+ },
701
+ {
702
+ id: 'steeper-note',
703
+ text: 'Losses loom larger than gains',
704
+ x: -80,
705
+ y: 40,
706
+ color: '#7C3AED',
707
+ },
708
+ ],
709
+ },
710
+ ],
711
+ };
712
+ },
713
+ };
714
+ /**
715
+ * Hyperbolic Discounting
716
+ * Present bias and time inconsistency
717
+ */
718
+ const hyperbolicDiscounting = {
719
+ id: 'hyperbolic_discounting',
720
+ name: 'Hyperbolic Discounting',
721
+ description: 'Shows time-inconsistent preferences with β-δ (quasi-hyperbolic) discounting vs exponential.',
722
+ category: 'behavioral',
723
+ level: 'postgraduate',
724
+ tags: ['discounting', 'hyperbolic', 'present bias', 'time inconsistency', 'behavioral'],
725
+ parameters: {
726
+ beta: {
727
+ type: 'number',
728
+ default: 0.7,
729
+ description: 'Present bias parameter (β)',
730
+ },
731
+ delta: {
732
+ type: 'number',
733
+ default: 0.95,
734
+ description: 'Exponential discount factor (δ)',
735
+ },
736
+ },
737
+ generate: (params) => {
738
+ const beta = params.beta ?? 0.7;
739
+ const delta = params.delta ?? 0.95;
740
+ return {
741
+ metadata: {
742
+ specVersion: '1.3',
743
+ title: 'Hyperbolic Discounting',
744
+ description: 'Present bias vs exponential discounting',
745
+ },
746
+ parameters: {
747
+ beta: { value: beta, label: 'β (present bias)', min: 0.3, max: 1, step: 0.05 },
748
+ delta: { value: delta, label: 'δ (per-period)', min: 0.8, max: 0.99, step: 0.01 },
749
+ // Time period
750
+ t: { value: 5, label: 'Period (t)', min: 0, max: 20 },
751
+ // Exponential discount factor
752
+ expDiscount: {
753
+ expression: 'delta^t',
754
+ label: 'Exp. Discount',
755
+ readonly: true,
756
+ },
757
+ // Quasi-hyperbolic (β-δ) discount factor
758
+ hypDiscount: {
759
+ expression: 't == 0 ? 1 : beta * delta^t',
760
+ label: 'Hyp. Discount',
761
+ readonly: true,
762
+ },
763
+ // Effective annual rate implied
764
+ expRate: {
765
+ expression: '1 / delta - 1',
766
+ label: 'Exp. Rate',
767
+ readonly: true,
768
+ },
769
+ },
770
+ charts: [
771
+ {
772
+ id: 'discount',
773
+ title: 'Discount Factors Over Time',
774
+ xAxis: { label: 'Time Period (t)', min: 0, max: 20 },
775
+ yAxis: { label: 'Discount Factor D(t)', min: 0, max: 1.1 },
776
+ elements: [
777
+ // Exponential discounting
778
+ {
779
+ id: 'exponential',
780
+ type: 'line',
781
+ equation: 'delta^x',
782
+ color: '#2563EB',
783
+ strokeWidth: 3,
784
+ label: 'Exponential',
785
+ curveLabel: { text: 'δ^t', x: 15, position: 'above' },
786
+ },
787
+ // Quasi-hyperbolic (β-δ)
788
+ {
789
+ id: 'hyperbolic',
790
+ type: 'line',
791
+ equation: 'x == 0 ? 1 : beta * delta^x',
792
+ color: '#DC2626',
793
+ strokeWidth: 3,
794
+ label: 'Quasi-Hyperbolic',
795
+ curveLabel: { text: 'βδ^t', x: 15, position: 'below' },
796
+ },
797
+ // Immediate drop at t=1
798
+ {
799
+ id: 'drop',
800
+ type: 'point',
801
+ x: 1,
802
+ y: 'beta * delta',
803
+ color: '#DC2626',
804
+ size: 10,
805
+ label: 'Present Bias',
806
+ },
807
+ // Current period
808
+ {
809
+ id: 'current',
810
+ type: 'point',
811
+ x: 't',
812
+ y: 'hypDiscount',
813
+ color: '#F59E0B',
814
+ size: 10,
815
+ label: 'D(t)',
816
+ droplines: { x: true, y: true },
817
+ draggable: true,
818
+ dragConfig: {
819
+ mode: 'expression',
820
+ parameters: { expressions: { t: 'round(x)' } },
821
+ constraints: { bounds: { minX: 0, maxX: 20 } },
822
+ },
823
+ },
824
+ ],
825
+ annotations: [
826
+ {
827
+ id: 'beta-label',
828
+ text: 'β = ${beta} (present bias)',
829
+ x: 10,
830
+ y: 0.95,
831
+ color: '#DC2626',
832
+ },
833
+ {
834
+ id: 'immediate-drop',
835
+ text: 'Immediate drop to ${beta * delta:.2f}',
836
+ x: 3,
837
+ y: 'beta * delta + 0.1',
838
+ color: '#DC2626',
839
+ },
840
+ {
841
+ id: 'consistent-note',
842
+ text: 'Exponential: time-consistent',
843
+ x: 10,
844
+ y: 'delta^10 + 0.1',
845
+ color: '#2563EB',
846
+ },
847
+ ],
848
+ },
849
+ ],
850
+ };
851
+ },
852
+ };
853
+ export const financeBehavioralTemplates = [
854
+ efficientFrontier,
855
+ capm,
856
+ blackScholes,
857
+ prospectTheory,
858
+ hyperbolicDiscounting,
859
+ ];
860
+ //# sourceMappingURL=financeBehavioral.js.map