dasycaus 1.0.0__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.
dasycaus-1.0.0/LICENSE ADDED
@@ -0,0 +1,48 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Dr. Merwan Roudane
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ ATTRIBUTION NOTICE:
26
+
27
+ This software implements the methodology developed by:
28
+ - Prof. Abdulnasser Hatemi-J (UAE University)
29
+ - Dr. Alan Mustafa (IEEE)
30
+
31
+ Based on the original GAUSS code and the following papers:
32
+
33
+ 1. Hatemi-J, A. (2021). Dynamic Asymmetric Causality Tests with an Application.
34
+ Papers 2106.07612, arXiv.org.
35
+
36
+ 2. Hatemi-J, A. (2012). Asymmetric Causality Tests with an Application.
37
+ Empirical Economics, 43(1), 447-456.
38
+
39
+ 3. Hacker, S. and Hatemi-J, A. (2006). Tests for causality between integrated
40
+ variables using asymptotic and bootstrap distributions: theory and application.
41
+ Applied Economics, 38(13), 1489-1500.
42
+
43
+ 4. Hacker, S. and Hatemi-J, A. (2012). A bootstrap test for causality with
44
+ endogenous lag length choice: theory and application in finance.
45
+ Journal of Economic Studies, 39(2), 144-160.
46
+
47
+ Proper citation of the original methodology is required when using this software
48
+ for academic or research purposes.
@@ -0,0 +1,8 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ recursive-include examples *.py
5
+ recursive-include tests *.py
6
+ recursive-include dasycaus *.py
7
+ global-exclude __pycache__
8
+ global-exclude *.py[co]
@@ -0,0 +1,440 @@
1
+ Metadata-Version: 2.4
2
+ Name: dasycaus
3
+ Version: 1.0.0
4
+ Summary: Dynamic Asymmetric Causality Tests for Time Series Analysis
5
+ Author-email: "Dr. Merwan Roudane" <merwanroudane920@gmail.com>
6
+ Maintainer-email: "Dr. Merwan Roudane" <merwanroudane920@gmail.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/merwanroudane/dasycaus
9
+ Project-URL: Repository, https://github.com/merwanroudane/dasycaus
10
+ Project-URL: Documentation, https://github.com/merwanroudane/dasycaus#readme
11
+ Project-URL: Bug Tracker, https://github.com/merwanroudane/dasycaus/issues
12
+ Keywords: causality,granger-causality,asymmetric-causality,time-series,econometrics,var-model,bootstrap,hatemi-j
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Intended Audience :: Financial and Insurance Industry
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Scientific/Engineering
25
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
26
+ Classifier: Topic :: Office/Business :: Financial
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: numpy>=1.20.0
31
+ Requires-Dist: scipy>=1.7.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=7.0; extra == "dev"
34
+ Requires-Dist: pytest-cov>=3.0; extra == "dev"
35
+ Requires-Dist: black>=22.0; extra == "dev"
36
+ Requires-Dist: flake8>=4.0; extra == "dev"
37
+ Requires-Dist: mypy>=0.950; extra == "dev"
38
+ Provides-Extra: plotting
39
+ Requires-Dist: matplotlib>=3.5.0; extra == "plotting"
40
+ Provides-Extra: export
41
+ Requires-Dist: pandas>=1.3.0; extra == "export"
42
+ Provides-Extra: full
43
+ Requires-Dist: matplotlib>=3.5.0; extra == "full"
44
+ Requires-Dist: pandas>=1.3.0; extra == "full"
45
+ Requires-Dist: pytest>=7.0; extra == "full"
46
+ Requires-Dist: pytest-cov>=3.0; extra == "full"
47
+ Dynamic: license-file
48
+
49
+ # DASYCAUS: Dynamic Asymmetric Causality Tests
50
+
51
+ [![Python Version](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
52
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
53
+
54
+ A Python library for **Dynamic Asymmetric and Symmetric Causality Tests** in time series analysis, based on the methodology developed by Hatemi-J (2012, 2021).
55
+
56
+ ## ๐Ÿ“š Overview
57
+
58
+ DASYCAUS provides a comprehensive implementation of:
59
+
60
+ - **Static Symmetric Causality Tests** (Granger causality with bootstrap)
61
+ - **Static Asymmetric Causality Tests** (testing positive and negative components separately)
62
+ - **Dynamic Symmetric Causality Tests** (time-varying causality using subsamples)
63
+ - **Dynamic Asymmetric Causality Tests** (time-varying asymmetric causality)
64
+
65
+ The library implements leverage-adjusted bootstrap procedures for accurate critical value computation and supports various information criteria for optimal lag selection.
66
+
67
+ ## ๐Ÿ”ฌ Theoretical Background
68
+
69
+ This library is based on the following key papers:
70
+
71
+ 1. **Hatemi-J, A. (2021).** "Dynamic Asymmetric Causality Tests with an Application." *arXiv:2106.07612*.
72
+
73
+ 2. **Hatemi-J, A. (2012).** "Asymmetric Causality Tests with an Application." *Empirical Economics*, 43(1), 447-456.
74
+
75
+ 3. **Hacker, S. and Hatemi-J, A. (2006).** "Tests for causality between integrated variables using asymptotic and bootstrap distributions: theory and application." *Applied Economics*, 38(13), 1489-1500.
76
+
77
+ 4. **Hacker, S. and Hatemi-J, A. (2012).** "A bootstrap test for causality with endogenous lag length choice: theory and application in finance." *Journal of Economic Studies*, 39(2), 144-160.
78
+
79
+ ## ๐Ÿš€ Installation
80
+
81
+ ### From PyPI (when published)
82
+
83
+ ```bash
84
+ pip install dasycaus
85
+ ```
86
+
87
+ ### From Source
88
+
89
+ ```bash
90
+ git clone https://github.com/merwanroudane/dasycaus.git
91
+ cd dasycaus
92
+ pip install -e .
93
+ ```
94
+
95
+ ### With Optional Dependencies
96
+
97
+ ```bash
98
+ # For plotting capabilities
99
+ pip install dasycaus[plotting]
100
+
101
+ # For data export features
102
+ pip install dasycaus[export]
103
+
104
+ # For all features
105
+ pip install dasycaus[full]
106
+ ```
107
+
108
+ ## ๐Ÿ“‹ Requirements
109
+
110
+ **Core Dependencies:**
111
+ - Python >= 3.8
112
+ - NumPy >= 1.20.0
113
+ - SciPy >= 1.7.0
114
+
115
+ **Optional Dependencies:**
116
+ - matplotlib >= 3.5.0 (for plotting)
117
+ - pandas >= 1.3.0 (for data export)
118
+
119
+ ## ๐Ÿ”ง Quick Start
120
+
121
+ ### Example 1: Static Symmetric Causality Test
122
+
123
+ ```python
124
+ import numpy as np
125
+ from dasycaus import symmetric_causality_test
126
+
127
+ # Load your data (T x n matrix)
128
+ data = np.loadtxt('your_data.txt')
129
+
130
+ # Conduct symmetric causality test
131
+ results = symmetric_causality_test(
132
+ data=data,
133
+ maxlags=8,
134
+ integration_order=1,
135
+ info_criterion='hjc',
136
+ bootstrap_sims=1000,
137
+ significance_levels=[0.05, 0.10]
138
+ )
139
+
140
+ print(f"Test Statistic: {results['test_statistic']:.4f}")
141
+ print(f"Optimal Lag: {results['optimal_lag']}")
142
+ print(f"Reject H0 at 5%: {results['reject_null'][0.05]}")
143
+ ```
144
+
145
+ ### Example 2: Static Asymmetric Causality Test
146
+
147
+ ```python
148
+ from dasycaus import asymmetric_causality_test
149
+
150
+ # Test positive components
151
+ results_positive = asymmetric_causality_test(
152
+ data=data,
153
+ maxlags=8,
154
+ component='positive', # or 'negative'
155
+ integration_order=1,
156
+ info_criterion='hjc',
157
+ bootstrap_sims=1000
158
+ )
159
+
160
+ print(f"Positive Component Test Statistic: {results_positive['test_statistic']:.4f}")
161
+ ```
162
+
163
+ ### Example 3: Dynamic Symmetric Causality Test
164
+
165
+ ```python
166
+ from dasycaus import dynamic_symmetric_causality_test
167
+ from dasycaus.utils import plot_dynamic_causality, create_summary_table
168
+
169
+ # Conduct dynamic test
170
+ results = dynamic_symmetric_causality_test(
171
+ data=data,
172
+ maxlags=8,
173
+ integration_order=1,
174
+ info_criterion='hjc',
175
+ bootstrap_sims=1000,
176
+ subsample_method='recursive' # or 'rolling'
177
+ )
178
+
179
+ # Print summary
180
+ print(create_summary_table(results))
181
+
182
+ # Plot results
183
+ plot_dynamic_causality(
184
+ results,
185
+ significance_level=0.05,
186
+ title="Dynamic Causality Test Results",
187
+ save_path="dynamic_test.png"
188
+ )
189
+ ```
190
+
191
+ ### Example 4: Dynamic Asymmetric Causality Test
192
+
193
+ ```python
194
+ from dasycaus import dynamic_asymmetric_causality_test
195
+
196
+ # Test dynamic asymmetric causality for positive components
197
+ results = dynamic_asymmetric_causality_test(
198
+ data=data,
199
+ maxlags=8,
200
+ component='positive',
201
+ integration_order=1,
202
+ info_criterion='hjc',
203
+ bootstrap_sims=1000,
204
+ subsample_method='recursive'
205
+ )
206
+
207
+ # Visualize
208
+ plot_dynamic_causality(results, significance_level=0.10)
209
+ ```
210
+
211
+ ## ๐Ÿ“Š Key Features
212
+
213
+ ### 1. Data Transformation
214
+ Transform integrated variables into cumulative positive and negative components:
215
+
216
+ ```python
217
+ from dasycaus import transform_to_cumulative_components
218
+
219
+ positive_components = transform_to_cumulative_components(
220
+ data,
221
+ component='positive',
222
+ include_trend=True
223
+ )
224
+
225
+ negative_components = transform_to_cumulative_components(
226
+ data,
227
+ component='negative',
228
+ include_trend=True
229
+ )
230
+ ```
231
+
232
+ ### 2. Lag Selection
233
+ Multiple information criteria supported:
234
+
235
+ ```python
236
+ from dasycaus import select_optimal_lag, compare_criteria
237
+
238
+ # Single criterion
239
+ lag_info = select_optimal_lag(
240
+ data,
241
+ maxlags=12,
242
+ info_criterion='hjc' # 'aic', 'aicc', 'sbc', 'hqc', 'hjc'
243
+ )
244
+
245
+ # Compare all criteria
246
+ comparison = compare_criteria(data, maxlags=12)
247
+ print(comparison['optimal_lags'])
248
+ ```
249
+
250
+ ### 3. Bootstrap Critical Values
251
+ Leverage-adjusted bootstrap for accurate inference:
252
+
253
+ ```python
254
+ from dasycaus import bootstrap_critical_values
255
+
256
+ cv = bootstrap_critical_values(
257
+ data,
258
+ lag_order=4,
259
+ integration_order=1,
260
+ num_simulations=1000,
261
+ significance_level=0.05,
262
+ leverage_adjustment=True
263
+ )
264
+ ```
265
+
266
+ ### 4. Subsample Methods
267
+
268
+ **Recursive Method:** Starts with minimum size, adds one observation each iteration
269
+ ```python
270
+ subsample_method='recursive'
271
+ ```
272
+
273
+ **Rolling Window Method:** Fixed window size, rolls forward
274
+ ```python
275
+ subsample_method='rolling'
276
+ ```
277
+
278
+ ## ๐Ÿ“ˆ Application Example: Oil Prices and Stock Market
279
+
280
+ Replicating the analysis from Hatemi-J (2021):
281
+
282
+ ```python
283
+ import numpy as np
284
+ from dasycaus import dynamic_asymmetric_causality_test
285
+ from dasycaus.utils import plot_dynamic_causality
286
+
287
+ # Load data (log of oil prices and stock prices)
288
+ data = np.loadtxt('oil_stock_data.txt') # 1990-2020
289
+
290
+ # Test if oil price increases cause stock market increases
291
+ results_positive = dynamic_asymmetric_causality_test(
292
+ data=data,
293
+ maxlags=4,
294
+ component='positive',
295
+ integration_order=1,
296
+ info_criterion='hjc',
297
+ bootstrap_sims=1000,
298
+ subsample_method='recursive'
299
+ )
300
+
301
+ # Test if oil price decreases cause stock market decreases
302
+ results_negative = dynamic_asymmetric_causality_test(
303
+ data=data,
304
+ maxlags=4,
305
+ component='negative',
306
+ integration_order=1,
307
+ info_criterion='hjc',
308
+ bootstrap_sims=1000,
309
+ subsample_method='recursive'
310
+ )
311
+
312
+ # Visualize results
313
+ plot_dynamic_causality(
314
+ results_positive,
315
+ significance_level=0.10,
316
+ title="H0: Oil Price Increase Does Not Cause Stock Market Increase"
317
+ )
318
+ ```
319
+
320
+ ## ๐Ÿ“– Documentation
321
+
322
+ ### Main Functions
323
+
324
+ #### `symmetric_causality_test`
325
+ Conducts static Granger causality test with bootstrap critical values.
326
+
327
+ **Parameters:**
328
+ - `data`: (T, n) array of time series data
329
+ - `maxlags`: Maximum lag order to consider
330
+ - `integration_order`: Integration order (0, 1, or 2)
331
+ - `info_criterion`: 'aic', 'aicc', 'sbc', 'hqc', or 'hjc'
332
+ - `bootstrap_sims`: Number of bootstrap simulations
333
+ - `significance_levels`: List of significance levels
334
+ - `random_seed`: Seed for reproducibility
335
+
336
+ **Returns:** Dictionary with test statistic, optimal lag, critical values, and rejection decisions.
337
+
338
+ #### `asymmetric_causality_test`
339
+ Tests causality in positive or negative components separately.
340
+
341
+ **Additional Parameters:**
342
+ - `component`: 'positive' or 'negative'
343
+ - `include_trend`: Whether to include deterministic trend
344
+
345
+ #### `dynamic_symmetric_causality_test`
346
+ Time-varying causality test using subsamples.
347
+
348
+ **Additional Parameters:**
349
+ - `subsample_method`: 'recursive' or 'rolling'
350
+
351
+ **Returns:** Dictionary with subsample results, test ratios, and rejection patterns.
352
+
353
+ #### `dynamic_asymmetric_causality_test`
354
+ Time-varying asymmetric causality test.
355
+
356
+ Combines data transformation with dynamic testing.
357
+
358
+ ## ๐Ÿงช Testing
359
+
360
+ Run the test suite:
361
+
362
+ ```bash
363
+ pytest tests/ -v --cov=dasycaus
364
+ ```
365
+
366
+ ## ๐Ÿ“ Citation
367
+
368
+ If you use this library in your research, please cite:
369
+
370
+ ```bibtex
371
+ @software{roudane2024dasycaus,
372
+ author = {Roudane, Merwan},
373
+ title = {DASYCAUS: Dynamic Asymmetric Causality Tests in Python},
374
+ year = {2024},
375
+ url = {https://github.com/merwanroudane/dasycaus},
376
+ }
377
+ ```
378
+
379
+ And the original methodology papers:
380
+
381
+ ```bibtex
382
+ @article{hatemi2012asymmetric,
383
+ title={Asymmetric causality tests with an application},
384
+ author={Hatemi-J, Abdulnasser},
385
+ journal={Empirical Economics},
386
+ volume={43},
387
+ number={1},
388
+ pages={447--456},
389
+ year={2012}
390
+ }
391
+
392
+ @article{hatemi2021dynamic,
393
+ title={Dynamic Asymmetric Causality Tests with an Application},
394
+ author={Hatemi-J, Abdulnasser},
395
+ journal={arXiv preprint arXiv:2106.07612},
396
+ year={2021}
397
+ }
398
+ ```
399
+
400
+ ## ๐Ÿค Contributing
401
+
402
+ Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
403
+
404
+ 1. Fork the repository
405
+ 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
406
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
407
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
408
+ 5. Open a Pull Request
409
+
410
+ ## ๐Ÿ“„ License
411
+
412
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
413
+
414
+ ## ๐Ÿ‘ค Author
415
+
416
+ **Dr. Merwan Roudane**
417
+ - Email: merwanroudane920@gmail.com
418
+ - GitHub: [@merwanroudane](https://github.com/merwanroudane)
419
+
420
+ ## ๐Ÿ™ Acknowledgments
421
+
422
+ This library is a Python implementation of the methodology developed by:
423
+ - **Prof. Abdulnasser Hatemi-J** (UAE University)
424
+ - **Dr. Alan Mustafa** (IEEE)
425
+
426
+ Original GAUSS code: DASCT01 - Gauss Module for Estimating the Dynamic Asymmetric and Symmetric Causality Tests
427
+
428
+ ## ๐Ÿ“š References
429
+
430
+ - Hatemi-J, A. (2003). A new method to choose optimal lag order in stable and unstable VAR models. *Applied Economics Letters*, 10(3), 135-137.
431
+ - Toda, H.Y. and Yamamoto, T. (1995). Statistical inference in vector autoregressions with possibly integrated processes. *Journal of Econometrics*, 66, 225-250.
432
+ - Phillips, P.C., Shi, S., and Yu, J. (2015). Testing for multiple bubbles: historical episodes of exuberance and collapse in the S&P 500. *International Economic Review*, 56(4), 1043-1078.
433
+
434
+ ## ๐Ÿ” Keywords
435
+
436
+ causality, Granger causality, asymmetric causality, dynamic causality, time series, econometrics, VAR model, bootstrap, Hatemi-J, oil prices, stock market, financial econometrics
437
+
438
+ ---
439
+
440
+ **Note:** This is an independent implementation for educational and research purposes. For the original GAUSS implementation, please contact the original authors.