-
Notifications
You must be signed in to change notification settings - Fork 2
/
step3.py
85 lines (64 loc) · 2.06 KB
/
step3.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# (c) 2022 - 2023 Open Risk (https://www.openriskmanagement.com)
import numpy as np
import pandas as pd
import pymrio
"""
Constructing a simple IO table that involves two economic sectors
Step 3 of the Academy Course [SFI32064](https://www.openriskacademy.com/course/view.php?id=64)
"""
# Initialize the system
io = pymrio.IOSystem()
# TWO NON-INTERACTING SECTORS WITH MULTIPLE TYPES OF DEMAND (ADDITIONAL COLUMNS OF Y)
"""
The Z matrix is initialized as a numpy array (2x2) but
stored as a pandas dataframe along an index we create
"""
Z = pd.DataFrame(
data=np.array([[1, 0], [0, 1]]),
index=["S1", "S2"],
columns=["S1", "S2"]
)
Y = pd.DataFrame(
data=np.array([[1, 0], [0, 1]]),
index=["S1", "S2"],
columns=["Y1", "Y2"]
)
"""
The fundamental equation (2.4) is effectively bootstrapped by setting the attributes of the IO system class to the corresponding matrix values via an assignment
x = Zi + Y
"""
io.Z = Z
io.Y = Y
# We are not ready 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("L Table (Leontief Inverse): \n", io.L, "\n") # L = 1 / (I - A)
del io
print(80 * '=')
# Initialize a more complex system
io = pymrio.IOSystem()
# TWO INTERACTING SECTORS
Z = pd.DataFrame(
data=np.array([[200, 100], [80, 50]]),
index=["F", "E"],
columns=["F", "E"]
)
Y = pd.DataFrame(
data=np.array([[300, 100], [200, 150]]),
index=["F", "E"],
columns=["G", "A"]
)
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("L Table (Leontief Inverse): \n", io.L, "\n") # L = 1 / (I - A)