Method314 commited on
Commit
439bbe7
·
verified ·
1 Parent(s): 613ae0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -26
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 * np.exp(log_returns_std)
86
- inner_lower_band = log_trend * np.exp(-log_returns_std)
87
- outer_upper_band = log_trend * np.exp(2 * log_returns_std)
88
- outer_lower_band = log_trend * np.exp(-2 * log_returns_std)
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='blue')))
95
- fig.add_trace(go.Scatter(x=extended_dates, y=log_trend, mode='lines', name='Log Trend', line=dict(color='red')))
96
- fig.add_trace(go.Scatter(x=extended_dates, y=inner_upper_band, mode='lines', name='1 SD Upper Band', line=dict(color='#6FB1A7')))
97
- fig.add_trace(go.Scatter(x=extended_dates, y=inner_lower_band, mode='lines', name='1 SD Lower Band', line=dict(color='#6FB1A7')))
98
- fig.add_trace(go.Scatter(x=extended_dates, y=outer_upper_band, mode='lines', name='2 SD Upper Band', line=dict(color='#FFC2A5')))
99
- fig.add_trace(go.Scatter(x=extended_dates, y=outer_lower_band, mode='lines', name='2 SD Lower Band', line=dict(color='#FFC2A5')))
100
 
101
  fig.update_layout(
102
  title={
103
- 'text': f'Stock Log Chart: {ticker}',
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", css=custom_css) as iface:
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", elem_id="ticker-input")
154
- start_date = gr.Textbox(label="Start Date", value="2015-01-01", elem_id="start-date-input")
155
- end_date = gr.Textbox(label="End Date", value=current_date, elem_id="end-date-input")
156
 
157
- submit_button = gr.Button("Generate Chart", elem_id="generate-button")
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")