|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from typing import Optional |
| 4 | +import logging |
4 | 5 |
|
5 | 6 | import pandas as pd |
6 | 7 | import numpy as np |
|
13 | 14 | from okama.portfolios import dcf as dcf |
14 | 15 | from okama.common.helpers import tails, helpers |
15 | 16 |
|
| 17 | +# Module-level logger |
| 18 | +logger = logging.getLogger(__name__) |
| 19 | + |
16 | 20 |
|
17 | 21 | class MonteCarlo: |
18 | 22 | """ |
@@ -739,8 +743,6 @@ def kstest_for_all_distributions(self) -> pd.DataFrame: |
739 | 743 | ks_results.append(helpers.Frame.kstest_series(self.ror, distr=d)) |
740 | 744 | return pd.DataFrame(ks_results, index=settings.distributions) |
741 | 745 |
|
742 | | - |
743 | | - |
744 | 746 | # Plots |
745 | 747 | def plot_qq( |
746 | 748 | self, |
@@ -882,11 +884,21 @@ def plot_qq( |
882 | 884 | plt.tight_layout() |
883 | 885 | plt.title(title) |
884 | 886 | plt.show() |
885 | | - # TODO: change print by logger |
886 | | - print(f"VaR {alpha:.0%}: theor={var_theor:.6f}, emp={var_emp:.6f}, delta(emp-theor)={var_emp - var_theor:.6f}") |
887 | | - print(f"CVAR {alpha:.0%}: theor={cvar_theor:.6f}, emp={cvar_emp:.6f}, delta(emp-theor)={cvar_emp - cvar_theor:.6f}") |
888 | | - print(f'95% CI empiric VaR (bootstrap): [{var_ci[0]:.6f}, {var_ci[1]:.6f}]') |
889 | | - print(f'95% CI empiric CVaR (bootstrap): [{cvar_ci[0]:.6f}, {cvar_ci[1]:.6f}]') |
| 887 | + # Log metrics using f-strings |
| 888 | + logger.info( |
| 889 | + f"VaR {alpha:.0%}: theor={var_theor:.6f}, emp={var_emp:.6f}, delta(emp-theor)={(var_emp - var_theor):.6f}" |
| 890 | + ) |
| 891 | + logger.info( |
| 892 | + f"CVAR {alpha:.0%}: theor={cvar_theor:.6f}, emp={cvar_emp:.6f}, delta(emp-theor)={(cvar_emp - cvar_theor):.6f}" |
| 893 | + ) |
| 894 | + # Log bootstrap confidence intervals only if they were computed |
| 895 | + if bootstrap_size_var: |
| 896 | + logger.info( |
| 897 | + f"95% CI empiric VaR (bootstrap): [{var_ci[0]:.6f}, {var_ci[1]:.6f}]" |
| 898 | + ) |
| 899 | + logger.info( |
| 900 | + f"95% CI empiric CVaR (bootstrap): [{cvar_ci[0]:.6f}, {cvar_ci[1]:.6f}]" |
| 901 | + ) |
890 | 902 |
|
891 | 903 | def plot_hist_fit(self, bins: int = None) -> None: |
892 | 904 | """ |
|
0 commit comments