aboutsummaryrefslogtreecommitdiff
path: root/app.py
blob: 57928dfe8c07e4716d1b1dcfdfebd58ecc5f2fdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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)