Update swing trading dashboard to support newly imported strategies
This commit is contained in:
parent
b9c35d3310
commit
cb95eb5bc6
74
dashboard.py
74
dashboard.py
@ -6,37 +6,11 @@ from dash_bootstrap_templates import load_figure_template
|
||||
from datetime import datetime
|
||||
from flask_caching import Cache
|
||||
from pandas import DataFrame, Series
|
||||
from typing import Callable, List, Dict
|
||||
|
||||
from plotting import CandlestickChart, figure_with_subplots
|
||||
|
||||
from daily_data import get_daily_data
|
||||
from strategies import advances
|
||||
from strategies import cumulative_rsi
|
||||
from strategies import declines
|
||||
from strategies import double_5s
|
||||
from strategies import down_days_in_a_row
|
||||
from strategies import end_of_month
|
||||
from strategies import high_volume_days
|
||||
from strategies import hilo_index_lows
|
||||
from strategies import ibs_rsi
|
||||
from strategies import internal_bar_strength
|
||||
from strategies import internal_bar_strength_band
|
||||
from strategies import large_moves_down
|
||||
from strategies import lower_lows
|
||||
from strategies import put_call_ratio_highs
|
||||
from strategies import rsi_power_zones
|
||||
from strategies import short_term_lows
|
||||
from strategies import tps
|
||||
from strategies import trin
|
||||
from strategies import trin_thrusts
|
||||
from strategies import turnaround
|
||||
from strategies import two_period_rsi
|
||||
from strategies import vix_above_moving_average
|
||||
from strategies import vix_reversal_1
|
||||
from strategies import vix_reversal_2
|
||||
from strategies import vix_reversal_3
|
||||
from strategies import vix_rsi
|
||||
from signals import calculate_signals
|
||||
from stylesheets import grid_stylesheet, theme_stylesheet
|
||||
|
||||
app = Dash(__name__, external_stylesheets = [theme_stylesheet, grid_stylesheet])
|
||||
@ -49,52 +23,6 @@ cache = Cache(app.server, config = {
|
||||
|
||||
load_figure_template('lux_dark')
|
||||
|
||||
SignalFunction = Callable[[DataFrame], Series]
|
||||
|
||||
signal_functions: List[Dict[str, SignalFunction]] = [
|
||||
{'strategy': '2-Period RSI', 'function': two_period_rsi.signals},
|
||||
{'strategy': 'Advances', 'function': advances.signals},
|
||||
{'strategy': 'Cumulative RSI', 'function': cumulative_rsi.signals},
|
||||
{'strategy': 'Declines', 'function': declines.signals},
|
||||
{'strategy': 'Double 5\'s', 'function': double_5s.signals},
|
||||
{'strategy': 'Down Days in a Row', 'function': down_days_in_a_row.signals},
|
||||
{'strategy': 'End of Month', 'function': end_of_month.signals},
|
||||
{'strategy': 'High Volume Days', 'function': high_volume_days.signals},
|
||||
{'strategy': 'HILO Index Lows', 'function': hilo_index_lows.signals},
|
||||
{'strategy': 'IBS + RSI', 'function': ibs_rsi.signals},
|
||||
{'strategy': 'Internal Bar Strength', 'function': internal_bar_strength.signals},
|
||||
{'strategy': 'Internal Bar Strength Band', 'function': internal_bar_strength_band.signals},
|
||||
{'strategy': 'Large Moves Down', 'function': large_moves_down.signals},
|
||||
{'strategy': 'Lower Lows', 'function': lower_lows.signals},
|
||||
{'strategy': 'Put / Call Ratio Highs', 'function': put_call_ratio_highs.signals},
|
||||
{'strategy': 'RSI PowerZones', 'function': rsi_power_zones.signals},
|
||||
{'strategy': 'Short-Term Lows', 'function': short_term_lows.signals},
|
||||
{'strategy': 'TPS', 'function': tps.signals},
|
||||
{'strategy': 'TRIN', 'function': trin.signals},
|
||||
{'strategy': 'TRIN Thrusts', 'function': trin_thrusts.signals},
|
||||
{'strategy': 'Turnaround', 'function': turnaround.signals},
|
||||
{'strategy': 'VIX Above Moving Average', 'function': vix_above_moving_average.signals},
|
||||
{'strategy': 'VIX Reversal 1', 'function': vix_reversal_1.signals},
|
||||
{'strategy': 'VIX Reversal 2', 'function': vix_reversal_2.signals},
|
||||
{'strategy': 'VIX Reversal 3', 'function': vix_reversal_3.signals},
|
||||
{'strategy': 'VIX RSI', 'function': vix_rsi.signals}
|
||||
]
|
||||
|
||||
def calculate_signals(data: DataFrame, days: int = 12) -> DataFrame:
|
||||
signal_data = []
|
||||
|
||||
for signal_info in signal_functions:
|
||||
signal_dict = {'Strategy': signal_info['strategy']}
|
||||
|
||||
signals = signal_info['function'](data).tail(days)
|
||||
dates = [datetime.strptime(str(date), '%Y-%m-%d').strftime('%m/%d') for date in data.tail(days)['Date']]
|
||||
for date, signal in zip(dates, signals):
|
||||
signal_dict[date] = signal
|
||||
|
||||
signal_data.append(signal_dict)
|
||||
|
||||
return DataFrame(signal_data)
|
||||
|
||||
def load_chart(data: DataFrame) -> dict:
|
||||
chart_data = data.tail(180)
|
||||
candlestick_chart = CandlestickChart(
|
||||
|
Loading…
Reference in New Issue
Block a user