mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 21:42:22 +00:00
adding data range for VaR (#2087)
* adding data range for VaR * Update qa_controller.py
This commit is contained in:
@@ -995,6 +995,7 @@ def display_var(
|
||||
adjusted_var: bool = False,
|
||||
student_t: bool = False,
|
||||
percentile: float = 0.999,
|
||||
data_range: int = 0,
|
||||
portfolio: bool = False,
|
||||
):
|
||||
"""Displays VaR of dataframe
|
||||
@@ -1013,12 +1014,20 @@ def display_var(
|
||||
If one should use the student-t distribution
|
||||
percentile: int
|
||||
var percentile
|
||||
data_range: int
|
||||
Number of rows you want to use VaR over
|
||||
portfolio: bool
|
||||
If the data is a portfolio
|
||||
"""
|
||||
var_list, hist_var_list = qa_model.get_var(
|
||||
data, use_mean, adjusted_var, student_t, percentile, portfolio
|
||||
)
|
||||
|
||||
if data_range > 0:
|
||||
var_list, hist_var_list = qa_model.get_var(
|
||||
data[-data_range:], use_mean, adjusted_var, student_t, percentile, portfolio
|
||||
)
|
||||
else:
|
||||
var_list, hist_var_list = qa_model.get_var(
|
||||
data, use_mean, adjusted_var, student_t, percentile, portfolio
|
||||
)
|
||||
|
||||
str_hist_label = "Historical VaR:"
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ from openbb_terminal.parent_classes import StockBaseController
|
||||
from openbb_terminal.rich_config import console, MenuText
|
||||
from openbb_terminal.stocks.quantitative_analysis.factors_view import capm_view
|
||||
|
||||
# pylint: disable=C0302
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -800,6 +802,18 @@ class QaController(StockBaseController):
|
||||
Percentile used for VaR calculations, for example input 99.9 equals a 99.9 Percent VaR
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-d",
|
||||
"--datarange",
|
||||
action="store",
|
||||
dest="data_range",
|
||||
type=int,
|
||||
default=0,
|
||||
help="""
|
||||
Number of rows you want to use VaR over,
|
||||
ex: if you are using days, 30 would show VaR for the last 30 TRADING days
|
||||
""",
|
||||
)
|
||||
ns_parser = self.parse_known_args_and_warn(parser, other_args)
|
||||
if ns_parser:
|
||||
if ns_parser.adjusted and ns_parser.student_t:
|
||||
@@ -812,6 +826,7 @@ class QaController(StockBaseController):
|
||||
ns_parser.adjusted,
|
||||
ns_parser.student_t,
|
||||
ns_parser.percentile / 100,
|
||||
ns_parser.data_range,
|
||||
False,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user