aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorloit <michael.foiani@gmail.com>2025-07-29 00:59:43 -0400
committerloit <michael.foiani@gmail.com>2025-07-29 00:59:43 -0400
commit0372b76ee22ea4421b70d6f7f8c2b29b2c7ac9dc (patch)
tree42dbf007e93e366550ea339fc9737d7718d67e46
parent00d89073d7802983b11f9e5931f932444806defd (diff)
add basic features to indicte if parameters are bad
-rw-r--r--api.py5
-rw-r--r--app.py48
2 files changed, 33 insertions, 20 deletions
diff --git a/api.py b/api.py
index 00c2733..41e361a 100644
--- a/api.py
+++ b/api.py
@@ -28,6 +28,10 @@ def fetch_chart_data(ticker, period='1y', interval='1d'):
data_obj = r.json()
# get the specific data we want
+ if 'timestamp' not in data_obj['chart']['result'][0]:
+ last_data = pull_last_from_file()
+ last_data['error'] = True
+ return last_data
timestamps = data_obj['chart']['result'][0]['timestamp']
close_prices = data_obj['chart']['result'][0]['indicators']['quote'][0]['close']
@@ -43,7 +47,6 @@ def fetch_chart_data(ticker, period='1y', interval='1d'):
name = data_obj['chart']['result'][0]['meta']['longName']
data = {'timestamps': timestamps, 'prices': close_prices, 'name': name, 'error': False}
-
update_last_file(data)
# save data to file in case necessary
return data
diff --git a/app.py b/app.py
index c251f73..68aacb8 100644
--- a/app.py
+++ b/app.py
@@ -27,26 +27,31 @@ app = Dash(__name__)
# intersected_y.append(y)
app.layout = html.Div([
- html.H4('Interactive color selection with simple Dash example'),
- html.Label("Ticker ", htmlFor="ticker"),
- dcc.Input(id="ticker", value="SPY", type="text"),
- html.Br(),
- html.Label("Period ", htmlFor="period"),
- dcc.Dropdown(
- id="period_dropdown",
- options=["1d","5d","1mo","3mo","6mo","1y","2y","5y","10y","ytd","max"],
- value = "1y",
- ),
- html.Br(),
- html.Label("Interval ", htmlFor="Interval"),
- dcc.Dropdown(
- id="interval_dropdown",
- options=["1m", "2m", "5m", "15m", "30m", "60m", "90m", "1h", "4h", "1d", "5d", "1wk", "1mo", "3mo"],
- value = "1d",
+ html.H4('Backtesting using the EMA method (5 vs 13) [ALPHA VERSION 0.0.2]'),
+ html.Div(
+ [
+ html.Label("Ticker ", htmlFor="ticker"),
+ dcc.Input(id="ticker", value="SPY", type="text"),
+ html.Br(),
+ html.Label("Period ", htmlFor="period_dropdown"),
+ dcc.Dropdown(
+ id="period_dropdown",
+ options=["1d","5d","1mo","3mo","6mo","1y","2y","5y","10y","ytd","max"],
+ value = "1y"),
+ html.Br(),
+ html.Label("Interval ", htmlFor="interval_dropdown"),
+ dcc.Dropdown(
+ id="interval_dropdown",
+ options=["1m", "2m", "5m", "15m", "30m", "60m", "90m", "1h", "4h", "1d", "5d", "1wk", "1mo", "3mo"],
+ value = "1d",
+ ),
+ html.P(id='error_message'),
+ ],
+ id='input_params'
),
html.Hr(),
dcc.Graph(id="graph"),
- html.P("If bought and sold on these signals, the percent gain/loss would be: TODO"),
+ html.P("If bought and sold on these signals, the percent gain/loss would be:"),
html.P(id="percent_gain")
])
@@ -54,15 +59,20 @@ app.layout = html.Div([
@app.callback(
Output("graph", "figure"),
Output("percent_gain", "children"),
+ Output("input_params", "style"),
+ Output("error_message", "children"),
Input("ticker", "value"),
Input("period_dropdown", "value"),
Input("interval_dropdown", "value")
)
def display_color(ticker, period, interval):
chart_data = fetch_chart_data(ticker, period, interval)
+ error_style = {"color" : "inherit"}
+ error_message = ''
if chart_data['error'] == True:
# implement a feeback mechanism for ERROR codes
- print("TODO: FIX THIS")
+ error_style = {"color" : "red"}
+ error_message = 'Issue with parameter selection. Please try again.'
timestamps_raw = chart_data['timestamps']
timestamps = [datetime.datetime.fromtimestamp(t) for t in timestamps_raw]
@@ -105,7 +115,7 @@ def display_color(ticker, period, interval):
yaxis=go.layout.YAxis(title='Price ($)')
)
)
- return (fig, percent_gain)
+ return fig, percent_gain, error_style, error_message