financialnoob / pairs_trading Goto Github PK
View Code? Open in Web Editor NEWexperiments with pair trading
experiments with pair trading
It looks like there is an issue with your medium account, please contact them to solve whatever issue there is, your work and contributions are great and much appreciated!
using statsmodels 0.13.2
LinAlgError Traceback (most recent call last)
Input In [21], in <cell line: 6>()
19 while converged==False:
20 mod = sm.tsa.MarkovRegression(spread, k_regimes=2, switching_variance=True)
---> 21 res = mod.fit(search_reps=1000)
22 if res.smoothed_marginal_probabilities[0][-1] > 0: # check if converged
23 converged=True
File ~/anaconda3/envs/ML/lib/python3.9/site-packages/statsmodels/tsa/regime_switching/markov_switching.py:1113, in MarkovSwitching.fit(self, start_params, transformed, cov_type, cov_kwds, method, maxiter, full_output, disp, callback, return_params, em_iter, search_reps, search_iter, search_scale, **kwargs)
1111 # Get better start params through EM algorithm
1112 if em_iter and not self.tvtp:
-> 1113 start_params = self._fit_em(start_params, transformed=transformed,
1114 maxiter=em_iter, tolerance=0,
1115 return_params=True)
1116 transformed = True
1118 if transformed:
File ~/anaconda3/envs/ML/lib/python3.9/site-packages/statsmodels/tsa/regime_switching/markov_switching.py:1205, in MarkovSwitching._fit_em(self, start_params, transformed, cov_type, cov_kwds, maxiter, tolerance, full_output, return_params, **kwargs)
1203 delta = 0
1204 while i < maxiter and (i < 2 or (delta > tolerance)):
-> 1205 out = self._em_iteration(params[-1])
1206 llf.append(out[0].llf)
1207 params.append(out[1])
File ~/anaconda3/envs/ML/lib/python3.9/site-packages/statsmodels/tsa/regime_switching/markov_regression.py:214, in MarkovRegression._em_iteration(self, params0)
212 coeffs = None
213 if self._k_exog > 0:
--> 214 coeffs = self._em_exog(result, self.endog, self.exog,
215 self.parameters.switching['exog'], tmp)
216 for i in range(self.k_regimes):
217 params1[self.parameters[i, 'exog']] = coeffs[i]
File ~/anaconda3/envs/ML/lib/python3.9/site-packages/statsmodels/tsa/regime_switching/markov_regression.py:250, in MarkovRegression._em_exog(self, result, endog, exog, switching, tmp)
247 tmp_endog = tmp[i] * endog
248 tmp_exog = tmp[i][:, np.newaxis] * switching_exog
249 coeffs[i, switching] = (
--> 250 np.dot(np.linalg.pinv(tmp_exog), tmp_endog))
252 return coeffs
File <array_function internals>:180, in pinv(*args, **kwargs)
File ~/anaconda3/envs/ML/lib/python3.9/site-packages/numpy/linalg/linalg.py:1990, in pinv(a, rcond, hermitian)
1988 return wrap(res)
1989 a = a.conjugate()
-> 1990 u, s, vt = svd(a, full_matrices=False, hermitian=hermitian)
1992 # discard small singular values
1993 cutoff = rcond[..., newaxis] * amax(s, axis=-1, keepdims=True)
File <array_function internals>:180, in svd(*args, **kwargs)
File ~/anaconda3/envs/ML/lib/python3.9/site-packages/numpy/linalg/linalg.py:1648, in svd(a, full_matrices, compute_uv, hermitian)
1645 gufunc = _umath_linalg.svd_n_s
1647 signature = 'D->DdD' if isComplexType(t) else 'd->ddd'
-> 1648 u, s, vh = gufunc(a, signature=signature, extobj=extobj)
1649 u = u.astype(result_t, copy=False)
1650 s = s.astype(_realType(result_t), copy=False)
File ~/anaconda3/envs/ML/lib/python3.9/site-packages/numpy/linalg/linalg.py:97, in _raise_linalgerror_svd_nonconvergence(err, flag)
96 def _raise_linalgerror_svd_nonconvergence(err, flag):
---> 97 raise LinAlgError("SVD did not converge")
LinAlgError: SVD did not converge
I have found some syntax format for the markdown equations that can be improved to enhance readability. I also found that you can add ;
at the end of plot generating cells to suppress the output to exclude string of text when generating plots, this can help with formatting for the notebook in general. Can I create a pull request to help you with these format issues?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.