-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstep4.py
More file actions
42 lines (30 loc) · 808 Bytes
/
step4.py
File metadata and controls
42 lines (30 loc) · 808 Bytes
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
# (c) 2022 - 2026 Open Risk (https://www.openriskmanagement.com)
import numpy as np
import pandas as pd
import pymrio
"""
Constructing the Leontief Inverse "by hand"
Step 4 of the Academy Course [SFI32064](https://www.openriskacademy.com/course/view.php?id=64)
"""
# Initialize the system (same as Step 3.2)
io = pymrio.IOSystem()
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
io.calc_all()
I = np.eye(2)
A2 = np.matmul(io.A, io.A)
A3 = np.matmul(A2, io.A)
A4 = np.matmul(A3, io.A)
L_4 = I + io.A + A2 + A3 + A4
print("4-th order approximation of Leontief Inverse\n", L_4)
print("Actual Solution\n", io.L)