econmethods 3__tar.gz → 3.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: econmethods
3
- Version: 3
3
+ Version: 3.0.1
4
4
  Summary: A python package implementing various econometrical tests and estimators
5
5
  Home-page: https://github.com/NaturionBG/econmethods
6
6
  Author: NaturionBG
@@ -312,6 +312,9 @@ class FECM:
312
312
  - *stat_vars*: a DataFrame of the same format as "df" - includes variables that will not be differenced and included into the ECM in their raw form. Ensure these variables are I(0). Defaults to None.
313
313
  - *lr_const*: Specify whether the long-run model should have a constant.
314
314
  - *autorem*: Enables/Disables automatic removal of insignificant regression coefficients in the ECM. Defaults to True.
315
+ - *remove_difs*: Remove the cointegration vector differences. Enabling this invalidates autorem. Defaults to False.
316
+ - *remove_lr_ins*: Enables/Disables automatic removal of insignificant regression coefficients in the long-run model. Defaults to False.
317
+ - *sf*: Your significance level.
315
318
  ----
316
319
  RETURNS:
317
320
  --
@@ -321,20 +324,23 @@ class FECM:
321
324
  If a CCE- method is chosen:
322
325
  - The AR(d) estimation results to forecast the cross-sectional mean | key = "ar"
