Skip to content

Commit

Permalink
Merge branch 'main' into feature/BlockchainBlockData
Browse files Browse the repository at this point in the history
  • Loading branch information
noubre authored Dec 13, 2022
2 parents 42a0d40 + 45b4543 commit a2a3a43
Show file tree
Hide file tree
Showing 65 changed files with 2,018 additions and 212 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:
key: ${{ runner.os }}-v1-linting
restore-keys: ${{ runner.os }}-v1-linting

- run: pip install bandit black codespell flake8 mypy==0.982 pyupgrade safety pylint==2.15.2
- run: pip install bandit black codespell flake8 mypy==0.982 pyupgrade safety pylint==2.15.2 packaging==22
- run: pip install types-pytz types-requests types-termcolor types-tabulate types-PyYAML types-python-dateutil types-setuptools types-six
- run: bandit -x ./tests -r . || true
- run: black --diff --check .
- run: codespell --ignore-words-list=commun,statics,ro,zar,zlot,jewl,ba,buil,coo,ether,hist,hsi,mape,navagation,operatio,pres,ser,yeld,shold,ist,varian,datas,ake,creat,vie,hel,ket,toke,certi,buidl,ot --quiet-level=2 --skip=./tests,.git,*.css,*.csv,*.html,*.ini,*.ipynb,*.js,*.json,*.lock,*.scss,*.txt,*.yaml,./build/pyinstaller,./website/config.toml
- run: codespell --ignore-words-list=commun,statics,ro,zar,zlot,jewl,ba,buil,coo,ether,hist,hsi,mape,navagation,operatio,pres,ser,yeld,shold,ist,varian,datas,ake,creat,vie,hel,ket,toke,certi,buidl,ot,te --quiet-level=2 --skip=./tests,.git,*.css,*.csv,*.html,*.ini,*.ipynb,*.js,*.json,*.lock,*.scss,*.txt,*.yaml,./build/pyinstaller,./website/config.toml
- run: flake8 . --count --ignore=E203,W503 --max-line-length=122 --show-source --statistics --exclude ./build/pyinstaller,./website/content
- run: mypy --ignore-missing-imports openbb_terminal
- run: shopt -s globstar && pyupgrade --py38-plus **/*.py
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
entry: codespell
args:
[
"--ignore-words-list=commun,ro,zar,vie,hel,jewl,zlot,ba,buil,coo,ether,hist,hsi,mape,navagation,operatio,pres,ser,yeld,shold,ist,varian,datas,ake,creat,statics,ket,toke,certi,buidl",
"--ignore-words-list=te,commun,ro,zar,vie,hel,jewl,zlot,ba,buil,coo,ether,hist,hsi,mape,navagation,operatio,pres,ser,yeld,shold,ist,varian,datas,ake,creat,statics,ket,toke,certi,buidl",
"--quiet-level=2",
"--skip=./tests,.git,*.css,*.csv,*.html,*.ini,*.ipynb,*.js,*.json,*.lock,*.scss,*.txt,*.yaml,build/pyinstaller/*,./website/config.toml",
]
Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,9 @@ With:

<br>

4. Consistent and clear argument naming; not `symbol` in _view and then `ticker` in `_file` -> ticker everywhere; the name should be descriptive of what information it hold (see Style Guide section below)
4. Consistent and clear argument naming; not `symbol` in `_view` and then `ticker` in `_file` -> ticker everywhere; the name should be descriptive of what information it holds (see Style Guide section below)

- Why? You can quickly understand what the input it should be; example: tickers and stock names are fundamentally different, but they’re both strings so they should be named accordingly.
- Why? You can quickly understand what the input should be; example: tickers and stock names are fundamentally different, but they’re both strings so they should be named accordingly.

<br>

Expand Down Expand Up @@ -796,7 +796,7 @@ With:

- Why? To respect the principles laid out in Code Structure and the previous bullet point. If your code does not have this `get_``display_` map it’s likely that i. and/or ii. fail to hold.

i. Data is processed in _model files and displayed in `_view` files
i. Data is processed in `_model` files and displayed in `_view` files

ii. `_view` and `_model` files will have the same arguments (except for output options)

Expand Down Expand Up @@ -1307,7 +1307,7 @@ The way to interpret this file is by following the path to a data source, e.g.

### Export Data

In the `_view.py` files it is common having at the end of each function `export_data` being called. This tipycally looks like:
In the `_view.py` files it is common having at the end of each function `export_data` being called. This typically looks like:

```python
export_data(
Expand Down Expand Up @@ -1512,7 +1512,7 @@ Install the pre-commit hooks by running: `pre-commit install`.

### Coding

Although the Coding Guidelines section has been already explained. It is worth mentioning that if you want to be faster
Although the Coding Guidelines section has been already explained, it is worth mentioning that if you want to be faster
at developing a new feature, you may implement it first on a `jupyter notebook` and then carry it across to the
terminal. This is mostly useful when the feature relies on scraping data from a website, or implementing a Neural
Network model.
Expand Down
1 change: 1 addition & 0 deletions openbb_terminal/core/config/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ def get_user_data_directory():
USER_PRESETS_DIRECTORY = USER_DATA_DIRECTORY / "presets"
USER_REPORTS_DIRECTORY = USER_DATA_DIRECTORY / "reports"
USER_CUSTOM_REPORTS_DIRECTORY = USER_DATA_DIRECTORY / "reports" / "custom reports"
USER_FORECAST_MODELS_DIRECTORY = USER_DATA_DIRECTORY / "exports" / "forecast_models"
2 changes: 1 addition & 1 deletion openbb_terminal/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
else:
raise Exception("Using git")
except Exception:
version = "2.0.0"
version = "2.0.1"
VERSION = str(os.getenv("OPENBB_VERSION", version))

# Select the terminal translation language
Expand Down
9 changes: 8 additions & 1 deletion openbb_terminal/forecast/brnn_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from darts.utils.likelihood_models import GaussianLikelihood
from openbb_terminal.decorators import log_start_end
from openbb_terminal.forecast import helpers
from openbb_terminal.core.config.paths import USER_FORECAST_MODELS_DIRECTORY

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -132,6 +133,8 @@ def get_brnn_data(
force_reset=force_reset,
save_checkpoints=save_checkpoints,
likelihood=GaussianLikelihood(),
log_tensorboard=True,
work_dir=USER_FORECAST_MODELS_DIRECTORY,
)

# fit model on train series for historical forecasting
Expand All @@ -145,9 +148,13 @@ def get_brnn_data(
past_covariate_val,
)
best_model = BlockRNNModel.load_from_checkpoint(
model_name=model_save_name, best=True
model_name=model_save_name,
best=True,
work_dir=USER_FORECAST_MODELS_DIRECTORY,
)

helpers.print_tensorboard_logs(model_save_name, USER_FORECAST_MODELS_DIRECTORY)

# Showing historical backtesting without retraining model (too slow)
return helpers.get_prediction(
"Block RNN",
Expand Down
9 changes: 3 additions & 6 deletions openbb_terminal/forecast/forecast_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
"Follow instructions on creating a new conda environment with the latest "
f"Darts version ({darts_latest}):"
)
print(
"https://github.com/OpenBB-finance/OpenBBTerminal/blob/main/openbb_terminal/README.md"
)
print("https://docs.openbb.co/terminal/quickstart/installation")
except ModuleNotFoundError:
raise ModuleNotFoundError(
"Please install the forecast version of the terminal. Instructions "
"are here: https://github.com/OpenBB-finance/OpenBBTerminal/"
"blob/main/openbb_terminal/README.md#anaconda--python"
"Please install the forecast version of the terminal. Instructions can be found "
"under the python tab: https://docs.openbb.co/terminal/quickstart/installation"
)

import pandas as pd
Expand Down
12 changes: 11 additions & 1 deletion openbb_terminal/forecast/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def get_pl_kwargs(
pl_trainer_kwargs = {
"callbacks": [my_stopper],
"accelerator": accelerator,
"logger": False,
# "logger": False,
# "enable_progress_bar": False,
"enable_model_summary": False,
}
Expand Down Expand Up @@ -980,3 +980,13 @@ def check_dates(s: pd.Series) -> bool:
except AttributeError:
return False
return True


def print_tensorboard_logs(model_save_name: str, user_directory: str):
console.print()
tensorboard_logs_dir = os.path.join(user_directory, model_save_name, "logs")
console.print(
"This model supports Tensorboard logs. To view, open a new terminal windown and run:"
)
console.print("tensorboard --logdir=" + tensorboard_logs_dir)
console.print()
9 changes: 8 additions & 1 deletion openbb_terminal/forecast/nbeats_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from openbb_terminal.decorators import log_start_end

from openbb_terminal.forecast import helpers
from openbb_terminal.core.config.paths import USER_FORECAST_MODELS_DIRECTORY

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -135,6 +136,8 @@ def get_NBEATS_data(
save_checkpoints=save_checkpoints,
random_state=42,
pl_trainer_kwargs=helpers.get_pl_kwargs(accelerator="cpu"),
log_tensorboard=True,
work_dir=USER_FORECAST_MODELS_DIRECTORY,
)

# fit model on train series for historical forecasting
Expand All @@ -147,7 +150,11 @@ def get_NBEATS_data(
past_covariate_train,
past_covariate_val,
)
best_model = NBEATSModel.load_from_checkpoint(model_name=model_save_name, best=True)
best_model = NBEATSModel.load_from_checkpoint(
model_name=model_save_name, best=True, work_dir=USER_FORECAST_MODELS_DIRECTORY
)

helpers.print_tensorboard_logs(model_save_name, USER_FORECAST_MODELS_DIRECTORY)

# Showing historical backtesting without retraining model (too slow)
return helpers.get_prediction(
Expand Down
9 changes: 8 additions & 1 deletion openbb_terminal/forecast/nhits_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from darts.utils.likelihood_models import GaussianLikelihood
from openbb_terminal.decorators import log_start_end
from openbb_terminal.forecast import helpers
from openbb_terminal.core.config.paths import USER_FORECAST_MODELS_DIRECTORY

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -164,6 +165,8 @@ def get_nhits_data(
force_reset=force_reset,
save_checkpoints=save_checkpoints,
likelihood=GaussianLikelihood(),
log_tensorboard=True,
work_dir=USER_FORECAST_MODELS_DIRECTORY,
)

# fit model on train series for historical forecasting
Expand All @@ -176,7 +179,11 @@ def get_nhits_data(
past_covariate_train,
past_covariate_val,
)
best_model = NHiTSModel.load_from_checkpoint(model_name=model_save_name, best=True)
best_model = NHiTSModel.load_from_checkpoint(
model_name=model_save_name, best=True, work_dir=USER_FORECAST_MODELS_DIRECTORY
)

helpers.print_tensorboard_logs(model_save_name, USER_FORECAST_MODELS_DIRECTORY)

# Showing historical backtesting without retraining model (too slow)
return helpers.get_prediction(
Expand Down
9 changes: 8 additions & 1 deletion openbb_terminal/forecast/rnn_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from darts.utils.likelihood_models import GaussianLikelihood
from openbb_terminal.decorators import log_start_end
from openbb_terminal.forecast import helpers
from openbb_terminal.core.config.paths import USER_FORECAST_MODELS_DIRECTORY

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -117,13 +118,19 @@ def get_rnn_data(
force_reset=force_reset,
save_checkpoints=save_checkpoints,
likelihood=GaussianLikelihood(),
log_tensorboard=True,
work_dir=USER_FORECAST_MODELS_DIRECTORY,
)

# fit model on train series for historical forecasting
with warnings.catch_warnings():
warnings.simplefilter("ignore")
helpers.fit_model(rnn_model, train, val)
best_model = RNNModel.load_from_checkpoint(model_name=model_save_name, best=True)
best_model = RNNModel.load_from_checkpoint(
model_name=model_save_name, best=True, work_dir=USER_FORECAST_MODELS_DIRECTORY
)

helpers.print_tensorboard_logs(model_save_name, USER_FORECAST_MODELS_DIRECTORY)

# Showing historical backtesting without retraining model (too slow)
return helpers.get_prediction(
Expand Down
9 changes: 8 additions & 1 deletion openbb_terminal/forecast/tcn_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from darts.models import TCNModel
from openbb_terminal.decorators import log_start_end
from openbb_terminal.forecast import helpers
from openbb_terminal.core.config.paths import USER_FORECAST_MODELS_DIRECTORY

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -132,6 +133,8 @@ def get_tcn_data(
save_checkpoints=save_checkpoints,
random_state=42,
pl_trainer_kwargs=helpers.get_pl_kwargs(accelerator="cpu"),
log_tensorboard=True,
work_dir=USER_FORECAST_MODELS_DIRECTORY,
)

# fit model on train series for historical forecasting
Expand All @@ -144,7 +147,11 @@ def get_tcn_data(
past_covariate_train,
past_covariate_val,
)
best_model = TCNModel.load_from_checkpoint(model_name=model_save_name, best=True)
best_model = TCNModel.load_from_checkpoint(
model_name=model_save_name, best=True, work_dir=USER_FORECAST_MODELS_DIRECTORY
)

helpers.print_tensorboard_logs(model_save_name, USER_FORECAST_MODELS_DIRECTORY)

# Showing historical backtesting without retraining model (too slow)
return helpers.get_prediction(
Expand Down
10 changes: 8 additions & 2 deletions openbb_terminal/forecast/tft_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from openbb_terminal.decorators import log_start_end
from openbb_terminal.forecast import helpers

from openbb_terminal.core.config.paths import USER_FORECAST_MODELS_DIRECTORY

warnings.simplefilter("ignore", ConvergenceWarning)

Expand Down Expand Up @@ -172,6 +172,8 @@ def get_tft_data(
quantiles=quantiles
), # QuantileRegression is set per default
add_relative_index=True, # TODO There is a bug with this. Must fix. Should be false
log_tensorboard=True,
work_dir=USER_FORECAST_MODELS_DIRECTORY,
)

# fit model on train series for historical forecasting
Expand All @@ -184,7 +186,11 @@ def get_tft_data(
past_covariate_train,
past_covariate_val,
)
best_model = TFTModel.load_from_checkpoint(model_name=model_save_name, best=True)
best_model = TFTModel.load_from_checkpoint(
model_name=model_save_name, best=True, work_dir=USER_FORECAST_MODELS_DIRECTORY
)

helpers.print_tensorboard_logs(model_save_name, USER_FORECAST_MODELS_DIRECTORY)

# Showing historical backtesting without retraining model (too slow)
return helpers.get_prediction(
Expand Down
7 changes: 6 additions & 1 deletion openbb_terminal/forecast/trans_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from darts.models import TransformerModel
from openbb_terminal.decorators import log_start_end
from openbb_terminal.forecast import helpers
from openbb_terminal.core.config.paths import USER_FORECAST_MODELS_DIRECTORY

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -142,6 +143,8 @@ def get_trans_data(
pl_trainer_kwargs=helpers.get_pl_kwargs(accelerator="cpu"),
force_reset=force_reset,
save_checkpoints=save_checkpoints,
log_tensorboard=True,
work_dir=USER_FORECAST_MODELS_DIRECTORY,
)

# fit model on train series for historical forecasting
Expand All @@ -155,9 +158,11 @@ def get_trans_data(
past_covariate_val,
)
best_model = TransformerModel.load_from_checkpoint(
model_name=model_save_name, best=True
model_name=model_save_name, best=True, work_dir=USER_FORECAST_MODELS_DIRECTORY
)

helpers.print_tensorboard_logs(model_save_name, USER_FORECAST_MODELS_DIRECTORY)

# Showing historical backtesting without retraining model (too slow)
return helpers.get_prediction(
"Transformer",
Expand Down
Loading

0 comments on commit a2a3a43

Please sign in to comment.