diff --git a/algo_bot/commands/strategies.py b/algo_bot/commands/strategies.py index 4b59546..645ad61 100644 --- a/algo_bot/commands/strategies.py +++ b/algo_bot/commands/strategies.py @@ -1,6 +1,5 @@ import argparse import re -import time import numpy as np import pandas as pd @@ -10,7 +9,7 @@ from algo_bot import cache, charting, utils from algo_bot.clients import alpha_vantage_client as avc from algo_bot.db.models import Screener -from prophet import Prophet +from neuralprophet import NeuralProphet RUN_STRATEGY_PARSER = argparse.ArgumentParser() RUN_STRATEGY_PARSER.add_argument("--screener-id", type=int, required=False) @@ -29,11 +28,10 @@ def run_strategy_predict_price(message, ticker): df = pd.DataFrame(data=results.loc[:, ["date", "4. close"]]).rename(columns={"date": "ds", "4. close": "y"}) # df['cap'] = df["y"].max() price = pd.DataFrame(data=results.loc[:, ["date", "4. close"]]).rename(columns={"4. close": "close"}).set_index(["date"]) - m = Prophet(mcmc_samples=300) - m.fit(df, control={'max_treedepth': 10}) - future = m.make_future_dataframe(periods=365, freq='d', include_history = True) - # future['cap'] = df["y"].max() - forecast = m.predict(future).set_index(["ds"]).sort_values(by="ds", ascending=False) + m = NeuralProphet(daily_seasonality=True) + m.fit(df, freq="D") + future = m.make_future_dataframe(df, periods=365, n_historic_predictions=True) + forecast = m.predict(future).set_index(["ds"]).sort_values(by="ds", ascending=True).rename(columns={"yhat1": "yhat"}) fig = charting.predicted_price( start=utils.today(), stop=utils.years_ago(), @@ -84,7 +82,7 @@ def run_strategy_risk_vs_reward(message, params): message, "Error: Screener not found or does not belong to you!" ) elif params.ticker: - data = { } + data = {} ticker = params.ticker data[ticker] = avc.time_series_daily(ticker)["4. close"] df = pd.DataFrame(data=data).sort_values(by="date", ascending=False).dropna() @@ -99,8 +97,8 @@ def run_strategy_risk_vs_reward(message, params): ) else: utils.reply_webapi( - message, "Error: Requires either --screener-id or --ticker" - ) + message, "Error: Requires either --screener-id or --ticker" + ) @respond_to("^strategy-turtle (.*)") @@ -197,14 +195,3 @@ def _turtle(screener): df = pd.DataFrame(records) return df - - -def _retry(callable): - while True: - try: - callable() - except ValueError as exc: - print(exc) - time.sleep(60) - else: - break diff --git a/requirements.lock b/requirements.lock index 18683f5..05430ca 100644 --- a/requirements.lock +++ b/requirements.lock @@ -7,6 +7,7 @@ argcomplete==1.12.3 argon2-cffi==20.1.0 astor==0.8.1 async-timeout==3.0.1 +attrdict==2.0.1 attrs==21.2.0 Babel==2.9.1 backcall==0.2.0 @@ -30,14 +31,16 @@ entrypoints==0.3 ephem==4.0.0.2 finviz==1.4.2 funcparserlib==0.3.6 +future==0.18.2 greenlet==1.1.1 holidays==0.10.4 hy==0.20.0 idna==2.10 importlib-metadata==4.7.1 ipykernel==6.2.0 -ipython==7.26.0 +ipython==7.27.0 ipython-genutils==0.2.0 +ipywidgets==7.6.3 jedi==0.18.0 Jinja2==3.0.1 jmespath==0.10.0 @@ -49,6 +52,7 @@ jupyter-server==1.10.2 jupyterlab==3.0.5 jupyterlab-pygments==0.1.2 jupyterlab-server==2.7.2 +jupyterlab-widgets==1.0.0 kiwisolver==1.3.2 korean-lunar-calendar==0.2.1 LunarCalendar==0.0.9 @@ -65,6 +69,7 @@ nbclient==0.5.4 nbconvert==6.1.0 nbformat==5.1.3 nest-asyncio==1.4.3 +neuralprophet==0.2.7 notebook==6.4.3 numpy==1.21.2 packaging==21.0 @@ -115,6 +120,8 @@ tabulate==0.8.7 tenacity==8.0.1 terminado==0.11.1 testpath==0.5.0 +torch==1.6.0 +torch-lr-finder==0.2.1 tornado==6.1 tqdm==4.62.2 traitlets==5.0.5 @@ -126,6 +133,7 @@ wcwidth==0.2.5 webencodings==0.5.1 websocket-client==0.44.0 wheel==0.37.0 +widgetsnbextension==3.5.1 yarl==1.6.3 yfinance==0.1.63 zipp==3.5.0 diff --git a/requirements.txt b/requirements.txt index 6b6a750..ce47084 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ requests==2.25.1 finviz==1.4.2 pystan==2.19.1.1 numpy==1.21.2 +neuralprophet prophet==1.0.1 plotly==4.14.3 pandas==1.2.0