323
326
  '''
324
- def __init__(self, df: pd.DataFrame, effects: str = 'rand', trend: int = 0, n_lags: int = 1, method: str = 'MG', coint: str | list[str] = 'x1', intercept: bool = True, stat_vars: pd.DataFrame|None = None, lr_const: bool = False, autorem: bool = True) -> None:
327
+ def __init__(self, df: pd.DataFrame, effects: str = 'rand', trend: int = 0, n_lags: int = 1, method: str = 'MG', coint: str | list[str] = 'x1', intercept: bool = True, stat_vars: pd.DataFrame|None = None, lr_const: bool = False, autorem: bool = True, remove_difs: bool = False, remove_lr_ins: bool = False, sf: float = 0.05) -> None:
325
328
  self.__df = df
326
329
  self.__eff = effects.lower()
327
330
  self.__t = trend
328
331
  self.__autorem = autorem
329
332
  self.__C = intercept
330
333
  self.__lag = n_lags
334
+ self.sf = sf
331
335
  self.x_difs = []
336
+ self.__remove_difs = remove_difs
332
337
  self.__method = method.lower()
333
338
  self.__exog = len(df.columns[3:])
334
339
  self.__l =[]
335
340
  self.__stat_vars = stat_vars
336
341
  self.__mean_names = ['target_avg_l1']
337
342
  self.__stat = []
343
+ self.__lr_autorem = remove_lr_ins
338
344
  self.__lr_c = lr_const
339
345
  if stat_vars is not None:
340
346
  for i in range(1, len(stat_vars.columns[2:])+1):
@@ -420,20 +426,20 @@ class FECM:
420
426
  res_lr = sm.OLS(lr_fe.loc[:, 'target'], sm.add_constant(lr_fe.iloc[:, 3:])).fit()
421
427
  else:
422
428
  res_lr = sm.OLS(lr_fe.loc[:, 'target'], lr_fe.iloc[:, 3:]).fit()
423
- while True:
424
- flag = True
425
- for coef, t in zip(res_lr.params.index, res_lr.pvalues):
426
- if t > 0.05:
427
- lr_fe = lr_fe.drop(columns=[coef])
428
- flag=False
429
- if flag:
430
- break
431
- else:
432
- if self.__lr_c:
433
- res_lr = sm.OLS(lr_fe.loc[:, 'target'], sm.add_constant(lr_fe.iloc[:, 3:])).fit()
429
+ if self.__lr_autorem:
430
+ while True:
431
+ flag = True
432
+ for coef, t in zip(res_lr.params.index, res_lr.pvalues):
433
+ if t > self.sf:
434
+ lr_fe = lr_fe.drop(columns=[coef])
435
+ flag=False
436
+ if flag:
437
+ break
434
438
  else:
435
- res_lr = sm.OLS(lr_fe.loc[:, 'target'], lr_fe.iloc[:, 3:]).fit()
436
-
439
+ if self.__lr_c:
440
+ res_lr = sm.OLS(lr_fe.loc[:, 'target'], sm.add_constant(lr_fe.iloc[:, 3:])).fit()
441
+ else:
442
+ res_lr = sm.OLS(lr_fe.loc[:, 'target'], lr_fe.iloc[:, 3:]).fit()
437
443
  return res_lr
438
444
  else:
439
445
  lr_fe = self.build_FE()
@@ -514,27 +520,34 @@ class FECM:
514
520
  else:
515
521
  est.append(sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit())
516
522
  if self.__autorem:
517
- while True:
518
- ts = []
519
- flag = True
520
- if max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[1] > 0.06:
521
- pool = pool.drop(columns=[max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[0]])
522
- flag=False
523
- for i in self.x_difs:
524
- try:
525
- tmp = est[0].pvalues[i] <= 0.05
526
- if tmp:
523
+ if not self.__remove_difs:
524
+ while True:
525
+ ts = []
526
+ flag = True
527
+ if max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[1] > self.sf:
528
+ pool = pool.drop(columns=[max(zip(est[0].params.index, est[0].pvalues), key=lambda x: x[1])[0]])
529
+ flag=False
530
+ for i in self.x_difs:
531
+ try:
532
+ tmp = est[0].pvalues[i] <= self.sf
533
+ if tmp:
534
+ ts.append(1)
535
+ except Exception:
527
536
  ts.append(1)
528
- except Exception:
529
- ts.append(1)
530
-
531
- if flag or len(ts) == len(self.x_difs):
532
- break
533
- else:
534
- if self.__C:
535
- est[0] = sm.OLS(pool['target_diff'], sm.add_constant(pool.iloc[:, 3:])).fit()
537
+
538
+ if flag or len(ts) == len(self.x_difs):
539
+ break
536
540
  else:
537
- est[0] = sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit()
541
+ if self.__C:
542
+ est[0] = sm.OLS(pool['target_diff'], sm.add_constant(pool.iloc[:, 3:])).fit()
543
+ else:
544
+ est[0] = sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit()
545
+ else:
546
+ pool = pool.drop(columns=[self.x_difs])
547
+ if self.__C:
548
+ est[0] = sm.OLS(pool['target_diff'], sm.add_constant(pool.iloc[:, 3:])).fit()
549
+ else:
550
+ est[0] = sm.OLS(pool['target_diff'], pool.iloc[:, 3:]).fit()
538
551
  return est
539
552
 
540
553
  def mg_algorithm(self) -> pd.DataFrame:
@@ -568,29 +581,35 @@ class FECM:
568
581
  dct['lr_res'] = self.__lr
569
582
  res = self.mg_algorithm()
570
583
  if self.__autorem:
571
- while True:
572
- ts = []
573
- flag = True
574
- if max(zip(res['coefs'].index, res['coefs']['T-pvalues']), key=lambda x: x[1])[1] > 0.06:
575
- self.__sr = self.build_sr([max(zip(res['coefs'].index, res['coefs']['T-pvalues']), key=lambda x: x[1])[0]])
576
- flag=False
577
- for i in self.x_difs:
578
- try:
579
- tmp = res['coefs']['T-pvalues'][i] <= 0.05
580
- if tmp:
584
+ if not self.__remove_difs:
585
+ while True:
586
+ ts = []
587
+ flag = True
588
+ if max(zip(res['coefs'].index, res['coefs']['T-pvalues']), key=lambda x: x[1])[1] > self.sf:
589
+ self.__sr = self.build_sr([max(zip(res['coefs'].index, res['coefs']['T-pvalues']), key=lambda x: x[1])[0]])
590
+ flag=False
591
+ for i in self.x_difs:
592
+ try:
593
+ tmp = res['coefs']['T-pvalues'][i] <= 0.1
594
+ if tmp:
595
+ ts.append(1)
596
+ except Exception:
581
597
  ts.append(1)
582
- except Exception:
583
- ts.append(1)
584
- if flag or len(ts) == len(self.x_difs):
585
- break
586
- else:
587
- res = self.mg_algorithm()
598
+ if flag or len(ts) == len(self.x_difs):
599
+ break
600
+ else:
601
+ res = self.mg_algorithm()
602
+ else:
603
+ self.__sr = self.build_sr([self.x_difs])
604
+ res = self.mg_algorithm()
605
+
588
606
 
589
607
  dct['sr_res'] = res
590
608
  return dct
591
609
 
592
610
  def __del__(self) -> None:
593
611
  pass
612
+
594
613
  class CDTwoWay:
595
614
  '''
596
615
  Implementation of the CD test to validate/reject cross-sectional dependence.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: econmethods
3
- Version: 3
3
+ Version: 3.0.1
4
4
  Summary: A python package implementing various econometrical tests and estimators
5
5
  Home-page: https://github.com/NaturionBG/econmethods
6
6
  Author: NaturionBG
@@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
5
5
 
6
6
  setup(
7
7
  name = 'econmethods',
8
- version = 'v3',
8
+ version = 'v3.0.1',
9
9
  description='A python package implementing various econometrical tests and estimators',
10
10
  packages = find_packages(),
11
11
  long_description=long_desc,
File without changes
File without changes