aboutsummaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
authorloit <michael.foiani@gmail.com>2025-07-28 18:00:08 -0400
committerloit <michael.foiani@gmail.com>2025-07-28 18:00:08 -0400
commit8907c286e857b622af171c2d8ac9040b05970549 (patch)
treec288bd62aa4e82f926c3666d61e00e3cb10d3b9b /app.py
parent8062d3a9cc10ccfec3dab7f859fa0d1d4c118d38 (diff)
add intersection interpolation code for graphing EMAs visually
Diffstat (limited to 'app.py')
-rw-r--r--app.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/app.py b/app.py
index a2e9f07..5cd5521 100644
--- a/app.py
+++ b/app.py
@@ -1,4 +1,5 @@
from dash import Dash, dcc, html, Input, Output
+from analysis import calc_emas, find_intersections, interpolate_intersection
import plotly.graph_objects as go
import json
import datetime
@@ -21,13 +22,23 @@ app.layout = html.Div([
# pull stock data from json files
timestamps_file = open('timestamps.json', 'r')
timestamps_file_data = timestamps_file.read()
-timestamps = json.loads(timestamps_file_data)
-timestamps = [datetime.datetime.fromtimestamp(t) for t in timestamps]
+timestamps_raw = json.loads(timestamps_file_data)
+timestamps = [datetime.datetime.fromtimestamp(t) for t in timestamps_raw]
prices_file = open('close_prices.json', 'r')
prices = json.loads(prices_file.read())
-# print('timestamps:\t', timestamps, '\nprices:\t', prices)
+ema_5 = calc_emas(5, prices)
+ema_13 = calc_emas(13, prices)
+
+intersection_indices = find_intersections(ema_5, ema_13)
+interpolated_intersections = [interpolate_intersection(indices, timestamps, ema_5, ema_13) for indices in intersection_indices]
+intersected_x = []
+intersected_y = []
+for x,y in interpolated_intersections:
+ intersected_x.append(x)
+ intersected_y.append(y)
+
@app.callback(
@@ -35,7 +46,13 @@ prices = json.loads(prices_file.read())
Input("dropdown", "value"))
def display_color(color):
fig = go.Figure(
- data=go.Line(x=timestamps, y=prices, marker_color=color))
+ [
+ go.Scatter(name='Price', x=timestamps, y=prices, line=dict(color='rgb(0, 255, 255)'), mode='lines'), # prices
+ go.Scatter(name='5 day EMA', x=timestamps, y=ema_5, line=dict(color='rgb(0, 255, 0)'), mode='lines'), # 5 ema line
+ go.Scatter(name='13 day EMA', x=timestamps, y=ema_13, line=dict(color='rgb(0, 0, 255)'), mode='lines'), # 13 ema line
+ go.Scatter(name='EMA Intersections', x=intersected_x, y=intersected_y, line=dict(color='rgb(255, 0, 0)'), mode='markers') # EMA intersection points
+ ]
+ )
return fig