Share OHLC data between the chart and signal grid
This commit is contained in:
parent
d8870e0c62
commit
a5d12cfcf8
19
dashboard.py
19
dashboard.py
@ -27,19 +27,17 @@ signal_functions: List[Dict[str, SignalFunction]] = [
|
||||
]
|
||||
|
||||
symbol = 'SPY'
|
||||
today = datetime.today()
|
||||
data = ohlc(symbol = symbol, start_date = today - timedelta(days = 180), end_date = today)
|
||||
|
||||
def calculate_signals(data: DataFrame, days: int = 12) -> DataFrame:
|
||||
end_date = datetime.today()
|
||||
start_date = end_date - timedelta(days = days + 10)
|
||||
data = ohlc(symbol = symbol, start_date = start_date, end_date = end_date)
|
||||
|
||||
recent_signals = data.tail(days)
|
||||
def calculate_signals(days: int = 12) -> DataFrame:
|
||||
signal_data = []
|
||||
|
||||
for signal_info in signal_functions:
|
||||
signals = signal_info['function'](recent_signals)
|
||||
signal_dict = {'Strategy': signal_info['strategy']}
|
||||
dates = [datetime.strptime(str(date), '%Y-%m-%d').strftime('%m/%d') for date in recent_signals['Date']]
|
||||
|
||||
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
|
||||
|
||||
@ -48,9 +46,6 @@ def calculate_signals(data: DataFrame, days: int = 12) -> DataFrame:
|
||||
return DataFrame(signal_data)
|
||||
|
||||
def load_chart() -> dict:
|
||||
today = datetime.today()
|
||||
data = ohlc(symbol = symbol, start_date = today - timedelta(days = 180), end_date = today)
|
||||
|
||||
candlestick_chart = CandlestickChart(
|
||||
x = data['Date'],
|
||||
opens = data['Open'],
|
||||
@ -61,7 +56,7 @@ def load_chart() -> dict:
|
||||
|
||||
return figure_with_subplots([[candlestick_chart]])
|
||||
|
||||
signal_data = calculate_signals(DataFrame(), days = 12)
|
||||
signal_data = calculate_signals()
|
||||
|
||||
app.layout = dbc.Container(
|
||||
[
|
||||
|
Loading…
Reference in New Issue
Block a user