Spaces:
Running
Running
Commit
•
700757f
1
Parent(s):
e7d2f5f
Update app.py
Browse files
app.py
CHANGED
@@ -110,6 +110,7 @@ def plot_price_with_cones(data, bootstrap_percentiles, days, thresholds, bootstr
|
|
110 |
return fig
|
111 |
|
112 |
# Streamlit app
|
|
|
113 |
st.title('Stock Price Simulation')
|
114 |
|
115 |
st.sidebar.header('Input Parameters')
|
@@ -120,6 +121,28 @@ This application simulates future stock prices using bootstrapping simulation me
|
|
120 |
You can specify the stock ticker, the date range, the number of simulation days, the number of simulations, and price thresholds.
|
121 |
The simulation results will show the probability of the stock price falling below, between, or above the specified thresholds.
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
**How to use:**
|
124 |
1. Enter the stock ticker, start date, and end date.
|
125 |
2. Set the number of days for the simulation and the number of iterations.
|
@@ -138,7 +161,7 @@ end_date = st.sidebar.date_input('End Date', pd.to_datetime('2025-01-01'))
|
|
138 |
days = st.sidebar.number_input('Number of Days for Simulation', min_value=1, max_value=365, value=30)
|
139 |
n_iterations = st.sidebar.number_input('Number of Simulations', min_value=100, max_value=100000, value=10000)
|
140 |
threshold1 = st.sidebar.number_input('Threshold 1', min_value=0, value=850)
|
141 |
-
threshold2 = st.sidebar.number_input('Threshold 2', min_value=0, value=
|
142 |
thresholds = [threshold1, threshold2]
|
143 |
|
144 |
if st.sidebar.button('Run Simulation'):
|
@@ -175,4 +198,6 @@ if st.sidebar.button('Run Simulation'):
|
|
175 |
- The probability of the stock price being below Threshold 1: {bootstrap_probabilities["below"]:.2%}
|
176 |
- The probability of the stock price being between Threshold 1 and Threshold 2: {bootstrap_probabilities["between"]:.2%}
|
177 |
- The probability of the stock price being above Threshold 2: {bootstrap_probabilities["above"]:.2%}
|
|
|
|
|
178 |
""")
|
|
|
110 |
return fig
|
111 |
|
112 |
# Streamlit app
|
113 |
+
st.set_page_config(layout="wide")
|
114 |
st.title('Stock Price Simulation')
|
115 |
|
116 |
st.sidebar.header('Input Parameters')
|
|
|
121 |
You can specify the stock ticker, the date range, the number of simulation days, the number of simulations, and price thresholds.
|
122 |
The simulation results will show the probability of the stock price falling below, between, or above the specified thresholds.
|
123 |
|
124 |
+
**Background and Concept**
|
125 |
+
|
126 |
+
The concept of bootstrapping was introduced by Bradley Efron in 1979. The primary goal of bootstrapping is to understand the variability of a statistic by generating multiple samples from the observed data. This approach assumes that the sample data represents the population, allowing us to draw inferences about the population from the sample.
|
127 |
+
|
128 |
+
**Steps in Bootstrapping:**
|
129 |
+
|
130 |
+
Given a dataset \( X = \{x_1, x_2, ..., x_n\} \), we aim to estimate the statistic \( \theta \) (e.g., the mean return of a stock).
|
131 |
+
|
132 |
+
1. **Resampling**: Create a resample \( X^* \) by drawing \( n \) observations from \( X \) with replacement. This means that each data point can be selected multiple times in a single resample:
|
133 |
+
""")
|
134 |
+
st.latex(r'X^* = \{x_1^*, x_2^*, ..., x_n^*\}')
|
135 |
+
st.write("""
|
136 |
+
2. **Statistic Calculation**: Calculate the statistic \( \theta^* \) for the resample \( X^* \):
|
137 |
+
""")
|
138 |
+
st.latex(r'\theta^* = f(X^*)')
|
139 |
+
st.write("""
|
140 |
+
3. **Repeat**: Repeat the above steps \( B \) times to generate \( B \) bootstrap statistics:
|
141 |
+
""")
|
142 |
+
st.latex(r'\{\theta_1^*, \theta_2^*, ..., \theta_B^*\}')
|
143 |
+
st.write("""
|
144 |
+
4. **Estimate**: Use the bootstrap statistics to estimate the mean, standard error, and confidence intervals of \( \theta \).
|
145 |
+
|
146 |
**How to use:**
|
147 |
1. Enter the stock ticker, start date, and end date.
|
148 |
2. Set the number of days for the simulation and the number of iterations.
|
|
|
161 |
days = st.sidebar.number_input('Number of Days for Simulation', min_value=1, max_value=365, value=30)
|
162 |
n_iterations = st.sidebar.number_input('Number of Simulations', min_value=100, max_value=100000, value=10000)
|
163 |
threshold1 = st.sidebar.number_input('Threshold 1', min_value=0, value=850)
|
164 |
+
threshold2 = st.sidebar.number_input('Threshold 2', min_value=0, value=1050)
|
165 |
thresholds = [threshold1, threshold2]
|
166 |
|
167 |
if st.sidebar.button('Run Simulation'):
|
|
|
198 |
- The probability of the stock price being below Threshold 1: {bootstrap_probabilities["below"]:.2%}
|
199 |
- The probability of the stock price being between Threshold 1 and Threshold 2: {bootstrap_probabilities["between"]:.2%}
|
200 |
- The probability of the stock price being above Threshold 2: {bootstrap_probabilities["above"]:.2%}
|
201 |
+
|
202 |
+
These results help in understanding the potential future movements of the stock price based on historical data and bootstrapping simulation.
|
203 |
""")
|