コード例 #1
0
    def _extract_features(self, df_data: pd.DataFrame):
        """
        Computes the features we want and keep only what is necessary for the neural network
        Features:
            - Volume is adjusted in order to keep consistent value in case of stock splits
            - Bid and ask prices are transformed as followed : BIDLO ->(PRC - BIDLO)/PRC and (ASKHI - PRC) / PRC

        :param df_data: Example:
                        date	TICKER	COMNAM	            BIDLO	ASKHI	        PRC	        VOL	        RET 	SHROUT	    sprtrn
            PERMNO
            36468	20100104	SHW	SHERWIN WILLIAMS CO	61.17000	62.14000	61.67000	1337900.0	0.000324	113341.0	0.016043
            36468	20100105	SHW	SHERWIN WILLIAMS CO	59.55000	61.86000	60.21000	3081500.0	-0.023674	113341.0	0.003116

        :return: dataframe with modified features and only self._features as columns
        """
        df_data.BIDLO = (df_data.BIDLO - df_data.PRC) / df_data.PRC
        df_data.ASKHI = (df_data.ASKHI - df_data.PRC) / df_data.PRC
        df_data.VOL = df_data.VOL / df_data.SHROUT  # to compensate for stock splits
        df_data.RET = df_data.RET + 1.

        columns_to_get = self._features
        return df_data[columns_to_get]