Added explanation for heatmap and basic portfolio return (#43)
Browse files- Added explanation for heatmap and basic portfolio return (bf04b3da159beb901af262ef20a622e8465e8a46)
Co-authored-by: Vi Koi Nguyen <Yim-Koi@users.noreply.huggingface.co>
app.py
CHANGED
@@ -31,14 +31,7 @@ from sharp_ratio import(
|
|
31 |
sharp_ratio_func
|
32 |
)
|
33 |
|
34 |
-
|
35 |
-
if num >=5 and num <15:
|
36 |
-
return 'Low Risk Aversion'
|
37 |
-
elif num >= 15 and num <25:
|
38 |
-
return 'Medium Risk Aversion'
|
39 |
-
elif num >= 25 and num <=35:
|
40 |
-
return 'High Rish Aversion'
|
41 |
-
#### Koi
|
42 |
|
43 |
def load_heading():
|
44 |
"""The function that displays the heading.
|
@@ -59,7 +52,7 @@ def get_choices():
|
|
59 |
choices = {}
|
60 |
#tab1, tab2, tab3, tab4, tab5 = st.tabs(["Tickers", "Quantity", "Benchmark","Risk Free Return","Risk Aversion"])
|
61 |
|
62 |
-
tickers = st.sidebar.text_input('Enter stock tickers.', 'GOOG,
|
63 |
|
64 |
# Set the weights
|
65 |
weights_str = st.sidebar.text_input('Enter the investment quantities', '50,30,25,25')
|
@@ -210,7 +203,59 @@ return is calculated. The model results can be found in Appendix A.
|
|
210 |
|
211 |
"""
|
212 |
##### ##### Koi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
basic_portfolio(choices['combined_df'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
display_heat_map(choices['data'],choices['choices'])
|
215 |
#display_portfolio_return(choices['combined_df'], choices['choices'])
|
216 |
preprocess(choices['raw_data'], choices['choices'])
|
|
|
31 |
sharp_ratio_func
|
32 |
)
|
33 |
|
34 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
def load_heading():
|
37 |
"""The function that displays the heading.
|
|
|
52 |
choices = {}
|
53 |
#tab1, tab2, tab3, tab4, tab5 = st.tabs(["Tickers", "Quantity", "Benchmark","Risk Free Return","Risk Aversion"])
|
54 |
|
55 |
+
tickers = st.sidebar.text_input('Enter stock tickers.', 'GOOG,AA,AVOG,AMD')
|
56 |
|
57 |
# Set the weights
|
58 |
weights_str = st.sidebar.text_input('Enter the investment quantities', '50,30,25,25')
|
|
|
203 |
|
204 |
"""
|
205 |
##### ##### Koi
|
206 |
+
# Creates the title for streamlit
|
207 |
+
st.subheader('Portfolio Historical Normalized Cumulative Returns')
|
208 |
+
"""
|
209 |
+
Cumulative Returns:\n
|
210 |
+
The cumulative return of an asset is calculated by subtracting the original price paid from the current profit or loss. This answers the question,
|
211 |
+
what is the return on my initial investment?\n
|
212 |
+
The graph below shows the historical normalized cumulative returns for each of the chosen assets for the entire time period of the available data.
|
213 |
+
The default line chart shows tickers AA, AMD, AVGO, and GOOG and we can see that all have a positive cumulative return over the period of the available data.
|
214 |
+
Any of these assets purchased on the starting day and sold on the ending day for the period would have earned a return on their investment.\n
|
215 |
+
This chart can also be used to analyze the correlation of the returns of the chosen assets over the displayed period.
|
216 |
+
Any segments of the line charts that show cumulative returns with similarly or oppositely angled segments can be considered to have some level of
|
217 |
+
correlation during those periods.
|
218 |
+
"""
|
219 |
basic_portfolio(choices['combined_df'])
|
220 |
+
"""
|
221 |
+
Negative Correlations (1): \n
|
222 |
+
Occur for assets whose cumulative returns move in opposite directions. When one goes up the other goes down and vice versa.
|
223 |
+
These negatively correlated assets would offer some level of diversification protection to each other.
|
224 |
+
Perfectly negatively correlated stocks are sort of the goal, but unlikely to be common.
|
225 |
+
In most cases finding some level of negatively correlated stocks, should offer some level of diversification protection to your portfolio.
|
226 |
+
The amount of protection depends upon the calculated metric. Our tool includes some CAPM analysis, which attempts to relate the risk and return
|
227 |
+
and the correlation of assets to determine the expected portfolio returns versus the combined, hopefully reduced, risk.\n
|
228 |
+
|
229 |
+
Positive Correlations (2):\n
|
230 |
+
Occur for assets whose cumulative returns move in concert. When one goes up the other also goes up and vice versa.
|
231 |
+
These positively correlated assets would not offer much or any diversification protection to each other.\n
|
232 |
+
"""
|
233 |
+
im = Image.open('1vs2.png')
|
234 |
+
col1, col2, col3 = st.columns([1,6,1])
|
235 |
+
|
236 |
+
with col1:
|
237 |
+
st.write("")
|
238 |
+
|
239 |
+
with col2:
|
240 |
+
st.image(im, caption='Trends of Assets Correlations',use_column_width='auto')
|
241 |
+
|
242 |
+
with col3:
|
243 |
+
st.write("")
|
244 |
+
|
245 |
+
# Creates the title for streamlit
|
246 |
+
st.subheader('Heatmap Showing Correlation Of Assets')
|
247 |
+
"""
|
248 |
+
Heatmap: \n
|
249 |
+
The Heat map shows the overall correlation of each asset to the other assets. Notice that the middle diagonal row is filled in with all 1’s.
|
250 |
+
That is because they are all perfectly correlated with themselves. A value of 1 equates to perfect correlation, -1 equates to perfect negative correlation,
|
251 |
+
and 0 equates to no correlation with values in between being relative to their distance from the extremes. A correlation value of .5 would mean
|
252 |
+
the asset moves half as much in the same direction as the correlated asset. A values of -0.5 would mean it moves half as much in the opposite direction
|
253 |
+
as the correlated asset. \n
|
254 |
+
The Heat map shows the correlation coefficient or value for each asset over the entire period to each other asset.
|
255 |
+
It also depicts the color of the intersection as darker for less correlation and lighter for more correlation, which could be either positive or negative.
|
256 |
+
The legend on the right indicates the absolute level of correlation for each color, again positive or negative associated to each color.\n
|
257 |
+
"""
|
258 |
+
|
259 |
display_heat_map(choices['data'],choices['choices'])
|
260 |
#display_portfolio_return(choices['combined_df'], choices['choices'])
|
261 |
preprocess(choices['raw_data'], choices['choices'])
|