nirvana-quant 1.0.0__py3-none-any.whl
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.
- nirvana/__init__.py +75 -0
- nirvana/domains/__init__.py +41 -0
- nirvana/domains/banking.py +77 -0
- nirvana/domains/consumer.py +132 -0
- nirvana/domains/cybersecurity.py +58 -0
- nirvana/domains/substitute.py +79 -0
- nirvana/domains/supply_chain.py +56 -0
- nirvana/experimental/__init__.py +22 -0
- nirvana/experimental/multiverse_invariance.py +269 -0
- nirvana/kalman.py +282 -0
- nirvana/manifold.py +184 -0
- nirvana/multiplex.py +75 -0
- nirvana/multiverse.py +217 -0
- nirvana/network.py +675 -0
- nirvana/proof.py +958 -0
- nirvana/stata.py +497 -0
- nirvana/static.py +774 -0
- nirvana/tree.py +497 -0
- nirvana/volatility.py +121 -0
- nirvana_quant-1.0.0.dist-info/METADATA +168 -0
- nirvana_quant-1.0.0.dist-info/RECORD +24 -0
- nirvana_quant-1.0.0.dist-info/WHEEL +5 -0
- nirvana_quant-1.0.0.dist-info/licenses/LICENSE +239 -0
- nirvana_quant-1.0.0.dist-info/top_level.txt +2 -0
nirvana/__init__.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NIRVANA: Chrono-Cancer Meta-Architecture for High-Dimensional Financial Risk & Network Dynamics
|
|
3
|
+
================================================================================================
|
|
4
|
+
A causal, manifold-based quantitative engine for financial time-series, volatility spillover,
|
|
5
|
+
and systemic risk analysis across interconnected banking systems.
|
|
6
|
+
|
|
7
|
+
Author: yinyusi65 & Nirvana Quant Team
|
|
8
|
+
License: MIT / Academic Research
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
__version__ = "1.0.0"
|
|
12
|
+
|
|
13
|
+
from .manifold import Base12Manifold, DualClockCoordinates
|
|
14
|
+
from .kalman import CausalOnlineKalman, MultivariateCausalKalman, CausalKalmanTVPRegressor
|
|
15
|
+
from .tree import NirvanaTreeEngine, TrainingSample
|
|
16
|
+
from .network import (
|
|
17
|
+
NirvanaConnectedness,
|
|
18
|
+
SystemicRiskReport,
|
|
19
|
+
DynamicSystemicRiskReport,
|
|
20
|
+
DEFAULT_ASSET_WEIGHTS,
|
|
21
|
+
DEFAULT_EXCHANGE_BANDS,
|
|
22
|
+
)
|
|
23
|
+
from .multiplex import MultiplexNetworkEngine
|
|
24
|
+
from .multiverse import MultiverseReconstructor
|
|
25
|
+
from .volatility import compute_parkinson, compute_garman_klass, compute_yang_zhang
|
|
26
|
+
from .static import (
|
|
27
|
+
NirvanaStaticBooster,
|
|
28
|
+
StaticEconometricReport,
|
|
29
|
+
NirvanaTreeRegressor,
|
|
30
|
+
NirvanaTwoStageRegressor,
|
|
31
|
+
parse_formula,
|
|
32
|
+
)
|
|
33
|
+
from .stata import stata_regress, StataRegressionResult, stata_summarize, stata_pwcorr
|
|
34
|
+
from .proof import (
|
|
35
|
+
prove_phase2_variable,
|
|
36
|
+
Phase2MultiverseProofReport,
|
|
37
|
+
rank_phase2_discovered_variables,
|
|
38
|
+
Phase2RankedVariablesReport,
|
|
39
|
+
DiscoveredVariableItem,
|
|
40
|
+
)
|
|
41
|
+
from . import domains
|
|
42
|
+
|
|
43
|
+
__all__ = [
|
|
44
|
+
"Base12Manifold",
|
|
45
|
+
"DualClockCoordinates",
|
|
46
|
+
"CausalOnlineKalman",
|
|
47
|
+
"MultivariateCausalKalman",
|
|
48
|
+
"NirvanaTreeEngine",
|
|
49
|
+
"TrainingSample",
|
|
50
|
+
"NirvanaStaticBooster",
|
|
51
|
+
"StaticEconometricReport",
|
|
52
|
+
"NirvanaTreeRegressor",
|
|
53
|
+
"NirvanaTwoStageRegressor",
|
|
54
|
+
"parse_formula",
|
|
55
|
+
"stata_regress",
|
|
56
|
+
"StataRegressionResult",
|
|
57
|
+
"stata_summarize",
|
|
58
|
+
"stata_pwcorr",
|
|
59
|
+
"prove_phase2_variable",
|
|
60
|
+
"Phase2MultiverseProofReport",
|
|
61
|
+
"rank_phase2_discovered_variables",
|
|
62
|
+
"Phase2RankedVariablesReport",
|
|
63
|
+
"DiscoveredVariableItem",
|
|
64
|
+
"NirvanaConnectedness",
|
|
65
|
+
"SystemicRiskReport",
|
|
66
|
+
"DynamicSystemicRiskReport",
|
|
67
|
+
"DEFAULT_ASSET_WEIGHTS",
|
|
68
|
+
"DEFAULT_EXCHANGE_BANDS",
|
|
69
|
+
"MultiplexNetworkEngine",
|
|
70
|
+
"MultiverseReconstructor",
|
|
71
|
+
"compute_parkinson",
|
|
72
|
+
"compute_garman_klass",
|
|
73
|
+
"compute_yang_zhang",
|
|
74
|
+
"domains",
|
|
75
|
+
]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NIRVANA DOMAIN-SPECIFIC SPECIALIZED EXTENSION MODULES
|
|
3
|
+
======================================================
|
|
4
|
+
Domain modules for translating universal Nirvana causal graph dynamics into
|
|
5
|
+
sector-specific actionable intelligence:
|
|
6
|
+
- banking: Basel IV, SIFI, bank capital buffers, HOSE/HNX/UPCoM limits
|
|
7
|
+
- cybersecurity: DDoS amplification, botnet hubs, BGP chokepoints
|
|
8
|
+
- supply_chain: Bullwhip effect, sole-source bottleneck suppliers
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .banking import (
|
|
12
|
+
DEFAULT_BANKING_TIERS,
|
|
13
|
+
DEFAULT_EXCHANGE_BANDS,
|
|
14
|
+
DEFAULT_ASSET_WEIGHTS,
|
|
15
|
+
classify_sifi_status,
|
|
16
|
+
)
|
|
17
|
+
from .cybersecurity import analyze_cyber_contagion
|
|
18
|
+
from .supply_chain import analyze_supply_chain_risk
|
|
19
|
+
from .consumer import (
|
|
20
|
+
DEFAULT_CONSUMER_CATEGORIES,
|
|
21
|
+
DEFAULT_EXPENDITURE_WEIGHTS,
|
|
22
|
+
analyze_consumer_dynamics,
|
|
23
|
+
)
|
|
24
|
+
from .substitute import (
|
|
25
|
+
DEFAULT_PROTEIN_SUBSTITUTE_ROLES,
|
|
26
|
+
analyze_substitution_thresholds,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"DEFAULT_BANKING_TIERS",
|
|
31
|
+
"DEFAULT_EXCHANGE_BANDS",
|
|
32
|
+
"DEFAULT_ASSET_WEIGHTS",
|
|
33
|
+
"classify_sifi_status",
|
|
34
|
+
"analyze_cyber_contagion",
|
|
35
|
+
"analyze_supply_chain_risk",
|
|
36
|
+
"DEFAULT_CONSUMER_CATEGORIES",
|
|
37
|
+
"DEFAULT_EXPENDITURE_WEIGHTS",
|
|
38
|
+
"analyze_consumer_dynamics",
|
|
39
|
+
"DEFAULT_PROTEIN_SUBSTITUTE_ROLES",
|
|
40
|
+
"analyze_substitution_thresholds",
|
|
41
|
+
]
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Nirvana Domain Module: Banking & Financial Systems
|
|
3
|
+
===================================================
|
|
4
|
+
Domain-specific parameters, regulatory bands, asset weights, and structural tiers
|
|
5
|
+
for Vietnamese commercial banks and Basel IV systemic risk analysis.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Dict, List, Optional
|
|
9
|
+
import numpy as np
|
|
10
|
+
import pandas as pd
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Structural Banking Tiers in the Vietnamese Banking System
|
|
14
|
+
DEFAULT_BANKING_TIERS: Dict[str, List[str]] = {
|
|
15
|
+
"BIG4_STATE": ["VCB", "CTG", "BID"],
|
|
16
|
+
"TIER1_RETAIL_CORP": ["TCB", "VPB", "MBB", "ACB", "HDB", "VIB", "TPB", "SHB", "STB"],
|
|
17
|
+
"TIER2_COMMERCIAL": ["MSB", "OCB", "LPB", "EIB", "SSB", "NAB"],
|
|
18
|
+
"TIER3_REGIONAL_RESTRUCTURING": ["BAB", "BVB", "KLB", "NVB", "PGB", "SGB", "VAB", "VBB"],
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# Statutory Exchange Price Limits (heteroskedasticity bounds)
|
|
22
|
+
DEFAULT_EXCHANGE_BANDS: Dict[str, float] = {
|
|
23
|
+
# HNX (10% limit)
|
|
24
|
+
"NVB": 0.10, "BAB": 0.10,
|
|
25
|
+
# UPCoM (15% limit)
|
|
26
|
+
"BVB": 0.15, "SGB": 0.15, "PGB": 0.15, "VBB": 0.15,
|
|
27
|
+
"KLB": 0.15, "ABB": 0.15, "NAB": 0.15, "VAB": 0.15,
|
|
28
|
+
# All others default to HOSE (7% limit)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Empirical 2024 Total Assets (Trillion VND) for all 27 Vietnamese commercial banks
|
|
32
|
+
DEFAULT_ASSET_WEIGHTS: Dict[str, float] = {
|
|
33
|
+
# Big4 State Banks (~1,800 - 2,300 Trillion VND)
|
|
34
|
+
"BID": 2300.0, "CTG": 2000.0, "VCB": 1800.0,
|
|
35
|
+
# Tier-1 Joint-Stock Retail & Corporate (~600 - 900 Trillion VND)
|
|
36
|
+
"MBB": 900.0, "TCB": 850.0, "VPB": 820.0, "ACB": 720.0,
|
|
37
|
+
"STB": 670.0, "SHB": 630.0, "HDB": 600.0,
|
|
38
|
+
# Tier-2 Commercial (~200 - 450 Trillion VND)
|
|
39
|
+
"VIB": 410.0, "LPB": 380.0, "TPB": 360.0, "MSB": 270.0,
|
|
40
|
+
"SSB": 270.0, "OCB": 240.0, "EIB": 200.0, "NAB": 200.0,
|
|
41
|
+
# Tier-3 Regional & Restructuring (~35 - 160 Trillion VND)
|
|
42
|
+
"ABB": 160.0, "VAB": 110.0, "BAB": 100.0, "NVB": 90.0,
|
|
43
|
+
"KLB": 85.0, "BVB": 85.0, "PGB": 55.0, "SGB": 35.0, "VBB": 35.0,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def classify_sifi_status(
|
|
48
|
+
net_spillovers: Dict[str, float],
|
|
49
|
+
hub_scores: Optional[Dict[str, float]] = None,
|
|
50
|
+
asset_weights: Optional[Dict[str, float]] = None,
|
|
51
|
+
sifi_net_cutoff: float = 2.0,
|
|
52
|
+
) -> pd.DataFrame:
|
|
53
|
+
"""
|
|
54
|
+
Classifies banks into Systemically Important Financial Institutions (SIFIs)
|
|
55
|
+
based on Net Transmitted Risk (NET > 0) and Hub Centrality.
|
|
56
|
+
"""
|
|
57
|
+
banks = list(net_spillovers.keys())
|
|
58
|
+
assets = asset_weights or DEFAULT_ASSET_WEIGHTS
|
|
59
|
+
|
|
60
|
+
records = []
|
|
61
|
+
for b in banks:
|
|
62
|
+
net = net_spillovers.get(b, 0.0)
|
|
63
|
+
hub = (hub_scores or {}).get(b, 0.0)
|
|
64
|
+
asset = assets.get(b, 100.0)
|
|
65
|
+
|
|
66
|
+
is_sifi = (net >= sifi_net_cutoff) or (hub >= 5.0 and asset >= 500.0)
|
|
67
|
+
records.append({
|
|
68
|
+
"bank": b,
|
|
69
|
+
"net_spillover": round(net, 2),
|
|
70
|
+
"hub_score": round(hub, 2),
|
|
71
|
+
"asset_trillion_vnd": asset,
|
|
72
|
+
"sifi_status": "SIFI_CRITICAL" if is_sifi else "NON_SIFI",
|
|
73
|
+
"recommended_capital_buffer": "1.50%" if is_sifi and asset > 1500 else ("1.00%" if is_sifi else "0.00%"),
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
df = pd.DataFrame(records)
|
|
77
|
+
return df.sort_values(by="net_spillover", ascending=False).reset_index(drop=True)
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NIRVANA DOMAIN MODULE: CONSUMER & RETAIL ECONOMETRICS
|
|
3
|
+
======================================================
|
|
4
|
+
Translates Nirvana directed lead-lag networks and Base-12 harmonic manifolds
|
|
5
|
+
into consumer economics intelligence:
|
|
6
|
+
- Essential Consumer Staples vs. Discretionary / Luxury Goods
|
|
7
|
+
- Base-12 Lunar Calendar & Seasonal Consumption Spikes (Tết, Back-to-school)
|
|
8
|
+
- Cost-push Pass-through vs. Demand-pull Shock Propagation
|
|
9
|
+
- Consumer Sentiment & Purchasing Power Elasticity
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from typing import Dict, List, Optional, Any
|
|
13
|
+
import numpy as np
|
|
14
|
+
import pandas as pd
|
|
15
|
+
|
|
16
|
+
DEFAULT_CONSUMER_CATEGORIES: Dict[str, str] = {
|
|
17
|
+
# Consumer Staples (Hàng Tiêu dùng Thiết yếu - Co giãn cầu thấp)
|
|
18
|
+
"VNM": "Staples_Dairy",
|
|
19
|
+
"MSN": "Staples_Integrated_FMCG",
|
|
20
|
+
"SAB": "Staples_Beverages",
|
|
21
|
+
"KDC": "Staples_Food_Oils",
|
|
22
|
+
"QNS": "Staples_Sugar_Soymilk",
|
|
23
|
+
"DBC": "Staples_Protein_Agri",
|
|
24
|
+
"BAF": "Staples_Protein_3F",
|
|
25
|
+
|
|
26
|
+
# Consumer Discretionary & Retail (Hàng Tiêu dùng Không thiết yếu & Bán lẻ - Co giãn cầu cao)
|
|
27
|
+
"MWG": "Discretionary_Retail_Electronics",
|
|
28
|
+
"PNJ": "Discretionary_Luxury_Jewelry",
|
|
29
|
+
"FRT": "Discretionary_Healthcare_Tech",
|
|
30
|
+
"DGW": "Discretionary_Distribution_ICT",
|
|
31
|
+
"VRE": "Discretionary_Retail_RealEstate",
|
|
32
|
+
"PET": "Discretionary_Distribution_Petro",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
DEFAULT_EXPENDITURE_WEIGHTS: Dict[str, float] = {
|
|
36
|
+
"VNM": 85.0, # Market Cap / Revenue scale proxy (Thousand Billion VND)
|
|
37
|
+
"MSN": 110.0,
|
|
38
|
+
"MWG": 70.0,
|
|
39
|
+
"PNJ": 35.0,
|
|
40
|
+
"SAB": 75.0,
|
|
41
|
+
"VRE": 45.0,
|
|
42
|
+
"FRT": 25.0,
|
|
43
|
+
"DGW": 12.0,
|
|
44
|
+
"KDC": 15.0,
|
|
45
|
+
"QNS": 18.0,
|
|
46
|
+
"DBC": 14.0,
|
|
47
|
+
"BAF": 8.0,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def analyze_consumer_dynamics(
|
|
52
|
+
report: Any,
|
|
53
|
+
categories: Optional[Dict[str, str]] = None,
|
|
54
|
+
expenditure_weights: Optional[Dict[str, float]] = None
|
|
55
|
+
) -> Dict[str, Any]:
|
|
56
|
+
"""
|
|
57
|
+
Translates systemic risk report into consumer & retail econometric insights.
|
|
58
|
+
|
|
59
|
+
Parameters:
|
|
60
|
+
- report: SystemicRiskReport from NirvanaConnectedness.fit()
|
|
61
|
+
- categories: Mapping of {ticker: category_name}
|
|
62
|
+
- expenditure_weights: Scale proxy for market footprint
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
- Structured dictionary with category-level spillovers, demand leaders, and resilience rankings.
|
|
66
|
+
"""
|
|
67
|
+
cats = categories or DEFAULT_CONSUMER_CATEGORIES
|
|
68
|
+
weights = expenditure_weights or DEFAULT_EXPENDITURE_WEIGHTS
|
|
69
|
+
|
|
70
|
+
net_spillovers = report.net_spillovers
|
|
71
|
+
hubs = report.eigenvector_hub
|
|
72
|
+
authorities = report.eigenvector_authority
|
|
73
|
+
|
|
74
|
+
# Aggregate by category: Staples vs Discretionary
|
|
75
|
+
staples_net: List[float] = []
|
|
76
|
+
discretionary_net: List[float] = []
|
|
77
|
+
category_summary: Dict[str, List[float]] = {}
|
|
78
|
+
|
|
79
|
+
for node, net_val in net_spillovers.items():
|
|
80
|
+
cat = cats.get(node, "Other")
|
|
81
|
+
category_summary.setdefault(cat, []).append(net_val)
|
|
82
|
+
if "Staples" in cat:
|
|
83
|
+
staples_net.append(net_val)
|
|
84
|
+
elif "Discretionary" in cat:
|
|
85
|
+
discretionary_net.append(net_val)
|
|
86
|
+
|
|
87
|
+
mean_staples = float(np.mean(staples_net)) if staples_net else 0.0
|
|
88
|
+
mean_discretionary = float(np.mean(discretionary_net)) if discretionary_net else 0.0
|
|
89
|
+
|
|
90
|
+
# Categorize roles:
|
|
91
|
+
# 1. Cost-Push / Pricing Power Transmitters (NET > 0 and high Hub)
|
|
92
|
+
pricing_leaders = [
|
|
93
|
+
node for node in report.top_transmitters
|
|
94
|
+
if "Staples" in cats.get(node, "")
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
# 2. Purchasing Power Bellwethers (high Hub in Discretionary)
|
|
98
|
+
discretionary_bellwethers = [
|
|
99
|
+
node for node in report.top_transmitters
|
|
100
|
+
if "Discretionary" in cats.get(node, "")
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
# 3. Demand Absorbers (NET < 0)
|
|
104
|
+
demand_absorbers = report.top_receivers
|
|
105
|
+
|
|
106
|
+
# 4. Resilience Ranking (Flight-to-Safety if present, else low authority)
|
|
107
|
+
resilience_ranking: List[str] = []
|
|
108
|
+
if hasattr(report, "flight_to_safety_index") and report.flight_to_safety_index:
|
|
109
|
+
resilience_ranking = sorted(
|
|
110
|
+
report.flight_to_safety_index.keys(),
|
|
111
|
+
key=lambda k: report.flight_to_safety_index[k],
|
|
112
|
+
reverse=True
|
|
113
|
+
)
|
|
114
|
+
else:
|
|
115
|
+
resilience_ranking = sorted(
|
|
116
|
+
authorities.keys(),
|
|
117
|
+
key=lambda k: authorities[k]
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
"staples_mean_net_spillover": round(mean_staples, 2),
|
|
122
|
+
"discretionary_mean_net_spillover": round(mean_discretionary, 2),
|
|
123
|
+
"dominant_regime": (
|
|
124
|
+
"Cost-Push Inflation (Staples Leading)"
|
|
125
|
+
if mean_staples > mean_discretionary
|
|
126
|
+
else "Discretionary Demand-Pull (Discretionary Leading)"
|
|
127
|
+
),
|
|
128
|
+
"pricing_power_leaders": pricing_leaders,
|
|
129
|
+
"discretionary_bellwethers": discretionary_bellwethers,
|
|
130
|
+
"most_vulnerable_demand_absorbers": demand_absorbers[:5],
|
|
131
|
+
"top_resilient_staples": [n for n in resilience_ranking if "Staples" in cats.get(n, "")][:5],
|
|
132
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Nirvana Domain Module: Cybersecurity & Network Infrastructure Contagion
|
|
3
|
+
========================================================================
|
|
4
|
+
Applies Nirvana causal graph connectedness to:
|
|
5
|
+
- Autonomous System (AS) / BGP route flapping and traffic spillover
|
|
6
|
+
- DDoS amplification hub detection & botnet synchronization tracking
|
|
7
|
+
- Subnet bottleneck / bridge identification (Betweenness centrality)
|
|
8
|
+
- Vulnerability sink / target server identification (Authority centrality)
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from typing import Dict, List, Optional
|
|
12
|
+
import numpy as np
|
|
13
|
+
import pandas as pd
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def analyze_cyber_contagion(
|
|
17
|
+
spillover_report,
|
|
18
|
+
ip_or_node_metadata: Optional[Dict[str, Dict]] = None,
|
|
19
|
+
ddos_hub_cutoff: float = 4.0,
|
|
20
|
+
) -> pd.DataFrame:
|
|
21
|
+
"""
|
|
22
|
+
Translates a Nirvana systemic risk report into cybersecurity topology metrics:
|
|
23
|
+
- Attack / Amplification Hub: High out-degree shock transmitter
|
|
24
|
+
- Critical Target / Vulnerable Sink: High in-degree authority receiver
|
|
25
|
+
- Chokepoint / Bridge Node: High betweenness centrality router
|
|
26
|
+
"""
|
|
27
|
+
nodes = list(spillover_report.net_spillovers.keys())
|
|
28
|
+
meta = ip_or_node_metadata or {}
|
|
29
|
+
|
|
30
|
+
records = []
|
|
31
|
+
for node in nodes:
|
|
32
|
+
net = spillover_report.net_spillovers.get(node, 0.0)
|
|
33
|
+
hub = (spillover_report.eigenvector_hub or {}).get(node, 0.0)
|
|
34
|
+
auth = (spillover_report.eigenvector_authority or {}).get(node, 0.0)
|
|
35
|
+
bc = (spillover_report.betweenness_centrality or {}).get(node, 0.0)
|
|
36
|
+
|
|
37
|
+
node_type = "UNKNOWN"
|
|
38
|
+
if hub >= ddos_hub_cutoff and net > 0:
|
|
39
|
+
node_type = "AMPLIFICATION_SOURCE / BOTNET_HUB"
|
|
40
|
+
elif auth >= ddos_hub_cutoff and net < 0:
|
|
41
|
+
node_type = "CRITICAL_TARGET / AT_RISK_SINK"
|
|
42
|
+
elif bc >= 10.0:
|
|
43
|
+
node_type = "INFRASTRUCTURE_CHOKEPOINT"
|
|
44
|
+
else:
|
|
45
|
+
node_type = "NORMAL_TRANSIT"
|
|
46
|
+
|
|
47
|
+
records.append({
|
|
48
|
+
"node": node,
|
|
49
|
+
"net_flow_shock": round(net, 2),
|
|
50
|
+
"hub_score": round(hub, 2),
|
|
51
|
+
"sink_authority_score": round(auth, 2),
|
|
52
|
+
"betweenness_bottleneck": round(bc, 2),
|
|
53
|
+
"cyber_classification": node_type,
|
|
54
|
+
"action_priority": "URGENT_ISOLATE" if "AMPLIFICATION" in node_type or "CRITICAL_TARGET" in node_type else "MONITOR",
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
df = pd.DataFrame(records)
|
|
58
|
+
return df.sort_values(by="hub_score", ascending=False).reset_index(drop=True)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NIRVANA DOMAIN EXTENSION: MICRO-ECONOMETRIC PRODUCT SUBSTITUTION
|
|
3
|
+
=================================================================
|
|
4
|
+
Specialized domain module for analyzing cross-price elasticity,
|
|
5
|
+
budget constraint binding thresholds, and consumer brand/product switching.
|
|
6
|
+
|
|
7
|
+
Author: yinyusi65 & Nirvana Quant Team
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from typing import Any, Dict, List, Optional
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
DEFAULT_PROTEIN_SUBSTITUTE_ROLES = {
|
|
15
|
+
"Pork_3F": "Anchor Good (Primary Household Staple)",
|
|
16
|
+
"Chicken_CP": "Close Substitute (Budget-Conscious Protein Alternative)",
|
|
17
|
+
"Eggs": "Secondary Macro-Buffer (Low-Cost Calorie Cushion)",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def analyze_substitution_thresholds(report: Any) -> Dict[str, Any]:
|
|
22
|
+
"""
|
|
23
|
+
Extracts structural micro-econometric switching thresholds from
|
|
24
|
+
a fitted Nirvana StaticEconometricReport.
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
report : StaticEconometricReport
|
|
29
|
+
The report object returned by NirvanaStaticBooster.fit().
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
Dict[str, Any]
|
|
34
|
+
Dictionary containing extracted price ratio triggers, binding income
|
|
35
|
+
cutoffs, and economic interpretations.
|
|
36
|
+
"""
|
|
37
|
+
threshold_rules = getattr(report, "top_substitution_thresholds", [])
|
|
38
|
+
feat_importances = getattr(report, "feature_importances", {})
|
|
39
|
+
|
|
40
|
+
# Detect dominant splitting features
|
|
41
|
+
top_driver = list(feat_importances.keys())[0] if feat_importances else "Unknown"
|
|
42
|
+
|
|
43
|
+
# Identify primary switching boundaries from rule descriptions
|
|
44
|
+
critical_price_ratio = None
|
|
45
|
+
binding_income_threshold = None
|
|
46
|
+
|
|
47
|
+
for rule in threshold_rules:
|
|
48
|
+
rule_lower = rule.lower()
|
|
49
|
+
if "ratio" in rule_lower and critical_price_ratio is None:
|
|
50
|
+
# Parse threshold number
|
|
51
|
+
try:
|
|
52
|
+
parts = rule.split("<=")
|
|
53
|
+
if len(parts) > 1:
|
|
54
|
+
val_str = parts[1].split()[0]
|
|
55
|
+
critical_price_ratio = float(val_str)
|
|
56
|
+
except Exception:
|
|
57
|
+
pass
|
|
58
|
+
elif "income" in rule_lower and binding_income_threshold is None:
|
|
59
|
+
try:
|
|
60
|
+
parts = rule.split("<=")
|
|
61
|
+
if len(parts) > 1:
|
|
62
|
+
val_str = parts[1].split()[0]
|
|
63
|
+
binding_income_threshold = float(val_str)
|
|
64
|
+
except Exception:
|
|
65
|
+
pass
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
"primary_non_linear_driver": top_driver,
|
|
69
|
+
"critical_price_ratio_trigger": critical_price_ratio,
|
|
70
|
+
"binding_income_threshold_million_vnd": binding_income_threshold,
|
|
71
|
+
"r2_phase1_linear_baseline": getattr(report, "r2_phase1", 0.0),
|
|
72
|
+
"r2_phase2_nirvana_enhanced": getattr(report, "r2_phase2", 0.0),
|
|
73
|
+
"unexplained_variance_resolved_pct": getattr(report, "r2_relative_improvement_pct", 0.0),
|
|
74
|
+
"economic_regime": (
|
|
75
|
+
"Threshold-Driven Budget Substitution"
|
|
76
|
+
if getattr(report, "r2_gain", 0.0) > 0.15
|
|
77
|
+
else "Linear Proportional Substitution"
|
|
78
|
+
),
|
|
79
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Nirvana Domain Module: Supply Chain & Industrial Contagion
|
|
3
|
+
===========================================================
|
|
4
|
+
Applies Nirvana causal graph connectedness to:
|
|
5
|
+
- Bullwhip effect propagation across multi-tier supplier networks
|
|
6
|
+
- Bottleneck supplier identification (Component shortage risk)
|
|
7
|
+
- Lead-time volatility cascading across industrial sectors
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from typing import Dict, List, Optional
|
|
11
|
+
import numpy as np
|
|
12
|
+
import pandas as pd
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def analyze_supply_chain_risk(
|
|
16
|
+
spillover_report,
|
|
17
|
+
tier_levels: Optional[Dict[str, int]] = None,
|
|
18
|
+
) -> pd.DataFrame:
|
|
19
|
+
"""
|
|
20
|
+
Translates Nirvana connectedness metrics into supply chain risk indicators:
|
|
21
|
+
- Shock Originator (Upstream Bullwhip Emitter): High net transmitter
|
|
22
|
+
- Vulnerable Assembler (Downstream Receiver): High authority receiver
|
|
23
|
+
- Strategic Bottleneck: High betweenness bridging critical tiers
|
|
24
|
+
"""
|
|
25
|
+
nodes = list(spillover_report.net_spillovers.keys())
|
|
26
|
+
tiers = tier_levels or {}
|
|
27
|
+
|
|
28
|
+
records = []
|
|
29
|
+
for node in nodes:
|
|
30
|
+
net = spillover_report.net_spillovers.get(node, 0.0)
|
|
31
|
+
hub = (spillover_report.eigenvector_hub or {}).get(node, 0.0)
|
|
32
|
+
auth = (spillover_report.eigenvector_authority or {}).get(node, 0.0)
|
|
33
|
+
bc = (spillover_report.betweenness_centrality or {}).get(node, 0.0)
|
|
34
|
+
|
|
35
|
+
tier = tiers.get(node, 1)
|
|
36
|
+
role = "REGULAR_SUPPLIER"
|
|
37
|
+
if hub >= 5.0 and net > 0:
|
|
38
|
+
role = "BULLWHIP_ORIGINATOR (UPSTREAM RISK)"
|
|
39
|
+
elif auth >= 5.0 and net < 0:
|
|
40
|
+
role = "HIGH_VULNERABILITY_ASSEMBLER"
|
|
41
|
+
elif bc >= 10.0:
|
|
42
|
+
role = "SOLE_SOURCE_BOTTLENECK"
|
|
43
|
+
|
|
44
|
+
records.append({
|
|
45
|
+
"supplier_or_tier": node,
|
|
46
|
+
"tier_level": tier,
|
|
47
|
+
"net_spillover": round(net, 2),
|
|
48
|
+
"hub_emitter_score": round(hub, 2),
|
|
49
|
+
"vulnerability_sink_score": round(auth, 2),
|
|
50
|
+
"bottleneck_centrality": round(bc, 2),
|
|
51
|
+
"strategic_role": role,
|
|
52
|
+
"buffer_stock_recommendation": "INCREASE_SAFETY_STOCK" if "BULLWHIP" in role or "BOTTLENECK" in role else "STANDARD_JIT",
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
df = pd.DataFrame(records)
|
|
56
|
+
return df.sort_values(by="bottleneck_centrality", ascending=False).reset_index(drop=True)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NIRVANA EXPERIMENTAL LAB
|
|
3
|
+
========================
|
|
4
|
+
Isolated incubator for frontier, non-production econometric research algorithms:
|
|
5
|
+
- Multiverse Invariant Causal Feature Extraction (Champion Variable Discovery)
|
|
6
|
+
- High-order interaction lattice exploration
|
|
7
|
+
- Non-linear symbolic manifold distillation
|
|
8
|
+
|
|
9
|
+
Author: yinyusi65
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from .multiverse_invariance import (
|
|
13
|
+
MultiverseChampionExtractor,
|
|
14
|
+
MultiverseChampionReport,
|
|
15
|
+
ChampionVariable,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"MultiverseChampionExtractor",
|
|
20
|
+
"MultiverseChampionReport",
|
|
21
|
+
"ChampionVariable",
|
|
22
|
+
]
|