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 new portfolio metrics #2029

Merged
merged 42 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
dddcba3
Making pa active + pa minor features
northern-64bit Jan 2, 2022
818c931
Fix linting
northern-64bit Jan 2, 2022
b7a7882
Merge branch 'GamestonkTerminal:main' into main
northern-64bit Jan 2, 2022
ed957ef
black linter
DidierRLopes Jan 4, 2022
3da6860
Merge pull request #2 from GamestonkTerminal/1134
northern-64bit Jan 6, 2022
d7060a1
Fixes
northern-64bit Jan 8, 2022
31bc1b6
Linting
northern-64bit Jan 8, 2022
43ae0cb
Making pa controller to base class standard
northern-64bit Jan 9, 2022
7b116b8
Merge branch 'main' into main
northern-64bit Jan 9, 2022
dedb080
Fix linting
northern-64bit Jan 9, 2022
45c371b
Merge branch 'GamestonkTerminal:main' into main
northern-64bit Jan 11, 2022
c662c06
Merge branch 'GamestonkTerminal:main' into main
northern-64bit Jan 27, 2022
dee8f64
Merge branch 'GamestonkTerminal:main' into main
northern-64bit Feb 3, 2022
b670930
Merge branch 'GamestonkTerminal:main' into main
northern-64bit Feb 26, 2022
d3c6883
Merge branch 'GamestonkTerminal:main' into main
northern-64bit Mar 8, 2022
3764b5f
Merge branch 'OpenBB-finance:main' into main
northern-64bit Jun 7, 2022
1c7a9e8
Merge branch 'main' of https://github.com/northern-64bit/GamestonkTer…
northern-64bit Jun 11, 2022
317dabb
Merge branch 'OpenBB-finance:main' into main
northern-64bit Jun 11, 2022
f9a54b2
Merge branch 'main' of https://github.com/northern-64bit/GamestonkTer…
northern-64bit Jun 11, 2022
41ee276
first metrics
northern-64bit Jun 30, 2022
29652af
Adding calmar ratio
northern-64bit Jun 30, 2022
e9d7e49
Adding metrics to controller
northern-64bit Jul 2, 2022
b98c8a1
Linting
northern-64bit Jul 2, 2022
6ba454d
Linting
northern-64bit Jul 2, 2022
a1b5cca
Test fixes
northern-64bit Jul 2, 2022
6f36908
Test fixes
northern-64bit Jul 2, 2022
a0540dd
Merge branch 'main' into portfolio_metrics
northern-64bit Jul 2, 2022
8c977c9
Adding tests
northern-64bit Jul 2, 2022
d730f66
Merge branch 'main' into portfolio_metrics
northern-64bit Jul 2, 2022
2f7d149
Linting
northern-64bit Jul 2, 2022
a0ebfa7
Merge branch 'portfolio_metrics' of github.com:northern-64bit/Gamesto…
northern-64bit Jul 2, 2022
52a8ddb
Restructuring added tests
northern-64bit Jul 2, 2022
e43eadb
Linting
northern-64bit Jul 2, 2022
02108cd
Updating hugo website and fixing help
northern-64bit Jul 4, 2022
3559b56
Merge branch 'main' into portfolio_metrics
northern-64bit Jul 4, 2022
282f9a0
Fixing commands
northern-64bit Jul 4, 2022
ea09aed
Fix kelly criterion command
northern-64bit Jul 5, 2022
0b7db8a
Merge branch 'main' into portfolio_metrics
JerBouma Jul 6, 2022
e50daa6
Merge branch 'main' into portfolio_metrics
northern-64bit Jul 6, 2022
c49ef21
Fixing tests
northern-64bit Jul 6, 2022
d064195
Linting
northern-64bit Jul 6, 2022
f97d37e
More linting
northern-64bit Jul 6, 2022
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
57 changes: 52 additions & 5 deletions openbb_terminal/portfolio/portfolio_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ class PortfolioController(BaseController):
"rsquare",
"skew",
"kurtosis",
"gaintopain",
"trackerr",
"information",
"tail",
"commonsense",
"jensens",
"calmar",
"kelly",
"payoff",
"profitfactor",
]
PATH = "/portfolio/"

