@@ -26,6 +26,7 @@ class StockData:
2626 def __init__ (self , stock ):
2727 self ._stock = stock
2828 self ._sec = yf .Ticker (self ._stock .get_ticker ())
29+ self ._min_max = MinMaxScaler (feature_range = (0 , 1 ))
2930
3031 def __data_verification (self , train ):
3132 print ('mean:' , train .mean (axis = 0 ))
@@ -36,28 +37,27 @@ def __data_verification(self, train):
3637 def get_stock_short_name (self ):
3738 return self ._sec .info ['shortName' ]
3839
40+ def get_min_max (self ):
41+ return self ._min_max
42+
3943 def get_stock_currency (self ):
4044 return self ._sec .info ['currency' ]
4145
4246 def download_transform_to_numpy (self , time_steps ):
43- min_max = MinMaxScaler (feature_range = (0 , 1 ))
4447 end_date = datetime .today ()
4548 print ('End Date: ' + end_date .strftime ("%Y-%m-%d" ))
4649 data = yf .download ([self ._stock .get_ticker ()], start = self ._stock .get_start_date (), end = end_date )[['Close' ]]
4750 data = data .reset_index ()
48- print (data )
49-
50- plotter = Plotter (True , self ._stock .get_project_folder (), self ._sec .info ['shortName' ], self ._sec .info ['currency' ], self ._stock .get_ticker ())
51+ #print(data)
5152
5253 training_data = data [data ['Date' ] < self ._stock .get_validation_date ()].copy ()
5354 test_data = data [data ['Date' ] >= self ._stock .get_validation_date ()].copy ()
5455 training_data = training_data .set_index ('Date' )
5556 # Set the data frame index using column Date
5657 test_data = test_data .set_index ('Date' )
57- print (test_data )
58- plotter .plot_histogram_data_split (training_data , test_data , self ._stock .get_validation_date ())
58+ #print(test_data)
5959
60- train_scaled = min_max .fit_transform (training_data )
60+ train_scaled = self . _min_max .fit_transform (training_data )
6161 self .__data_verification (train_scaled )
6262
6363 # Training Data Transformation
@@ -72,7 +72,7 @@ def download_transform_to_numpy(self, time_steps):
7272
7373 total_data = pd .concat ((training_data , test_data ), axis = 0 )
7474 inputs = total_data [len (total_data ) - len (test_data ) - time_steps :]
75- test_scaled = min_max .fit_transform (inputs )
75+ test_scaled = self . _min_max .fit_transform (inputs )
7676
7777 # Testing Data Transformation
7878 x_test = []
@@ -83,16 +83,16 @@ def download_transform_to_numpy(self, time_steps):
8383
8484 x_test , y_test = np .array (x_test ), np .array (y_test )
8585 x_test = np .reshape (x_test , (x_test .shape [0 ], x_test .shape [1 ], 1 ))
86- return (x_train , y_train ), (x_test , y_test ), (min_max , test_data )
86+ return (x_train , y_train ), (x_test , y_test ), (training_data , test_data )
8787
88- def __daterange (self , start_date , end_date ):
88+ def __date_range (self , start_date , end_date ):
8989 for n in range (int ((end_date - start_date ).days )):
9090 yield start_date + timedelta (n )
9191
9292 def generate_future_data (self , time_steps , min_max , start_date , end_date ):
9393 x_future = []
9494 y_future = []
95- for single_date in self .__daterange (start_date , end_date ):
95+ for single_date in self .__date_range (start_date , end_date ):
9696 x_future .append (single_date )
9797 y_future .append (random .uniform (10 , 100 ))
9898
0 commit comments