Внешний инструмент VAR на PythonPython

Программы на Python
Anonymous
Внешний инструмент VAR на Python

Сообщение Anonymous »

Я пытаюсь воспроизвести модель VAR внешнего инструмента Gertler-Karadi 2015 в Python. У меня проблемы с функциями. Он не принимает значения и не выдает ошибок.
Я пытался отладить, но все равно это не сработало. Я подумал, возможно, данные нуждаются в масштабировании или нормализации, но могу ошибаться.
# Define variables (based on your data)
num_impulses = 40 # number of periods
# based on the given matrices
col_names = ['IP', 'HICP', 'de1y', 'eurostoxx50', 'bbb_spread'] # example column names

# Initialize the impulse response storage
irs = np.zeros([num_lags + num_impulses, num_vars])
# Set initial impulse response (based on the third column of A0)
irs[num_lags, :] = A0[:, 2] # Correctly initializing with the third column of A0

# Iterate to calculate the impulse responses
for jj in range(1, num_impulses):
# Extract lagged values for the current impulse response calculation
lvars = irs[np.arange(start=num_lags + jj - 1, stop=jj - 1, step=-1), :].T
# Compute the next row of the impulse response
irs[num_lags + jj, :] = lvars.flatten().T@ Bhat # Ensure correct dimensions and transpose Bhat

# Slice the relevant impulse response values
irs = irs[num_lags:num_lags + num_impulses, :]

# Convert to DataFrame
irf_chol = pd.DataFrame(irs, columns=col_names)
print(irf_chol.head())

Результат просто потрясающий
IP HICP de1y eurostoxx50 bbb_spread
0 0.000000 0.000000 1.000000 0.412065 -0.355296
1 -0.025553 -0.009461 -0.560410 -1.062703 6.280475
2 0.692767 -0.093960 -20.098512 4.914833 16.835246
3 0.342356 0.788316 91.130221 56.952628 -616.248000
4 -47.819026 0.379773 755.920970 -438.207420 647.235308


Подробнее здесь: https://stackoverflow.com/questions/785 ... -in-python

Вернуться в «Python»