<jupyter_start><jupyter_text>Yin's Capital ProductThis notebook walks readers through the procedure of installing *YinPortfolioManagement*. Here we introduce the following usages.- Installation- Use RNN3 RegressorAll rights reserved to Yiqiao Yin.  Installation<jupyter_code># !pip install git+https://github.com/yiqiao-yin/YinPortfolioManagement.git<jupyter_output><empty_output><jupyter_text>Usage of RNN3 RegressorWhat is LSTM or RNN? Recurrent Neural Network (a sequential model)Given data $X$ and $Y$, we want to feed information forward into a time stamp. Then we form some belief and we make some initial predictions. We investigate our beliefs by looking at the loss function of the initial guesses and the real value. We update our model according to error we observed.  Architecture: Feed-forwardConsider data with time stamp$$X_{\langle 1 \rangle} \rightarrow X_{\langle 2 \rangle} \rightarrow \dots \rightarrow X_{\langle T \rangle}$$and feed-forward architecture pass information through exactly as the following:$$\text{Information in:} \rightarrow\begin{matrix}Y_{\langle 1 \rangle}, \hat{Y}_{\langle 1 \rangle} & Y_{\langle 2 \rangle}, \hat{Y}_{\langle 2 \rangle} &       & Y_{\langle T \rangle}, \hat{Y}_{\langle T \rangle} \\\uparrow               & \uparrow               &       & \uparrow \\X_{\langle 1 \rangle} \rightarrow    & X_{\langle 2 \rangle} \rightarrow    & \dots \rightarrow & X_{\langle T \rangle} \\\uparrow               & \uparrow               &       & \uparrow \\w_{\langle 1 \rangle}, b_{0, \langle 1 \rangle}    & w_{\langle 2 \rangle}, b_{0, \langle 2 \rangle}    &       & w_{\langle T \rangle}, b_{0, \langle T \rangle} \\\end{matrix}\rightarrow\text{Form beliefs about } Y_{\angle T \rangle}$$while the educated guesses $\hat{Y}_{\langle T \rangle}$ are our beliefs about real $Y$ at time stamp $T$.  Architecture: Feed-backwardLet us clearly define our loss function to make sure we have a proper grip of our mistakes. $$\mathcal{L} = \sum_t L(\hat{y}_{\langle t \rangle} - y_t)^2$$and we can compute the gradient $$\triangledown = \frac{\partial \mathcal{L}}{\partial a}$$and then with respect with parameters $w$ and $b$$$\frac{\partial \triangledown}{\partial w}, \frac{\partial \triangledown}{\partial a}$$and now with perspective of where we make our mistakes according to our parameters we can go backward$$\text{Information in:} \leftarrow\underbrace{\begin{matrix}Y_{\langle 1 \rangle}, \hat{Y}_{\langle 1 \rangle} & Y_{\langle 2 \rangle}, \hat{Y}_{\langle 2 \rangle} &       & Y_{\langle T \rangle}, \hat{Y}_{\langle T \rangle} \\\uparrow               & \uparrow               &       & \uparrow \\X_{\langle 1 \rangle} \leftarrow    & X_{\langle 2 \rangle} \leftarrow    & \dots \leftarrow & X_{\langle T \rangle} \\\uparrow               & \uparrow               &       & \uparrow \\w'_{\langle 1 \rangle}, b'_{0, \langle 1 \rangle}    & w'_{\langle 2 \rangle}, b'_{0, \langle 2 \rangle}    &       & w'_{\langle T \rangle}, b'_{0, \langle T \rangle} \\\end{matrix}}_{\text{Update: } w, b \text{ with } w', b'}\leftarrow\text{Total Loss: } \mathcal{L} (\hat{y}, y)$$and the *update* action in the above architecture is dependent on your optimizer specified in the algorithm.<jupyter_code>from YinCapital_forecast.modules import RNN_Regressor
tmp = RNN_Regressor(
    start_date =   '2013-01-01',
    end_date   =   '2021-07-14',
    tickers    =   'AAPL',
    numberOfPastDays = 50,
    cutoff     =   0.9,
    numOfHiddenLayer = 2,
    l1_units   =   50,
    l2_units   =   50,
    l3_units   =   50,
    dropOutRate = 0.3,
    optimizer  =   'adam',
    loss       =   'mean_squared_error',
    epochs     =   15,
    batch_size =   64,
    plotGraph  =   True,
    verbose    =   True )<jupyter_output>------------------------------------------------------------------------------

            MANUAL: To install this python package, please use the following code.

            # In a python notebook:
            # !pip install git+https://github.com/yiqiao-yin/YinPortfolioManagement.git
            # In a command line:
            # pip install git+https://github.com/yiqiao-yin/YinPortfolioManagement.git

            # Run
            tmp = RNN_Regressor(
                start_date       =   '2013-01-01',
                end_date         =   '2019-12-6',
                tickers          =   'AAPL',
                numberOfPastDays = 100,
                cutoff           =   0.8,
                numOfHiddenLayer = 3,
                l1_units         =   50,
                l2_units         =   50,
                l3_units         =   50,
                l4_units         =   30,
                l5_units         =   10,
                dropOutRate       =  0.2,
                optimizer  [...]<jupyter_text>A Deeper RNN: RNN5A curious question is the the following: does test set performance get better when we increase the number of hidden layers in a RNN architecture?<jupyter_code>tmp = RNN_Regressor(
    start_date =   '2013-01-01',
    end_date   =   '2021-07-14',
    tickers    =   'AAPL',
    numberOfPastDays = 120,
    cutoff     =   0.9,
    numOfHiddenLayer = 5,
    l1_units   =   50,
    l2_units   =   50,
    l3_units   =   50,
    dropOutRate = 0.3,
    optimizer  =   'adam',
    loss       =   'mean_squared_error',
    epochs     =   15,
    batch_size =   64,
    plotGraph  =   True,
    verbose    =   True )<jupyter_output>------------------------------------------------------------------------------

            MANUAL: To install this python package, please use the following code.

            # In a python notebook:
            # !pip install git+https://github.com/yiqiao-yin/YinPortfolioManagement.git
            # In a command line:
            # pip install git+https://github.com/yiqiao-yin/YinPortfolioManagement.git

            # Run
            tmp = RNN_Regressor(
                start_date       =   '2013-01-01',
                end_date         =   '2019-12-6',
                tickers          =   'AAPL',
                numberOfPastDays = 100,
                cutoff           =   0.8,
                numOfHiddenLayer = 3,
                l1_units         =   50,
                l2_units         =   50,
                l3_units         =   50,
                l4_units         =   30,
                l5_units         =   10,
                dropOutRate       =  0.2,
                optimizer  [...]
{'fraction_non_alphanumeric': 0.13405909797822707, 'fraction_numerical': 0.028149300155520994, 'mean_word_length': 1.8218516893374288, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '570121', 'license': 'MIT', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1836, 'n_words': 560, 'path': 'docs/python_MM_YinPortfolioManagement.ipynb', 'repo_name': 'yiqiao-yin/WYNAssociates', 'size': '6430'}