File size: 7,912 Bytes
60697f7
1e3e920
 
 
 
 
 
 
 
 
 
 
 
 
014addd
95325c0
 
 
b0e5414
1e3e920
95325c0
1e3e920
7e94170
1e3e920
60697f7
1e3e920
60697f7
1e3e920
 
 
60697f7
 
 
b0e5414
 
 
 
 
60697f7
 
 
 
 
 
 
 
 
 
 
36802e9
f5d8854
 
36802e9
 
 
 
 
 
 
828b2d5
 
36802e9
 
 
 
60697f7
 
de7640f
60697f7
de7640f
60697f7
de7640f
60697f7
de7640f
60697f7
 
 
1e3e920
 
 
7e94170
 
 
 
 
 
 
 
a1219fd
 
7e94170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46e7bbc
95325c0
 
 
 
 
 
 
 
 
46e7bbc
 
95325c0
014addd
 
 
95325c0
014addd
 
 
 
 
 
 
 
 
 
1e3e920
7e94170
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Copyright Yiqiao Yin.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime

import streamlit as st

from utils.helper import *


def run():
    st.set_page_config(page_title="Momentum-Strategy", page_icon="💹", layout="wide")

    st.write("# Welcome to the Momentum Strategy Simulator! 💹")

    st.sidebar.success("Select a language above.")

    st.markdown(
        """
        # Stock Return Simulation App
        
        This application is a return simulation tool for selected stocks. It allows users to simulate returns based on a momentum strategy using the 4th factor from the Carhart 4-factor model. The application automatically downloads stock data from Yahoo Finance live when the user presses the button, ensuring that the data is always refreshed to the most recent trading day records.
        """
    )

    st.markdown(
        """ 
        ## Usage
        
        1. **Downloading Data**: Click the "Download Data" button to fetch stock data from Yahoo Finance live. This action ensures that the data is up-to-date with the most recent trading day records.
        
        2. **Select Language**: The application supports multiple languages. Simply click on the desired language option on the left-hand side of the interface. The default language is English.
        
        3. **Momentum Strategy**: The application runs a momentum strategy based on the 4th factor from the Carhart 4-factor model. The strategy balances the portfolio once a month. Each month, the strategy selects a portfolio consisting of stocks that have performed the best in the past month in terms of stock growth rate.
        
        4. **Input Custom Stocks**: Users are free to input any stocks they like. Please separate the stock tickers using commas and ensure that the tickers are in capital letters.
        
        5. **No AI Involved**: Please note that there is no artificial intelligence involved in the strategy. It selects the strongest performing stocks based on the most recent records.

        6. **Momentum + MPT**: On a macro level, I'd adivse to run this app, which is [Momentum Strategy](https://huggingface.co/spaces/eagle0504/Momentum-Strategy-Screener), first. Then take the selected stocks to the second app, [Modern Portfolio Theory Demo](https://huggingface.co/spaces/eagle0504/MPT-Demo), and run again to assess reward-risk ratio.

        ## YouTube Video Explanation

        Please use the [link](https://youtu.be/C6Bc3pe369c?si=CpqDxFL86hQb4yKg).

        """
    )

    with st.expander("Please expand/collapse to watch/hide the video:"):
        st.video("https://youtu.be/C6Bc3pe369c?si=CpqDxFL86hQb4yKg")

    st.markdown(
        """        
        ## Instructions
        
        1. Click the "Download Data" button to fetch the latest stock data.

        2. Select your preferred language from the options provided.

        3. Input your desired stocks into the designated field, separated by commas.

        4. Explore the simulated returns based on the momentum strategy.

        5. Repeat the process as needed to adjust your stock selection and language preference.
        
        **Note**: This application is for simulation purposes only and does not provide investment advice. Always perform your own research or consult with a financial advisor before making investment decisions.
    """
    )

    with st.expander("Reference (Expand/Collapse)"):
        st.markdown(
            f"""
            # Factor Models and Mutual Fund Evaluation

            ## Monthly Momentum Factor (MOM)

            The Monthly Momentum Factor (MOM) can be calculated by subtracting the equal-weighted average of the lowest performing firms from the equal-weighted average of the highest performing firms, lagged one month (Carhart, 1997). A stock exhibits momentum if its prior 12-month average of returns is positive. Similar to the three-factor model, the momentum factor is defined by a self-financing portfolio of (long positive momentum) + (short negative momentum). Momentum strategies remain popular in financial markets, and financial analysts often incorporate the 52-week price high/low in their Buy/Sell recommendations.
            
            - Carhart, M. M. (1997). On persistence in mutual fund performance. The Journal of finance, 52(1), 57-82. [link](https://onlinelibrary.wiley.com/doi/10.1111/j.1540-6261.1997.tb03808.x)

            ## Four-Factor Model

            The four-factor model is commonly used for active management and mutual fund evaluation. Three commonly used methods to adjust a mutual fund's returns for risk are:

            ### 1. Market Model:

            $$
            EXR_t = α^J + β_mkt * EXMKT_t + ε_t
            $$

            The intercept in this model is referred to as "Jensen's alpha".

            ### 2. Fama–French Three-Factor Model:

            $$
            EXR_t = α^FF + β_mkt * EXMKT_t + β_HML * HML_t + β_SMB * SMB_t + ε_t
            $$

            The intercept in this model is referred to as the "three-factor alpha".

            ### 3. Carhart Four-Factor Model:

            $$
            EXR_t = α^c + β_mkt * EXMKT_t + β_HML * HML_t + β_SMB * SMB_t + β_UMD * UMD_t + ε_t
            $$

            The intercept in this model is referred to as the "four-factor alpha".

            `EXR_t` is the monthly return to the asset of concern in excess of the monthly t-bill rate. These models are used to adjust for risk by regressing the excess returns of the asset on an intercept (the alpha) and some factors on the right-hand side of the equation that attempt to control for market-wide risk factors. The right-hand side risk factors include the monthly return of the CRSP value-weighted index less the risk-free rate (`EXMKT_t`), monthly premium of the book-to-market factor (`HML_t`), monthly premium of the size factor (`SMB_t`), and the monthly premium on winners minus losers (`UMD_t`) from Fama-French (1993) and Carhart (1997).

            A fund manager demonstrates forecasting ability when their fund has a positive and statistically significant alpha.

            SMB is a zero-investment portfolio that is long on small capitalization (cap) stocks and short on big-cap stocks. Similarly, HML is a zero-investment portfolio that is long on high book-to-market (B/M) stocks and short on low B/M stocks, and UMD is a zero-cost portfolio that is long previous 12-month return winners and short previous 12-month loser stocks.
            """
        )

    with st.expander("Please expand/collapse to chat with an AI advisor:"):
        user_question = st.text_input(
            "Enter a question:", "What does the company NVIDIA do?"
        )
        ai_answer = call_gpt(
            prompt=user_question,
            content="""
            You are a Financial Advisor. You know all about FinTech, Corporate Finance, Modern Portfolio Theory, and knowledge like that.
            """,
        )
        st.markdown(ai_answer)

    # Credit
    def current_year():
        now = datetime.now()
        return now.year

    # Example usage:
    current_year = current_year()  # This will print the current year
    st.markdown(
        f"""
            <h6 style='text-align: left;'>Copyright © 2010-{current_year} Present Yiqiao Yin</h6>
        """,
        unsafe_allow_html=True,
    )


if __name__ == "__main__":
    run()