indiasim 0.1.0__tar.gz
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.
- indiasim-0.1.0/.gitignore +5 -0
- indiasim-0.1.0/LICENSE +21 -0
- indiasim-0.1.0/PKG-INFO +115 -0
- indiasim-0.1.0/README.md +94 -0
- indiasim-0.1.0/examples/make_quickstart.py +69 -0
- indiasim-0.1.0/examples/quickstart.ipynb +881 -0
- indiasim-0.1.0/pyproject.toml +30 -0
- indiasim-0.1.0/src/indiasim/__init__.py +19 -0
- indiasim-0.1.0/src/indiasim/_bridge.py +100 -0
- indiasim-0.1.0/src/indiasim/core.py +371 -0
- indiasim-0.1.0/src/indiasim/data/engine.js +709 -0
- indiasim-0.1.0/src/indiasim/data/india-data.json +276 -0
- indiasim-0.1.0/src/indiasim/data/moments.js +62 -0
- indiasim-0.1.0/src/indiasim/data/targets.json +89 -0
- indiasim-0.1.0/sync_engine.py +15 -0
- indiasim-0.1.0/tests/test_indiasim.py +128 -0
indiasim-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dr Sulaxan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
indiasim-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: indiasim
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Agent-based simulator of the Indian economy (Economy Lab), calibrated to RBI, MoSPI and PLFS data
|
|
5
|
+
Project-URL: Homepage, https://slxnjdhv.github.io/india-economy-simulator/
|
|
6
|
+
Project-URL: Source, https://github.com/slxnjdhv/india-economy-simulator
|
|
7
|
+
Author: Dr Sulaxan
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Intended Audience :: Education
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Requires-Dist: mini-racer>=0.12
|
|
16
|
+
Requires-Dist: numpy>=1.22
|
|
17
|
+
Requires-Dist: pandas>=1.5
|
|
18
|
+
Provides-Extra: test
|
|
19
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# indiasim
|
|
23
|
+
|
|
24
|
+
**indiasim** is the Python package for the Economy Lab: an agent-based model of the Indian economy, calibrated to RBI, MoSPI and PLFS data. It runs the same engine as the [website](https://slxnjdhv.github.io/india-economy-simulator/). The same economy number gives identical results in Python, Node.js and the browser, matching to the last digit.
|
|
25
|
+
|
|
26
|
+
The model has:
|
|
27
|
+
- 1,000 households and 100 firms (food and non-food, formal and informal);
|
|
28
|
+
- a banking sector, moneylenders, the government (wage tax and GST) and the RBI;
|
|
29
|
+
- the rest of the world: imported inputs such as oil, exports and a floating rupee.
|
|
30
|
+
|
|
31
|
+
The accounts are checked every month.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install "git+https://github.com/slxnjdhv/india-economy-simulator#subdirectory=python"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
It needs Python 3.9 or later. Dependencies are installed automatically: `mini-racer` (an embedded V8 JavaScript engine), `numpy` and `pandas`. Node.js is not needed.
|
|
40
|
+
|
|
41
|
+
## Quick start
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import indiasim as isim
|
|
45
|
+
|
|
46
|
+
# One economy, 3 years, a failed monsoon in month 4, the RBI following its usual rule
|
|
47
|
+
df = isim.run(months=36, shocks=["monsoon"])
|
|
48
|
+
df[["infl", "foodInfl", "coreInfl", "u", "repo", "inr_per_usd"]].plot(subplots=True)
|
|
49
|
+
|
|
50
|
+
# The same experiment on 100 economies with different luck, in parallel
|
|
51
|
+
many = isim.run_many(seeds=range(1, 101), shocks=["monsoon"])
|
|
52
|
+
many.groupby("month")["infl"].describe()
|
|
53
|
+
|
|
54
|
+
# Vary one setting: hold the repo rate 1 point lower, unchanged, 1 and 2 points higher
|
|
55
|
+
sw = isim.sweep("repoDelta", [-0.01, 0, 0.01, 0.02], seeds=range(1, 41))
|
|
56
|
+
sw[sw.month > 12].groupby("repoDelta")[["infl", "u"]].mean()
|
|
57
|
+
|
|
58
|
+
# How well does the model match India? (calibration statistics, 2015–2024)
|
|
59
|
+
isim.moments()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## What you can do
|
|
63
|
+
|
|
64
|
+
| Function | What it does |
|
|
65
|
+
|---|---|
|
|
66
|
+
| `run(months, seed, policy=, shocks=, params=, params_after=)` | One economy. Returns a monthly DataFrame. |
|
|
67
|
+
| `run_many(seeds, months, ...)` | Many economies in parallel. Returns a long DataFrame with a `seed` column. |
|
|
68
|
+
| `sweep(setting, values, seeds, ...)` | Varies one setting or policy lever across values, on the same economies. |
|
|
69
|
+
| `Economy(seed, **settings)` | Step through one economy month by month: `.warm_up()`, `.set(repo=0.07)`, `.shock("oil")`, `.run(12)`, `.history`. |
|
|
70
|
+
| `Game(scenario, seed)` | The website's policy games, with "nothing changed" and "RBI rule" comparison economies. |
|
|
71
|
+
| `moments(params=, seeds=, years=)` | Compares the model with Indian data on the calibration statistics. |
|
|
72
|
+
| `calibration_targets()`, `india_data()` | The Indian data used, with official sources. |
|
|
73
|
+
| `defaults()`, `scenarios()`, `shocks()` | Model settings, games and scripted shocks. |
|
|
74
|
+
|
|
75
|
+
**Policy.** Options for `policy=`:
|
|
76
|
+
- `"rule"`: the RBI's usual rule sets the repo rate.
|
|
77
|
+
- `"fixed"`: the repo rate stays where the warm-up left it.
|
|
78
|
+
- A dict, such as `{"repo": 0.07}`, `{"repoDelta": 0.01}`, `{"spendDelta": 0.02}` or `{"tax": 0.12}`.
|
|
79
|
+
|
|
80
|
+
**Shocks.** Scripted shocks are `"monsoon"`, `"oil"` and `"slowdown"`. You can set the timing and size, as in `{"key": "oil", "start": 2, "depth": 1.0}`, where a depth of 1.0 doubles the world oil price. Random harvest, oil-price, demand and capital-flow shocks happen every month as well. They are sized by calibration, and you can switch them off with `params={"foodSd": 0, "oilSd": 0, "demSd": 0, "erNoise": 0}`.
|
|
81
|
+
|
|
82
|
+
**Settings.** `params=` changes settings from the start of the 10-year warm-up. `params_after=` changes them only when the experiment starts. Use `params_after=` to compare otherwise identical economies.
|
|
83
|
+
|
|
84
|
+
## Output columns
|
|
85
|
+
|
|
86
|
+
Rates are fractions: 0.04 means 4%. Month 1 is the first month of the experiment, and warm-up months are numbered 0 and below.
|
|
87
|
+
|
|
88
|
+
| Column | Meaning |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `infl`, `foodInfl`, `coreInfl` | CPI, food and core inflation, year on year |
|
|
91
|
+
| `u` | Unemployment rate |
|
|
92
|
+
| `repo`, `loanRate` | RBI repo rate; bank lending rate |
|
|
93
|
+
| `piE` | Expected inflation |
|
|
94
|
+
| `Y`, `Y_index` | Real output; output index (100 = end of warm-up) |
|
|
95
|
+
| `C`, `I`, `G`, `X`, `M`, `gdp` | Consumption, investment, government, exports, imports and GDP in rupees. `*_pct_gdp0` gives each as % of starting monthly GDP. |
|
|
96
|
+
| `wage`, `realWage` | Average wage; real wage index (1 = start) |
|
|
97
|
+
| `deficit`, `defRatio`, `debtRatio` | Government deficit (rupees and % of GDP); debt as % of a year's GDP |
|
|
98
|
+
| `er`, `inr_per_usd`, `erChg`, `tradeBal` | Rupee index; ₹ per US$ (₹83 at month 0); 12-month change; trade balance, % of GDP |
|
|
99
|
+
| `infShare`, `infShareNF` | Informal share of all jobs and of non-farm jobs |
|
|
100
|
+
| `gini` | Wealth inequality |
|
|
101
|
+
| `residual`, `money`, `loans` | Accounting check (the residual is always about 0), money stock and bank loans |
|
|
102
|
+
|
|
103
|
+
`df.attrs` holds the economy number, its fingerprint, whether the accounts balanced, and the full settings used.
|
|
104
|
+
|
|
105
|
+
## Reproducibility
|
|
106
|
+
|
|
107
|
+
Every result depends only on the settings and the economy number. Fingerprints (`df.attrs["fingerprint"]`, `Economy.fingerprint`) let you confirm a run matches someone else's, or the website's.
|
|
108
|
+
|
|
109
|
+
## Citation
|
|
110
|
+
|
|
111
|
+
Dr Sulaxan, *Economy Lab: an agent-based simulator of the Indian economy* (2026). https://github.com/slxnjdhv/india-economy-simulator
|
|
112
|
+
|
|
113
|
+
## Limits
|
|
114
|
+
|
|
115
|
+
This is a calibrated teaching and research prototype, not a forecasting model. See the [calibration report](https://slxnjdhv.github.io/india-economy-simulator/prototype/calibration.html) for where it matches Indian data and where it doesn't.
|
indiasim-0.1.0/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# indiasim
|
|
2
|
+
|
|
3
|
+
**indiasim** is the Python package for the Economy Lab: an agent-based model of the Indian economy, calibrated to RBI, MoSPI and PLFS data. It runs the same engine as the [website](https://slxnjdhv.github.io/india-economy-simulator/). The same economy number gives identical results in Python, Node.js and the browser, matching to the last digit.
|
|
4
|
+
|
|
5
|
+
The model has:
|
|
6
|
+
- 1,000 households and 100 firms (food and non-food, formal and informal);
|
|
7
|
+
- a banking sector, moneylenders, the government (wage tax and GST) and the RBI;
|
|
8
|
+
- the rest of the world: imported inputs such as oil, exports and a floating rupee.
|
|
9
|
+
|
|
10
|
+
The accounts are checked every month.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install "git+https://github.com/slxnjdhv/india-economy-simulator#subdirectory=python"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
It needs Python 3.9 or later. Dependencies are installed automatically: `mini-racer` (an embedded V8 JavaScript engine), `numpy` and `pandas`. Node.js is not needed.
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
import indiasim as isim
|
|
24
|
+
|
|
25
|
+
# One economy, 3 years, a failed monsoon in month 4, the RBI following its usual rule
|
|
26
|
+
df = isim.run(months=36, shocks=["monsoon"])
|
|
27
|
+
df[["infl", "foodInfl", "coreInfl", "u", "repo", "inr_per_usd"]].plot(subplots=True)
|
|
28
|
+
|
|
29
|
+
# The same experiment on 100 economies with different luck, in parallel
|
|
30
|
+
many = isim.run_many(seeds=range(1, 101), shocks=["monsoon"])
|
|
31
|
+
many.groupby("month")["infl"].describe()
|
|
32
|
+
|
|
33
|
+
# Vary one setting: hold the repo rate 1 point lower, unchanged, 1 and 2 points higher
|
|
34
|
+
sw = isim.sweep("repoDelta", [-0.01, 0, 0.01, 0.02], seeds=range(1, 41))
|
|
35
|
+
sw[sw.month > 12].groupby("repoDelta")[["infl", "u"]].mean()
|
|
36
|
+
|
|
37
|
+
# How well does the model match India? (calibration statistics, 2015–2024)
|
|
38
|
+
isim.moments()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## What you can do
|
|
42
|
+
|
|
43
|
+
| Function | What it does |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `run(months, seed, policy=, shocks=, params=, params_after=)` | One economy. Returns a monthly DataFrame. |
|
|
46
|
+
| `run_many(seeds, months, ...)` | Many economies in parallel. Returns a long DataFrame with a `seed` column. |
|
|
47
|
+
| `sweep(setting, values, seeds, ...)` | Varies one setting or policy lever across values, on the same economies. |
|
|
48
|
+
| `Economy(seed, **settings)` | Step through one economy month by month: `.warm_up()`, `.set(repo=0.07)`, `.shock("oil")`, `.run(12)`, `.history`. |
|
|
49
|
+
| `Game(scenario, seed)` | The website's policy games, with "nothing changed" and "RBI rule" comparison economies. |
|
|
50
|
+
| `moments(params=, seeds=, years=)` | Compares the model with Indian data on the calibration statistics. |
|
|
51
|
+
| `calibration_targets()`, `india_data()` | The Indian data used, with official sources. |
|
|
52
|
+
| `defaults()`, `scenarios()`, `shocks()` | Model settings, games and scripted shocks. |
|
|
53
|
+
|
|
54
|
+
**Policy.** Options for `policy=`:
|
|
55
|
+
- `"rule"`: the RBI's usual rule sets the repo rate.
|
|
56
|
+
- `"fixed"`: the repo rate stays where the warm-up left it.
|
|
57
|
+
- A dict, such as `{"repo": 0.07}`, `{"repoDelta": 0.01}`, `{"spendDelta": 0.02}` or `{"tax": 0.12}`.
|
|
58
|
+
|
|
59
|
+
**Shocks.** Scripted shocks are `"monsoon"`, `"oil"` and `"slowdown"`. You can set the timing and size, as in `{"key": "oil", "start": 2, "depth": 1.0}`, where a depth of 1.0 doubles the world oil price. Random harvest, oil-price, demand and capital-flow shocks happen every month as well. They are sized by calibration, and you can switch them off with `params={"foodSd": 0, "oilSd": 0, "demSd": 0, "erNoise": 0}`.
|
|
60
|
+
|
|
61
|
+
**Settings.** `params=` changes settings from the start of the 10-year warm-up. `params_after=` changes them only when the experiment starts. Use `params_after=` to compare otherwise identical economies.
|
|
62
|
+
|
|
63
|
+
## Output columns
|
|
64
|
+
|
|
65
|
+
Rates are fractions: 0.04 means 4%. Month 1 is the first month of the experiment, and warm-up months are numbered 0 and below.
|
|
66
|
+
|
|
67
|
+
| Column | Meaning |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `infl`, `foodInfl`, `coreInfl` | CPI, food and core inflation, year on year |
|
|
70
|
+
| `u` | Unemployment rate |
|
|
71
|
+
| `repo`, `loanRate` | RBI repo rate; bank lending rate |
|
|
72
|
+
| `piE` | Expected inflation |
|
|
73
|
+
| `Y`, `Y_index` | Real output; output index (100 = end of warm-up) |
|
|
74
|
+
| `C`, `I`, `G`, `X`, `M`, `gdp` | Consumption, investment, government, exports, imports and GDP in rupees. `*_pct_gdp0` gives each as % of starting monthly GDP. |
|
|
75
|
+
| `wage`, `realWage` | Average wage; real wage index (1 = start) |
|
|
76
|
+
| `deficit`, `defRatio`, `debtRatio` | Government deficit (rupees and % of GDP); debt as % of a year's GDP |
|
|
77
|
+
| `er`, `inr_per_usd`, `erChg`, `tradeBal` | Rupee index; ₹ per US$ (₹83 at month 0); 12-month change; trade balance, % of GDP |
|
|
78
|
+
| `infShare`, `infShareNF` | Informal share of all jobs and of non-farm jobs |
|
|
79
|
+
| `gini` | Wealth inequality |
|
|
80
|
+
| `residual`, `money`, `loans` | Accounting check (the residual is always about 0), money stock and bank loans |
|
|
81
|
+
|
|
82
|
+
`df.attrs` holds the economy number, its fingerprint, whether the accounts balanced, and the full settings used.
|
|
83
|
+
|
|
84
|
+
## Reproducibility
|
|
85
|
+
|
|
86
|
+
Every result depends only on the settings and the economy number. Fingerprints (`df.attrs["fingerprint"]`, `Economy.fingerprint`) let you confirm a run matches someone else's, or the website's.
|
|
87
|
+
|
|
88
|
+
## Citation
|
|
89
|
+
|
|
90
|
+
Dr Sulaxan, *Economy Lab: an agent-based simulator of the Indian economy* (2026). https://github.com/slxnjdhv/india-economy-simulator
|
|
91
|
+
|
|
92
|
+
## Limits
|
|
93
|
+
|
|
94
|
+
This is a calibrated teaching and research prototype, not a forecasting model. See the [calibration report](https://slxnjdhv.github.io/india-economy-simulator/prototype/calibration.html) for where it matches Indian data and where it doesn't.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Build and run examples/quickstart.ipynb (so the notebook on GitHub shows real outputs).
|
|
2
|
+
|
|
3
|
+
Run: python examples/make_quickstart.py (needs nbformat, nbclient, ipykernel, matplotlib)
|
|
4
|
+
"""
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import nbformat as nbf
|
|
8
|
+
from nbclient import NotebookClient
|
|
9
|
+
|
|
10
|
+
md, code = nbf.v4.new_markdown_cell, nbf.v4.new_code_cell
|
|
11
|
+
cells = [
|
|
12
|
+
md("# indiasim quick start\n\nThe Economy Lab model of the Indian economy, run from Python. It runs the same engine as the "
|
|
13
|
+
"[website](https://slxnjdhv.github.io/india-economy-simulator/), calibrated to RBI, MoSPI and PLFS data for 2015–2024.\n\n"
|
|
14
|
+
"Install: `pip install \"git+https://github.com/slxnjdhv/india-economy-simulator#subdirectory=python\"`"),
|
|
15
|
+
code("import indiasim as isim\nimport matplotlib.pyplot as plt\nimport pandas as pd\n\npd.set_option('display.precision', 3)\nisim.__version__"),
|
|
16
|
+
md("## 1. One economy: a failed monsoon\n\nEach run first warms the economy up for 10 years. The monsoon then fails in month 4, and the RBI follows its usual rule. "
|
|
17
|
+
"Rates are fractions, so 0.04 means 4%."),
|
|
18
|
+
code("df = isim.run(months=36, shocks=['monsoon'])\n"
|
|
19
|
+
"ax = (100 * df[['infl', 'foodInfl', 'coreInfl']]).plot(figsize=(8, 3.5), title='Inflation, % year on year')\n"
|
|
20
|
+
"ax.axhspan(2, 6, color='grey', alpha=0.1); ax.set_xlabel('month'); plt.show()\n"
|
|
21
|
+
"df[['infl', 'foodInfl', 'coreInfl', 'u', 'repo', 'inr_per_usd']].iloc[[0, 6, 12, 24, 35]]"),
|
|
22
|
+
md("## 2. The cost of lower inflation: a repo-rate sweep on 40 economies\n\nHold the repo rate between 1 point below and 2 points above its starting level for 3 years. "
|
|
23
|
+
"Every setting uses the same 40 economies, so differences come from policy, not luck."),
|
|
24
|
+
code("sw = isim.sweep('repoDelta', [-0.01, 0.0, 0.01, 0.02], seeds=range(1, 41), months=36)\n"
|
|
25
|
+
"yr23 = sw[sw.month > 12].groupby('repoDelta')[['infl', 'u']].mean() * 100\n"
|
|
26
|
+
"yr23.columns = ['inflation, %', 'unemployment, %']\nyr23"),
|
|
27
|
+
code("lo, hi = yr23.iloc[0], yr23.iloc[-1]\n"
|
|
28
|
+
"ratio = (hi['unemployment, %'] - lo['unemployment, %']) / (lo['inflation, %'] - hi['inflation, %'])\n"
|
|
29
|
+
"print(f'Sacrifice ratio: {ratio:.2f} points of unemployment per point of inflation')"),
|
|
30
|
+
md("## 3. Oil, the rupee and imported inflation\n\nWorld oil prices double in month 3. Compare 40 economies with and without the shock."),
|
|
31
|
+
code("none = isim.run_many(seeds=range(1, 41), months=36, policy='fixed')\n"
|
|
32
|
+
"oil = isim.run_many(seeds=range(1, 41), months=36, policy='fixed', shocks=[{'key': 'oil', 'start': 2, 'depth': 1.0}])\n"
|
|
33
|
+
"fig, ax = plt.subplots(1, 2, figsize=(10, 3.5))\n"
|
|
34
|
+
"for name, d in [('no shock', none), ('oil doubles', oil)]:\n"
|
|
35
|
+
" q = d.groupby('month')['inr_per_usd'].quantile([0.1, 0.5, 0.9]).unstack()\n"
|
|
36
|
+
" ax[0].plot(q.index, q[0.5], label=name); ax[0].fill_between(q.index, q[0.1], q[0.9], alpha=0.2)\n"
|
|
37
|
+
" ax[1].plot(d.groupby('month')['tradeBal'].mean() * 100, label=name)\n"
|
|
38
|
+
"ax[0].set_title('Rupees per US$ (median, 10th–90th pct)'); ax[1].set_title('Trade balance, % of GDP')\n"
|
|
39
|
+
"ax[0].legend(); plt.tight_layout(); plt.show()"),
|
|
40
|
+
md("## 4. Does a large informal sector weaken monetary policy?\n\nInformal firms borrow from moneylenders, whose rates don't follow the repo rate. "
|
|
41
|
+
"For each informal-sector size, compare a 2-point rate hike with no change, on the same 20 economies."),
|
|
42
|
+
code("rows = []\nfor inf in [0.2, 0.5, 0.75, 1.0]:\n"
|
|
43
|
+
" p = {'informal': inf}\n"
|
|
44
|
+
" base = isim.run_many(seeds=range(1, 21), months=24, policy='fixed', params=p)\n"
|
|
45
|
+
" hike = isim.run_many(seeds=range(1, 21), months=24, policy={'repoDelta': 0.02}, params=p)\n"
|
|
46
|
+
" y2 = lambda d, k: d[d.month > 12][k].mean() * 100\n"
|
|
47
|
+
" rows.append({'informal setting': inf, 'informal share of jobs, %': y2(base, 'infShare'),\n"
|
|
48
|
+
" 'fall in inflation, pts': y2(base, 'infl') - y2(hike, 'infl'),\n"
|
|
49
|
+
" 'rise in unemployment, pts': y2(hike, 'u') - y2(base, 'u')})\n"
|
|
50
|
+
"pd.DataFrame(rows).set_index('informal setting')"),
|
|
51
|
+
md("## 5. Step by step, like a policymaker"),
|
|
52
|
+
code("e = isim.Economy(seed=74).warm_up(rule=False) # repo held where the warm-up left it\n"
|
|
53
|
+
"e.run(6)\n"
|
|
54
|
+
"e.shock('monsoon')\n"
|
|
55
|
+
"e.run(4)\n"
|
|
56
|
+
"e.set(repo=0.075) # respond with a hike\n"
|
|
57
|
+
"e.run(14)\n"
|
|
58
|
+
"e.history.loc[1:, ['repo', 'infl', 'foodInfl', 'u']].iloc[::4]"),
|
|
59
|
+
md("## 6. How well does the model match India?\n\nThe calibration statistics, 2015–2024: the Indian value, the model average over 10 economies of 20 years, and the model's 10th–90th percentile range."),
|
|
60
|
+
code("isim.moments()"),
|
|
61
|
+
md("## 7. Reproducibility\n\nThe same settings and economy number always give the same result, in Python and on the website. The fingerprint identifies a run exactly."),
|
|
62
|
+
code("a = isim.run(months=36, seed=74, shocks=['monsoon'])\nb = isim.run(months=36, seed=74, shocks=['monsoon'])\n"
|
|
63
|
+
"a.attrs['fingerprint'], a.attrs['fingerprint'] == b.attrs['fingerprint'], a.attrs['balanced']"),
|
|
64
|
+
]
|
|
65
|
+
nb = nbf.v4.new_notebook(cells=cells, metadata={"kernelspec": {"name": "python3", "display_name": "Python 3", "language": "python"}})
|
|
66
|
+
out = Path(__file__).with_name("quickstart.ipynb")
|
|
67
|
+
NotebookClient(nb, timeout=600, kernel_name="python3").execute()
|
|
68
|
+
nbf.write(nb, out)
|
|
69
|
+
print("wrote", out)
|