Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding data range for VaR #2087

Merged
merged 2 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions openbb_terminal/common/quantitative_analysis/qa_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:"

Expand Down
15 changes: 15 additions & 0 deletions openbb_terminal/stocks/quantitative_analysis/qa_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
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__)


Expand Down Expand Up @@ -800,6 +802,18 @@ def call_var(self, other_args: List[str]):
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:
Expand All @@ -812,6 +826,7 @@ def call_var(self, other_args: List[str]):
ns_parser.adjusted,
ns_parser.student_t,
ns_parser.percentile / 100,
ns_parser.data_range,
False,
)

Expand Down