Skip to content
Open
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
29 changes: 8 additions & 21 deletions algo_bot/commands/strategies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import argparse
import re
import time

import numpy as np
import pandas as pd
Expand All @@ -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)
Expand All @@ -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(),
Expand Down Expand Up @@ -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()
Expand All @@ -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 (.*)")
Expand Down Expand Up @@ -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
10 changes: 9 additions & 1 deletion requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down