# ============================================ # 關稅衝擊 + 投入產出 (Leontief) 經濟連鎖效應 模型 > [] 關稅衝擊 + 投入產出 (Leontief) 經濟連鎖效應 模型# 作者:風海自知命 # ============================================ import numpy as np import pandas as pd import matplotlib.pyplot as plt # ======== 模型參數 ======== # 技術係數矩陣 A (3產業toy示例,可自行替換為真實IO表數據) A = np.array([ [0.2, 0.1, 0.0], [0.05, 0.3, 0.1], [0.0, 0.05, 0.25] ]) # 初始出口額 (sector0: 100, sector1: 50, sector2: 30) export_values = np.array([100.0, 50.0, 30.0]) # 關稅檔位 (百分比) tariff_rates = np.array([0.10, 0.15, 0.20, 0.25, 0.30, 0.35]) # 彈性情境 (低 / 中 / 高) elasticities = [-0.8, -1.5, -2.5] # ======== Leontief 逆矩陣 ======== I = np.eye(len(A)) L = np.linalg.inv(I - A) # Leontief inverse # ======== 計算函數 ======== def calc_impact(tariff, elasticity, sector=0): """ tariff: 關稅 (小數) elasticity: 貿易彈性 (負值) sector: 出口衝擊發生在哪個產業 """ # 出口下降百分比 delta_percent = elasticity * tariff # 出口下降金額 delta_export = np.zeros(len(export_values)) delta_export[sector] = export_values[sector] * delta_percent # 最終需求變動 delta_x = L.dot(delta_export) return delta_percent*100, delta_x, delta_x.sum() # ======== 計算所有情境 ======== results = [] for e in elasticities: for t in tariff_rates: pct, dx_vec, dx_sum = calc_impact(t, e, sector=0) results.append({ "Elasticity": e, "TariffRate": f"{int(t*100)}%", "ExportChange(%)": round(pct, 2), "Sector0": round(dx_vec[0], 2), "Sector1": round(dx_vec[1], 2), "Sector2": round(dx_vec[2], 2), "TotalOutputChange": round(dx_sum, 2) }) df = pd.DataFrame(results) # ======== 顯示結果表 ======== print("=== 關稅衝擊與經濟連鎖效應(Toy IO 模型) ===") print(df) # ======== 繪圖 ======== fig, ax = plt.subplots(figsize=(8,6)) for e in elasticities: subset = df[df["Elasticity"] == e] ax.plot(subset["TariffRate"], subset["TotalOutputChange"], marker='o', label=f"Elasticity={e}") ax.set_xlabel("Tariff Rate") ax.set_ylabel("Total Output Change") ax.set_title("Tariff Impact on Total Output (Toy IO Model)") ax.legend() plt.grid(True) plt.show()