werleycordeiro/Dynamic_Nelson_Siegel_Svensson_Kalman_Filter

the error

Opened this issue · 2 comments

from Dynamic_Nelson_Siegel_Svensson_Kalman_Filter import kalman
url = 'https://www.dropbox.com/s/inpnlugzkddp42q/bonds.csv?dl=1' # US Yield Curve 1972 - 2000
df = pd.read_csv(url, sep=';', index_col=0)
print(df)
print(len(df))

mty = np.array([3, 6, 9, 12, 15, 18, 21, 24, 30, 36, 48, 60, 72, 84, 96, 108, 120]) # maturities in months
from scipy import optimize

frct = True
lik = False
ahead = 12

model = 'S'

param = np.array([-2.798522, -3.55908713, # lambdas
0.14170940, 0.07289485, 0.11492339, 0.11120008, 0.09055795, 0.07672075, 0.07222108,
0.07076431, 0.07012891, 0.07267366, 0.10624206, 0.09029621, 0.10374527, 0.09801215,
0.09122014, 0.11794190, 0.13354418, # H
0.99010443, 0.02496842, -0.002294319, 0.0000, # phi
-0.02812401, 0.94256154, 0.028699387, 0.000, # phi
0.05178493, 0.01247332, 0.788078795, 0.0000, # phi
0.00000000, 0.00000000, 0.0000000000, 0.6000, # phi
8.345444, -1.572442, 0.2029919, 2.96696726, # mu
0.3408764, -0.07882772, -0.21351036, 0.1, # Q
0.62661018, -0.00425989, 0.2, # Q
1.08802059, 0.3, # Q
0.4]) # Q

optimize.minimize(fun=kalman, x0=param, args=(df, lik, frct, ahead, mty, model), method='L-BFGS-B', bounds=None,
options={'disp': True})

When I run the program, I get the following error:
TypeError: order must be str, not int

can you help me to resolve errors
thanks

now,I get the following error:
ValueError: setting an array element with a sequence.

this is the detailed error code

ary = asanyarray(ary)
TypeError: only size-1 arrays can be converted to Python scalars

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/liuenmao/IProgram/PycharmProjects/DLMU_Project/Options_Futures_OtherDerivatives/原油市场/油价结构冲击影响研究/OilShocks_TS.py", line 311, in
main()
File "/Users/liuenmao/IProgram/PycharmProjects/DLMU_Project/Options_Futures_OtherDerivatives/原油市场/油价结构冲击影响研究/OilShocks_TS.py", line 307, in main
OilPriceShockR.run_ts()
File "/Users/liuenmao/IProgram/PycharmProjects/DLMU_Project/Options_Futures_OtherDerivatives/原油市场/油价结构冲击影响研究/OilShocks_TS.py", line 291, in run_ts
optimize.minimize(fun=kalman, x0=param, args=(df, lik, frct, ahead, mty, model), method='L-BFGS-B', bounds=None,
File "/Users/liuenmao/软件/anaconda3/python.app/Contents/lib/python3.9/site-packages/scipy/optimize/_minimize.py", line 623, in minimize
return _minimize_lbfgsb(fun, x0, args, jac, bounds,
File "/Users/liuenmao/软件/anaconda3/python.app/Contents/lib/python3.9/site-packages/scipy/optimize/lbfgsb.py", line 306, in _minimize_lbfgsb
sf = _prepare_scalar_function(fun, x0, jac=jac, args=args, epsilon=eps,
File "/Users/liuenmao/软件/anaconda3/python.app/Contents/lib/python3.9/site-packages/scipy/optimize/optimize.py", line 261, in _prepare_scalar_function
sf = ScalarFunction(fun, x0, args, grad, hess,
File "/Users/liuenmao/软件/anaconda3/python.app/Contents/lib/python3.9/site-packages/scipy/optimize/_differentiable_functions.py", line 159, in init
self._update_grad()
File "/Users/liuenmao/软件/anaconda3/python.app/Contents/lib/python3.9/site-packages/scipy/optimize/_differentiable_functions.py", line 238, in _update_grad
self._update_grad_impl()
File "/Users/liuenmao/软件/anaconda3/python.app/Contents/lib/python3.9/site-packages/scipy/optimize/_differentiable_functions.py", line 155, in update_grad
self.g = approx_derivative(fun_wrapped, self.x, f0=self.f,
File "/Users/liuenmao/软件/anaconda3/python.app/Contents/lib/python3.9/site-packages/scipy/optimize/_numdiff.py", line 486, in approx_derivative
return _dense_difference(fun_wrapped, x0, f0, h,
File "/Users/liuenmao/软件/anaconda3/python.app/Contents/lib/python3.9/site-packages/scipy/optimize/_numdiff.py", line 579, in _dense_difference
J_transposed[i] = df / dx
ValueError: setting an array element with a sequence.