Expand Down Expand Up @@ -771,10 +781,9 @@ def call_om(self, other_args: List[str]):
ns_parser.end,
)
else:
if not self.portfolio_name:
console.print(
"[red]Please first define the portfolio (via 'load')[/red]\n"
)
console.print(
"[red]Please first define the portfolio (via 'load')[/red]\n"
)

@log_start_end(log=logger)
def call_cret(self, other_args: List[str]):
Expand Down Expand Up @@ -1133,7 +1142,7 @@ def call_metric(self, other_args: List[str]):
dest="metric",
default="-h" not in other_args,
choices=self.VALID_METRICS,
help="Period to apply rolling window",
help="Set metric of choice",
)
parser.add_argument(
"-r",
Expand Down Expand Up @@ -1172,6 +1181,44 @@ def call_metric(self, other_args: List[str]):
)
elif ns_parser.metric == "rsquare":
portfolio_view.display_rsquare(self.portfolio, ns_parser.export)
elif ns_parser.metric == "gaintopain":
portfolio_view.display_gaintopain_ratio(
self.portfolio, ns_parser.export
)
elif ns_parser.metric == "trackerr":
portfolio_view.display_tracking_error(
self.portfolio, ns_parser.export
)
elif ns_parser.metric == "information":
portfolio_view.display_information_ratio(
self.portfolio, ns_parser.export
)
elif ns_parser.metric == "tail":
portfolio_view.display_tail_ratio(self.portfolio, ns_parser.export)
elif ns_parser.metric == "commonsense":
portfolio_view.display_common_sense_ratio(
self.portfolio, ns_parser.export
)
elif ns_parser.metric == "jensens":
portfolio_view.display_jensens_alpha(
self.portfolio, ns_parser.risk_free_rate, ns_parser.export
)
elif ns_parser.metric == "calmar":
portfolio_view.display_calmar_ratio(
self.portfolio, ns_parser.export
)
elif ns_parser.metric == "kelly":
portfolio_view.display_kelly_criterion(
self.portfolio, ns_parser.export
)
elif ns_parser.metric == "payoff":
portfolio_view.display_payoff_ratio(
self.portfolio, ns_parser.export
)
elif ns_parser.metric == "profitfactor":
portfolio_view.display_profit_factor(
self.portfolio, ns_parser.export
)

@log_start_end(log=logger)
def call_distr(self, other_args: List[str]):
Expand Down
16 changes: 14 additions & 2 deletions openbb_terminal/portfolio/portfolio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,19 @@

PERIODS = ["mtd", "qtd", "ytd", "3m", "6m", "1y", "3y", "5y", "10y", "all"]

now = datetime.now()
PERIODS_DAYS = {
"mtd": (now - datetime(now.year, now.month, 1)).days,
"qtd": (
now
- datetime(
now.year,
1 if now.month < 4 else 4 if now.month < 7 else 7 if now.month < 7 else 10,
1,
)
).days,
"ytd": (now - datetime(now.year, 1, 1)).days,
"all": 0,
"3m": 3 * 21,
"6m": 6 * 21,
"1y": 12 * 21,
Expand Down Expand Up @@ -194,7 +206,7 @@ def filter_df_by_period(df: pd.DataFrame, period: str = "all") -> pd.DataFrame:

Returns
----------
str
pd.DataFrame
A cleaned value
"""
if period == "mtd":
Expand Down Expand Up @@ -284,7 +296,7 @@ def get_maximum_drawdown(return_series: pd.Series) -> float:
Returns
-------
float
maximum drawdown
Maximum drawdown
"""
comp_ret = (return_series + 1).cumprod()
peak = comp_ret.expanding(min_periods=1).max()
Expand Down
Loading