Skip to content

Commit 242add3

Browse files
committed
chore: switch to logging from print in MonteCarlo.plot_qq()
1 parent a6682de commit 242add3

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

okama/portfolios/mc.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from typing import Optional
4+
import logging
45

56
import pandas as pd
67
import numpy as np
@@ -13,6 +14,9 @@
1314
from okama.portfolios import dcf as dcf
1415
from okama.common.helpers import tails, helpers
1516

17+
# Module-level logger
18+
logger = logging.getLogger(__name__)
19+
1620

1721
class MonteCarlo:
1822
"""
@@ -739,8 +743,6 @@ def kstest_for_all_distributions(self) -> pd.DataFrame:
739743
ks_results.append(helpers.Frame.kstest_series(self.ror, distr=d))
740744
return pd.DataFrame(ks_results, index=settings.distributions)
741745

742-
743-
744746
# Plots
745747
def plot_qq(
746748
self,
@@ -882,11 +884,21 @@ def plot_qq(
882884
plt.tight_layout()
883885
plt.title(title)
884886
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+
)
890902

891903
def plot_hist_fit(self, bins: int = None) -> None:
892904
"""

0 commit comments

Comments
 (0)