from dash import Dash, dcc, html, Input, Output, dash_table import plotly.graph_objects as go import json from datetime import datetime, timedelta from ema_algo import Ema_Algo from api import fetch_chart_data_yahoo from analysis import summarize_results import pytz import pandas as pd app = Dash(__name__) # pull the data from the files table_data, algos_to_results = summarize_results('test-1-ema') app.layout = html.Div([ html.H4('Backtesting using EMA algos [ALPHA VERSION 0.1.0]'), dcc.Dropdown( id='batch_name', options=[ {'label': 'Test 1 - EMA', 'value': 'test-1-ema'} ], value='test-1-ema', clearable=False ), html.Hr(), dash_table.DataTable( table_data.to_dict('records'), [{"name": i, "id": i} for i in table_data.columns], style_table={'overflowX': 'auto'}, style_cell={'textAlign': 'center'}, style_header={ 'backgroundColor': 'rgb(230, 230, 230)', 'fontWeight': 'bold' }, style_data={ 'whiteSpace': 'normal', 'height': 'auto' }, sort_action='native', ), html.Hr(), # dcc.Graph(id="graph"), html.P("If bought and sold on these signals, the percent gain/loss would be:"), html.P(id="percent_gain"), # for each algo, print the individual results given by the map html.Div(id='algo_results', children=[ html.Div([ html.Div([ ]) ]) for algo_name, result in algos_to_results.items() ]) ]) @app.callback( Input("batch_name", "value"), ) def display_color(batch_name): # compute the results to show in the table path = batch_name result_summary = summarize_results(path) if not result_summary: return "No results found for the given file ID." # update the table data global table_data table_data = result_summary # table = go.Figure( # data = [go.Table( # header=dict(values=["algo name", "algo params", "avg percent gain", "best stock for gain"]), # cells=dict(values=result_summary) # )] # ) # data = fetch_chart_data_yahoo('XRP-USD', '1d', None, timedelta(weeks=52)) # times = [datetime.fromtimestamp(t).astimezone(pytz.timezone('US/Eastern')) for t in data['timestamps']] # comp_scatter = go.Scatter(name='Price (yahoo)', x=times, y=data['prices'], line=dict(color='rgb(255, 0, 0)'), mode='lines') # fig = go.Figure( # data = [ # go.Scatter(name='Price', x=timestamps, y=prices, line=dict(color='rgb(0, 0, 0)'), mode='lines'), # comp_scatter # ] # # + algo_graphs + buy_sell_scatters # , # layout = go.Layout( # title=go.layout.Title(text='Chart for ' + chart_data['name']), # xaxis=go.layout.XAxis(title='Date (dt=' + url_params['interval'] + ', range=' + url_params['period'] + ')'), # yaxis=go.layout.YAxis(title='Price ($)') # ) # ) return app.run(debug=True)