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