christoffersen-lib 0.1.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.
- christoffersen_lib-0.1.0/PKG-INFO +17 -0
- christoffersen_lib-0.1.0/README.md +1 -0
- christoffersen_lib-0.1.0/christoffersen/__init__.py +1 -0
- christoffersen_lib-0.1.0/christoffersen/independence.py +29 -0
- christoffersen_lib-0.1.0/christoffersen_lib.egg-info/PKG-INFO +17 -0
- christoffersen_lib-0.1.0/christoffersen_lib.egg-info/SOURCES.txt +10 -0
- christoffersen_lib-0.1.0/christoffersen_lib.egg-info/dependency_links.txt +1 -0
- christoffersen_lib-0.1.0/christoffersen_lib.egg-info/requires.txt +2 -0
- christoffersen_lib-0.1.0/christoffersen_lib.egg-info/top_level.txt +1 -0
- christoffersen_lib-0.1.0/setup.cfg +4 -0
- christoffersen_lib-0.1.0/setup.py +16 -0
- christoffersen_lib-0.1.0/tests/test_independence.py +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: christoffersen_lib
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Christoffersen Independence Test for VaR backtesting
|
|
5
|
+
Author: Ton Nom
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: numpy
|
|
9
|
+
Requires-Dist: scipy
|
|
10
|
+
Dynamic: author
|
|
11
|
+
Dynamic: description
|
|
12
|
+
Dynamic: description-content-type
|
|
13
|
+
Dynamic: requires-dist
|
|
14
|
+
Dynamic: requires-python
|
|
15
|
+
Dynamic: summary
|
|
16
|
+
|
|
17
|
+
# Christoffersen Lib - Test d'indépendance pour la VaR
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Christoffersen Lib - Test d'indépendance pour la VaR
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .independence import independence_test
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from scipy.stats import chi2
|
|
3
|
+
|
|
4
|
+
def independence_test(violations):
|
|
5
|
+
"""
|
|
6
|
+
Réalise le test d'indépendance de Christoffersen pour le backtesting de la VaR.
|
|
7
|
+
"""
|
|
8
|
+
violations = np.array(violations)
|
|
9
|
+
n00, n01, n10, n11 = 0, 0, 0, 0
|
|
10
|
+
|
|
11
|
+
for t in range(1, len(violations)):
|
|
12
|
+
if violations[t-1] == 0 and violations[t] == 0: n00 += 1
|
|
13
|
+
elif violations[t-1] == 0 and violations[t] == 1: n01 += 1
|
|
14
|
+
elif violations[t-1] == 1 and violations[t] == 0: n10 += 1
|
|
15
|
+
elif violations[t-1] == 1 and violations[t] == 1: n11 += 1
|
|
16
|
+
|
|
17
|
+
# Probabilités conditionnelles
|
|
18
|
+
pi0 = n01 / (n00 + n01) if (n00 + n01) > 0 else 0
|
|
19
|
+
pi1 = n11 / (n10 + n11) if (n10 + n11) > 0 else 0
|
|
20
|
+
pi = (n01 + n11) / (n00 + n01 + n10 + n11) if (n00 + n01 + n10 + n11) > 0 else 0
|
|
21
|
+
|
|
22
|
+
# Log-likelihood Ratio (LR ind)
|
|
23
|
+
term_null = (1 - pi)**(n00 + n10) * pi**(n01 + n11)
|
|
24
|
+
term_alt = (1 - pi0)**n00 * pi0**n01 * (1 - pi1)**n10 * pi1**n11
|
|
25
|
+
|
|
26
|
+
lr_ind = -2 * np.log(term_null / term_alt) if term_alt > 0 else 0
|
|
27
|
+
p_value = 1 - chi2.cdf(lr_ind, df=1)
|
|
28
|
+
|
|
29
|
+
return lr_ind, p_value
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: christoffersen_lib
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Christoffersen Independence Test for VaR backtesting
|
|
5
|
+
Author: Ton Nom
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: numpy
|
|
9
|
+
Requires-Dist: scipy
|
|
10
|
+
Dynamic: author
|
|
11
|
+
Dynamic: description
|
|
12
|
+
Dynamic: description-content-type
|
|
13
|
+
Dynamic: requires-dist
|
|
14
|
+
Dynamic: requires-python
|
|
15
|
+
Dynamic: summary
|
|
16
|
+
|
|
17
|
+
# Christoffersen Lib - Test d'indépendance pour la VaR
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
christoffersen/__init__.py
|
|
4
|
+
christoffersen/independence.py
|
|
5
|
+
christoffersen_lib.egg-info/PKG-INFO
|
|
6
|
+
christoffersen_lib.egg-info/SOURCES.txt
|
|
7
|
+
christoffersen_lib.egg-info/dependency_links.txt
|
|
8
|
+
christoffersen_lib.egg-info/requires.txt
|
|
9
|
+
christoffersen_lib.egg-info/top_level.txt
|
|
10
|
+
tests/test_independence.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
christoffersen
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="christoffersen_lib",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
author="Ton Nom",
|
|
7
|
+
description="Christoffersen Independence Test for VaR backtesting",
|
|
8
|
+
long_description=open("README.md").read(),
|
|
9
|
+
long_description_content_type="text/markdown",
|
|
10
|
+
packages=find_packages(),
|
|
11
|
+
install_requires=[
|
|
12
|
+
"numpy",
|
|
13
|
+
"scipy"
|
|
14
|
+
],
|
|
15
|
+
python_requires='>=3.7',
|
|
16
|
+
)
|
|
File without changes
|