QuantumLearner commited on
Commit
308545b
·
verified ·
1 Parent(s): 140807d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -46
app.py CHANGED
@@ -4,18 +4,27 @@ import pandas as pd
4
  import plotly.graph_objects as go
5
  import streamlit as st
6
 
7
- st.set_page_config(page_title = "Expected Stock Price Movement Using Volatility Multipliers", layout = "wide")
8
  st.title('Expected Stock Price Movement Using Volatility Multipliers')
9
 
10
- # Sidebar inputs with standard labels
11
- st.sidebar.header('Input Parameters')
12
- ticker = st.sidebar.text_input('Enter Stock Ticker', 'ADS.DE')
13
- start_date = st.sidebar.date_input('Start Date', pd.to_datetime('2020-01-01'))
14
- end_date = st.sidebar.date_input('End Date', pd.to_datetime('2025-12-30'))
15
- time_horizon = st.sidebar.slider('Time Horizon (Days)', min_value=1, max_value=60, value=30)
16
- std_multipliers = st.sidebar.multiselect('Select Std Multipliers', [1, 1.25, 1.5, 1.75, 2], default=[1, 1.25, 1.5])
17
- rolling_window = st.sidebar.slider('Rolling Window (Days)', min_value=10, max_value=90, value=30, step=5)
 
 
 
 
18
 
 
 
 
 
 
19
 
20
  # Inject CSS for custom styling
