File size: 1,993 Bytes
558db1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def build_econometric_validation_html(dm_results, var_results):
    validation_html = ""
    if dm_results or var_results:
        val_rows = ""
        if dm_results:
            dm_pass = dm_results.get('significant', False) and dm_results.get('winner') == 'Model 1'
            dm_col  = "#3fb950" if dm_pass else "#e3b341"
            val_rows += (
                f'<div class="mc"><div class="ml" title="Diebold-Mariano Test: Does the ML model statistically beat a naive historical baseline?">'
                f'Predictive Alpha (DM Test) &#9432;</div>'
                f'<div class="mv" style="color:{dm_col}">{"PASS" if dm_pass else "INCONCLUSIVE"}</div>'
                f'<div class="ml" style="margin-top:4px">p = {dm_results.get("p_value", 1.0):.4f}</div></div>'
            )
        if var_results:
            var_pass = var_results.get('overall_pass', False)
            var_col  = "#3fb950" if var_pass else "#f85149"
            uc_p  = var_results.get('unconditional_coverage', {}).get('p_value', 0.0)
            ind_p = var_results.get('independence', {}).get('p_value', 0.0)
            diag_text = var_results.get('diagnostic', '')
            val_rows += (
                f'<div class="mc"><div class="ml" title="Christoffersen Test: Does the VaR limit hold up against real-world volatility clustering?">'
                f'Tail Risk Validity (VaR) &#9432;</div>'
                f'<div class="mv" style="color:{var_col}">{"PASS" if var_pass else "FAIL"}</div>'
                f'<div class="ml" style="margin-top:4px">Coverage p = {uc_p:.4f} &nbsp;|&nbsp; Independence p = {ind_p:.4f}</div>'
                + (f'<div class="ml" style="margin-top:2px;color:#8b949e;font-size:.72rem">{diag_text}</div>' if diag_text and not var_pass else '')
                + '</div>'
            )
        validation_html = (
            '<p class="st">Econometric Validation (Out-of-Sample)</p>'
            f'<div class="mg">{val_rows}</div>'
        )
    return validation_html