-
Notifications
You must be signed in to change notification settings - Fork 3
/
step2.py
66 lines (50 loc) · 1.67 KB
/
step2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# (c) 2022 - 2024 Open Risk (https://www.openriskmanagement.com)
import numpy as np
import pandas as pd
import pymrio
"""
Constructing a very simple IO table that involves only one economic sector
Step 2 of the Academy Course [SFI32064](https://www.openriskacademy.com/course/view.php?id=64)
"""
# Initialize the system
io = pymrio.IOSystem()
# SINGLE SECTOR
Z = pd.DataFrame(
data=np.array([[1]]), # initialize with value=1
index=["S1"],
columns=["S1"]
)
Y = pd.DataFrame(
data=np.array([[2]]), # initialize with value=2
index=["S1"],
columns=["Y1"]
)
io.Z = Z
io.Y = Y
# Calculate everything that can be calculated
io.calc_all()
# Report
print("Z Table (Industry Transactions):\n", io.Z, "\n") # input
print("Y Table (Demand): \n", io.Y, "\n") # input
print("x Vector (Total Output): \n", io.x, "\n") # x = Z + Y
print("A Table (Normalized Transactions): \n", io.A, "\n") # A = Z / x
print("B Table (Normalized Transactions): \n", io.As, "\n") # B = Z / x
print("L Table (Leontief Inverse): \n", io.L, "\n") # L = 1 / (I - A)
print("G Table (Ghosh Inverse): \n", io.G, "\n") # L = 1 / (I - B)
# Recalculate everything except the coefficients
io.reset_all_to_coefficients()
# Update the final demand value
Y = pd.DataFrame(
data=np.array([[1]]),
index=["S1"],
columns=["Y1"]
)
io.Y = Y
io.calc_all()
# Report
print("Z Table (Industry Transactions):\n", io.Z, "\n") # input
print("Y Table (Demand): \n", io.Y, "\n") # input
print("x Vector (Total Output): \n", io.x, "\n") # x = Z + Y
print("A Table (Normalized Transactions): \n", io.A, "\n") # A = Z / x
print("L Table (Leontief Inverse): \n", io.L, "\n") # L = 1 / (I - A)
print(io.meta)