21
  st.markdown("""
@@ -36,37 +45,24 @@ st.markdown("""
36
  </style>
37
  """, unsafe_allow_html=True)
38
 
39
-
40
  st.write("""
41
  This analysis estimates the potential price movement of a selected stock over a specified time horizon.
42
  The predictions are based on historical volatility, calculated from the stock's daily returns.
43
  You can adjust the time horizon and standard deviation multipliers to see how the expected price range changes.
44
  """)
45
 
46
- st.markdown("""
47
- ### How to Use This App
48
- 1. **Input Parameters**: Use the sidebar to enter the stock ticker, date range, time horizon, standard deviation multipliers, and rolling window period for the analysis.
49
- 2. **Run the Analysis**: Click the "Run" button to perform the analyses and visualize the results.
50
-
51
- Each analysis is accompanied by a detailed explanation and visual representation, providing insights into the stock's price behavior and helping you make informed decisions regarding potential price movements.
52
- """)
53
-
54
  # Display the main formula with clear, basic LaTeX
55
  st.latex(r'''
56
  P_t = P_0 \times e^{\sigma \times \sqrt{t} \times z}
57
  ''')
58
 
59
- # Provide detailed explanations using plain text
60
  st.markdown("""
61
  **Formula for price movement estimation explained:**
62
-
63
  - **P_t**: Estimated price at time (t)
64
  - **P_0**: Current price
65
  - **σ (sigma)**: Standard deviation of the stock's returns, representing volatility
66
  - **t**: Time horizon in days
67
  - **z**: Multiplier corresponding to the desired confidence level, which adjusts for standard deviation
68
-
69
- The formula calculates the future stock price P_t based on the exponential growth affected by the volatility (σ), time (t), and the confidence level multiplier (z). This approach assumes a log-normal distribution of prices, common in financial modeling for stock prices.
70
  """)
71
 
72
  if st.sidebar.button('Run'):
@@ -82,17 +78,9 @@ if st.sidebar.button('Run'):
82
  date_range = pd.date_range(plot_data.index[-1] + pd.DateOffset(1), periods=time_horizon, freq='D')
83
 
84
  st.markdown("""
85
- <h3 style='color: green; font-size: 24px;'>Method 1: Dynamic Volatility</h3>
86
-
87
- **Description:**
88
- This method assesses stock price movement by calculating volatility over dynamically changing periods based on a rolling window. It adjusts for recent market behaviors, making the estimation sensitive to the latest trends.
89
-
90
- **Technical Explanation:**
91
- The application calculates the standard deviation (volatility) of the stock’s daily returns over the past rolling window period, then shifts this window one day at a time through the desired forecasting period. This dynamic calculation helps in adapting to recent market volatility which could impact future price movements significantly.
92
-
93
- **Visualization:**
94
- The method plots the past days of stock prices and overlays the expected upper and lower bounds for the price over the forecast horizon. This visual representation uses different colors to distinguish between past prices and forecasted boundaries, enhancing understanding of volatility impacts.
95
- """, unsafe_allow_html=True)
96
 
97
  # Plot historical prices once
98
  fig1.add_trace(go.Scatter(x=plot_data.index, y=plot_data, mode='lines', name='Historical Prices'))
@@ -147,27 +135,19 @@ if st.sidebar.button('Run'):
147
  st.plotly_chart(fig1)
148
 
149
  st.markdown("""
150
- <h3 style='color: green; font-size: 24px;'>Method 2: Single Volatility Measure</h3>
151
-
152
- **Description:**
153
- This method calculates stock price movement based on a single, constant measure of volatility derived from the entire historical data set available. By using this approach, it simplifies the calculation but may not reflect recent market dynamics as effectively as the dynamic method.
154
-
155
- **Technical Explanation:**
156
- The application calculates the standard deviation (volatility) of the stock's daily returns across the entire period for which data is available. This constant measure of volatility is then used to estimate the price range over the forecasting period, assuming that the past long-term volatility will continue into the future.
157
-
158
- **Visualization:**
159
- The method plots the historical data and overlays expected upper and lower price boundaries based on this single measure of volatility. The visualization clearly marks these projected bounds with different colors to illustrate potential future price movements based on historical volatility levels, providing a straightforward visual interpretation of risk and variability over time.
160
- """, unsafe_allow_html=True)
161
 
162
  st.plotly_chart(fig2)
163
  else:
164
  st.write("No data found for the given ticker and date range.")
165
 
166
-
167
  hide_streamlit_style = """
168
  <style>
169
  #MainMenu {visibility: hidden;}
170
  footer {visibility: hidden;}
171
  </style>
172
  """
173
- st.markdown(hide_streamlit_style, unsafe_allow_html=True)
 
4
  import plotly.graph_objects as go
5
  import streamlit as st
6
 
7
+ st.set_page_config(page_title="Expected Stock Price Movement Using Volatility Multipliers", layout="wide")
8
  st.title('Expected Stock Price Movement Using Volatility Multipliers')
9
 
10
+ # Sidebar section with instructions
11
+ st.sidebar.header('How to Use This App')
12
+ st.sidebar.markdown("""
13
+ 1. **Input Parameters**: Enter the stock ticker, date range, time horizon, standard deviation multipliers, and rolling window period.
14
+ 2. **Run the Analysis**: Click the "Run" button to perform the analyses and visualize the results.
15
+ """)
16
+
17
+ # Wrapping ticker and date settings in an expander
18
+ with st.sidebar.expander("Ticker and Date Settings", expanded=True):
19
+ ticker = st.text_input('Enter Stock Ticker', 'ADS.DE')
20
+ start_date = st.date_input('Start Date', pd.to_datetime('2020-01-01'))
21
+ end_date = st.date_input('End Date', pd.to_datetime('2025-12-30'))
22
 
23
+ # Wrapping parameter settings in an expander
24
+ with st.sidebar.expander("Parameter Settings", expanded=True):
25
+ time_horizon = st.slider('Time Horizon (Days)', min_value=1, max_value=60, value=30)
26
+ std_multipliers = st.multiselect('Select Std Multipliers', [1, 1.25, 1.5, 1.75, 2], default=[1, 1.25, 1.5])
27
+ rolling_window = st.slider('Rolling Window (Days)', min_value=10, max_value=90, value=30, step=5)
28
 
29
  # Inject CSS for custom styling
30
  st.markdown("""
 
45
  </style>
46
  """, unsafe_allow_html=True)
47
 
 
48
  st.write("""
49
  This analysis estimates the potential price movement of a selected stock over a specified time horizon.
50
  The predictions are based on historical volatility, calculated from the stock's daily returns.
51
  You can adjust the time horizon and standard deviation multipliers to see how the expected price range changes.
52
  """)
53
 
 
 
 
 
 
 
 
 
54
  # Display the main formula with clear, basic LaTeX
55
  st.latex(r'''
56
  P_t = P_0 \times e^{\sigma \times \sqrt{t} \times z}
57
  ''')
58
 
 
59
  st.markdown("""
60
  **Formula for price movement estimation explained:**
 
61
  - **P_t**: Estimated price at time (t)
62
  - **P_0**: Current price
63
  - **σ (sigma)**: Standard deviation of the stock's returns, representing volatility
64
  - **t**: Time horizon in days
65
  - **z**: Multiplier corresponding to the desired confidence level, which adjusts for standard deviation
 
 
66
  """)
67
 
68
  if st.sidebar.button('Run'):
 
78
  date_range = pd.date_range(plot_data.index[-1] + pd.DateOffset(1), periods=time_horizon, freq='D')
79
 
80
  st.markdown("""
81
+ ### Method 1: Dynamic Volatility
82
+ This method assesses stock price movement by calculating volatility over dynamically changing periods based on a rolling window.
83
+ """)
 
 
 
 
 
 
 
 
84
 
85
  # Plot historical prices once
86
  fig1.add_trace(go.Scatter(x=plot_data.index, y=plot_data, mode='lines', name='Historical Prices'))
 
135
  st.plotly_chart(fig1)
136
 
137
  st.markdown("""
138
+ ### Method 2: Single Volatility Measure
139
+ This method calculates stock price movement based on a single, constant measure of volatility derived from the entire historical data set available.
140
+ """)
 
 
 
 
 
 
 
 
141
 
142
  st.plotly_chart(fig2)
143
  else:
144
  st.write("No data found for the given ticker and date range.")
145
 
146
+ # Hide Streamlit's menu and footer
147
  hide_streamlit_style = """
148
  <style>
149
  #MainMenu {visibility: hidden;}
150
  footer {visibility: hidden;}
151
  </style>
152
  """
153
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)