Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,8 @@ It simulates various market scenarios to analyze the dependencies between differ
|
|
| 18 |
Users can assess potential outcomes in terms of best, worst, and mean case scenarios.
|
| 19 |
""")
|
| 20 |
|
|
|
|
|
|
|
| 21 |
# Sidebar: How to Use (closed by default)
|
| 22 |
with st.sidebar.expander("How to Use", expanded=False):
|
| 23 |
st.write("""
|
|
@@ -64,23 +66,53 @@ if run_button and len(portfolio_tickers) == len(portfolio_weights):
|
|
| 64 |
st.markdown("This section explores how the portfolio performs under simulated market drop scenarios using copula models.")
|
| 65 |
|
| 66 |
with st.expander("Methodology", expanded=False):
|
|
|
|
|
|
|
| 67 |
st.markdown("""
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
""")
|
| 85 |
|
| 86 |
# Define the portfolio and allocation
|
|
|
|
| 18 |
Users can assess potential outcomes in terms of best, worst, and mean case scenarios.
|
| 19 |
""")
|
| 20 |
|
| 21 |
+
st.sidebar.title("Input Parameters")
|
| 22 |
+
|
| 23 |
# Sidebar: How to Use (closed by default)
|
| 24 |
with st.sidebar.expander("How to Use", expanded=False):
|
| 25 |
st.write("""
|
|
|
|
| 66 |
st.markdown("This section explores how the portfolio performs under simulated market drop scenarios using copula models.")
|
| 67 |
|
| 68 |
with st.expander("Methodology", expanded=False):
|
| 69 |
+
st.markdown("## Simulating Market Drop Scenarios: Best, Worst, and Mean Cases")
|
| 70 |
+
#st.markdown("## Transforming Returns")
|
| 71 |
st.markdown("""
|
| 72 |
+
To prepare the returns for copula modeling, we transform them to a uniform distribution using quantile transformation.
|
| 73 |
+
This is to ensure that the data fits within the range required by the copula model.
|
| 74 |
+
""")
|
| 75 |
+
st.latex(r"""
|
| 76 |
+
u_i = \frac{\text{rank}(R_i)}{n + 1}
|
| 77 |
+
""")
|
| 78 |
+
|
| 79 |
+
#st.markdown("## Fitting the Copula Model")
|
| 80 |
+
st.markdown("""
|
| 81 |
+
Next, we fit a multivariate Student-t copula to the transformed data. The copula model captures the dependencies between the stock returns to understand the joint behavior of the assets.
|
| 82 |
+
""")
|
| 83 |
+
st.latex(r"""
|
| 84 |
+
C_{\nu}(u_1, u_2, \ldots, u_d) = t_{\nu, \Sigma}(t_{\nu}^{-1}(u_1), t_{\nu}^{-1}(u_2), \ldots, t_{\nu}^{-1}(u_d))
|
| 85 |
+
""")
|
| 86 |
+
|
| 87 |
+
#st.markdown("## Simulating Scenarios")
|
| 88 |
+
st.markdown("""
|
| 89 |
+
Using the fitted copula model, we simulate a large number of return scenarios. This simulation helps us explore potential future outcomes
|
| 90 |
+
and assess the portfolio's risk under various market conditions.
|
| 91 |
+
""")
|
| 92 |
+
|
| 93 |
+
#st.markdown("## Market Drop Scenarios")
|
| 94 |
+
st.markdown("""
|
| 95 |
+
We identify scenarios where the specified ticker drops by the given percentage. By analyzing these scenarios, we can evaluate how the portfolio performs under stress.
|
| 96 |
+
""")
|
| 97 |
+
|
| 98 |
+
#st.markdown("## Portfolio Returns")
|
| 99 |
+
st.markdown("""
|
| 100 |
+
For each identified scenario, we calculate the portfolio returns. The portfolio return is a weighted sum of the individual stock returns.
|
| 101 |
+
""")
|
| 102 |
+
st.latex(r"""
|
| 103 |
+
R_p = \sum_{i=1}^{n} w_i R_i
|
| 104 |
+
""")
|
| 105 |
+
|
| 106 |
+
#st.markdown("## Visualizing Results")
|
| 107 |
+
st.markdown("""
|
| 108 |
+
We visualize the simulated portfolio returns using histograms, cumulative distribution functions, and kernel density estimates.
|
| 109 |
+
These visualizations help us understand the distribution and characteristics of potential returns.
|
| 110 |
+
""")
|
| 111 |
+
|
| 112 |
+
#st.markdown("## Portfolio Price Trajectory")
|
| 113 |
+
st.markdown("""
|
| 114 |
+
Finally, we visualize the portfolio's price trajectory under the worst-case, best-case, and mean scenarios.
|
| 115 |
+
This helps in understanding the potential impact of market drops on the portfolio value.
|
| 116 |
""")
|
| 117 |
|
| 118 |
# Define the portfolio and allocation
|