-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Various portfolio/po issues (#3286)
* Allow for loading without -f flag * Massive upgrade to params file read/write * Better handling empty dfs and none in prompt toolkit * Fix tr typing and handle none error * Added options * Fixed tests Co-authored-by: James Maslek <jmaslek11@gmail.com>
- Loading branch information
Showing
13 changed files
with
395 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
openbb_terminal/portfolio/portfolio_optimization/parameters/params_helpers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import argparse | ||
from typing import Dict | ||
from pathlib import Path | ||
from openbb_terminal.helper_funcs import log_and_raise | ||
from openbb_terminal.core.config import paths | ||
|
||
|
||
def check_save_file(file: str) -> str: | ||
"""Argparse type to check parameter file to be saved""" | ||
if file == "defaults.ini": | ||
log_and_raise( | ||
argparse.ArgumentTypeError( | ||
"Cannot overwrite defaults.ini file, please save with a different name" | ||
) | ||
) | ||
else: | ||
if not file.endswith(".ini"): | ||
log_and_raise( | ||
argparse.ArgumentTypeError("File to be saved needs to be .ini") | ||
) | ||
|
||
return file | ||
|
||
|
||
def load_data_files() -> Dict[str, Path]: | ||
"""Loads files from the misc directory and from the user's custom exports | ||
Returns | ||
---------- | ||
Dict[str, Path] | ||
The dictionary of filenames and their paths | ||
""" | ||
default_path = paths.MISCELLANEOUS_DIRECTORY / "portfolio_examples" / "optimization" | ||
custom_exports = paths.USER_EXPORTS_DIRECTORY / "portfolio" | ||
data_files = {} | ||
for directory in [default_path, custom_exports]: | ||
for file_type in ["xlsx", "ini"]: | ||
for filepath in Path(directory).rglob(f"*.{file_type}"): | ||
if filepath.is_file(): | ||
data_files[filepath.name] = filepath | ||
|
||
return data_files |
Oops, something went wrong.