Update app.py
Browse files
app.py
CHANGED
|
@@ -71,9 +71,6 @@ def plot_interactive_logarithmic_stock_chart(ticker, start_date, end_date):
|
|
| 71 |
if data.empty:
|
| 72 |
return "No data available for the specified date range."
|
| 73 |
|
| 74 |
-
log_returns = np.log(data['Close'] / data['Close'].shift(1))
|
| 75 |
-
log_returns_std = log_returns.std()
|
| 76 |
-
|
| 77 |
x = (data.index - data.index[0]).days
|
| 78 |
y = np.log(data['Close'])
|
| 79 |
slope, intercept = np.polyfit(x, y, 1)
|
|
@@ -82,25 +79,25 @@ def plot_interactive_logarithmic_stock_chart(ticker, start_date, end_date):
|
|
| 82 |
all_days = np.arange(len(x) + future_days)
|
| 83 |
log_trend = np.exp(intercept + slope * all_days)
|
| 84 |
|
| 85 |
-
inner_upper_band = log_trend *
|
| 86 |
-
inner_lower_band = log_trend
|
| 87 |
-
outer_upper_band = log_trend *
|
| 88 |
-
outer_lower_band = log_trend
|
| 89 |
|
| 90 |
extended_dates = pd.date_range(start=data.index[0], periods=len(all_days), freq='D')
|
| 91 |
|
| 92 |
fig = go.Figure()
|
| 93 |
|
| 94 |
-
fig.add_trace(go.Scatter(x=data.index, y=data['Close'], mode='lines', name='Close Price', line=dict(color='
|
| 95 |
-
fig.add_trace(go.Scatter(x=extended_dates, y=log_trend, mode='lines', name='Log Trend', line=dict(color='
|
| 96 |
-
fig.add_trace(go.Scatter(x=extended_dates, y=inner_upper_band, mode='lines', name='
|
| 97 |
-
fig.add_trace(go.Scatter(x=extended_dates, y=inner_lower_band, mode='lines', name='
|
| 98 |
-
fig.add_trace(go.Scatter(x=extended_dates, y=outer_upper_band, mode='lines', name='
|
| 99 |
-
fig.add_trace(go.Scatter(x=extended_dates, y=outer_lower_band, mode='lines', name='
|
| 100 |
|
| 101 |
fig.update_layout(
|
| 102 |
title={
|
| 103 |
-
'text':
|
| 104 |
'y': 0.95,
|
| 105 |
'x': 0.5,
|
| 106 |
'xanchor': 'center',
|
|
@@ -137,24 +134,17 @@ def plot_interactive_logarithmic_stock_chart(ticker, start_date, end_date):
|
|
| 137 |
# Get the current date
|
| 138 |
current_date = datetime.now().strftime("%Y-%m-%d")
|
| 139 |
|
| 140 |
-
# Custom CSS for button and input hover effects
|
| 141 |
-
custom_css = """
|
| 142 |
-
#generate-button:hover, #ticker-input:hover, #start-date-input:hover, #end-date-input:hover {
|
| 143 |
-
background-color: #FFB3BA !important; /* Pastel red */
|
| 144 |
-
}
|
| 145 |
-
"""
|
| 146 |
-
|
| 147 |
# Create Gradio interface with custom Seafoam theme
|
| 148 |
-
with gr.Blocks(theme=seafoam, title="Stock Log Charts"
|
| 149 |
gr.Markdown("# Stock Log Charts")
|
| 150 |
gr.Markdown("Enter a stock ticker and date range to generate a logarithmic chart.")
|
| 151 |
|
| 152 |
with gr.Row():
|
| 153 |
-
ticker = gr.Textbox(label="Stock Ticker", value="MSFT"
|
| 154 |
-
start_date = gr.Textbox(label="Start Date", value="2015-01-01"
|
| 155 |
-
end_date = gr.Textbox(label="End Date", value=current_date
|
| 156 |
|
| 157 |
-
submit_button = gr.Button("Generate Chart"
|
| 158 |
|
| 159 |
with gr.Row():
|
| 160 |
log_plot = gr.Plot(label="Logarithmic Stock Chart")
|
|
|
|
| 71 |
if data.empty:
|
| 72 |
return "No data available for the specified date range."
|
| 73 |
|
|
|
|
|
|
|
|
|
|
| 74 |
x = (data.index - data.index[0]).days
|
| 75 |
y = np.log(data['Close'])
|
| 76 |
slope, intercept = np.polyfit(x, y, 1)
|
|
|
|
| 79 |
all_days = np.arange(len(x) + future_days)
|
| 80 |
log_trend = np.exp(intercept + slope * all_days)
|
| 81 |
|
| 82 |
+
inner_upper_band = log_trend * 2
|
| 83 |
+
inner_lower_band = log_trend / 2
|
| 84 |
+
outer_upper_band = log_trend * 4
|
| 85 |
+
outer_lower_band = log_trend / 4
|
| 86 |
|
| 87 |
extended_dates = pd.date_range(start=data.index[0], periods=len(all_days), freq='D')
|
| 88 |
|
| 89 |
fig = go.Figure()
|
| 90 |
|
| 91 |
+
fig.add_trace(go.Scatter(x=data.index, y=data['Close'], mode='lines', name='Close Price', line=dict(color='#3A9184')))
|
| 92 |
+
fig.add_trace(go.Scatter(x=extended_dates, y=log_trend, mode='lines', name='Log Trend', line=dict(color='#FF8C61')))
|
| 93 |
+
fig.add_trace(go.Scatter(x=extended_dates, y=inner_upper_band, mode='lines', name='Inner Upper Band', line=dict(color='#6FB1A7')))
|
| 94 |
+
fig.add_trace(go.Scatter(x=extended_dates, y=inner_lower_band, mode='lines', name='Inner Lower Band', line=dict(color='#6FB1A7')))
|
| 95 |
+
fig.add_trace(go.Scatter(x=extended_dates, y=outer_upper_band, mode='lines', name='Outer Upper Band', line=dict(color='#FFC2A5')))
|
| 96 |
+
fig.add_trace(go.Scatter(x=extended_dates, y=outer_lower_band, mode='lines', name='Outer Lower Band', line=dict(color='#FFC2A5')))
|
| 97 |
|
| 98 |
fig.update_layout(
|
| 99 |
title={
|
| 100 |
+
'text': 'Stock Log Charts',
|
| 101 |
'y': 0.95,
|
| 102 |
'x': 0.5,
|
| 103 |
'xanchor': 'center',
|
|
|
|
| 134 |
# Get the current date
|
| 135 |
current_date = datetime.now().strftime("%Y-%m-%d")
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
# Create Gradio interface with custom Seafoam theme
|
| 138 |
+
with gr.Blocks(theme=seafoam, title="Stock Log Charts") as iface:
|
| 139 |
gr.Markdown("# Stock Log Charts")
|
| 140 |
gr.Markdown("Enter a stock ticker and date range to generate a logarithmic chart.")
|
| 141 |
|
| 142 |
with gr.Row():
|
| 143 |
+
ticker = gr.Textbox(label="Stock Ticker", value="MSFT")
|
| 144 |
+
start_date = gr.Textbox(label="Start Date", value="2015-01-01")
|
| 145 |
+
end_date = gr.Textbox(label="End Date", value=current_date)
|
| 146 |
|
| 147 |
+
submit_button = gr.Button("Generate Chart")
|
| 148 |
|
| 149 |
with gr.Row():
|
| 150 |
log_plot = gr.Plot(label="Logarithmic Stock Chart")
|