@@ -26,6 +26,7 @@ class StockData:
26
26
def __init__ (self , stock ):
27
27
self ._stock = stock
28
28
self ._sec = yf .Ticker (self ._stock .get_ticker ())
29
+ self ._min_max = MinMaxScaler (feature_range = (0 , 1 ))
29
30
30
31
def __data_verification (self , train ):
31
32
print ('mean:' , train .mean (axis = 0 ))
@@ -36,28 +37,27 @@ def __data_verification(self, train):
36
37
def get_stock_short_name (self ):
37
38
return self ._sec .info ['shortName' ]
38
39
40
+ def get_min_max (self ):
41
+ return self ._min_max
42
+
39
43
def get_stock_currency (self ):
40
44
return self ._sec .info ['currency' ]
41
45
42
46
def download_transform_to_numpy (self , time_steps ):
43
- min_max = MinMaxScaler (feature_range = (0 , 1 ))
44
47
end_date = datetime .today ()
45
48
print ('End Date: ' + end_date .strftime ("%Y-%m-%d" ))
46
49
data = yf .download ([self ._stock .get_ticker ()], start = self ._stock .get_start_date (), end = end_date )[['Close' ]]
47
50
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)
51
52
52
53
training_data = data [data ['Date' ] < self ._stock .get_validation_date ()].copy ()
53
54
test_data = data [data ['Date' ] >= self ._stock .get_validation_date ()].copy ()
54
55
training_data = training_data .set_index ('Date' )
55
56
# Set the data frame index using column Date
56
57
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)
59
59
60
- train_scaled = min_max .fit_transform (training_data )
60
+ train_scaled = self . _min_max .fit_transform (training_data )
61
61
self .__data_verification (train_scaled )
62
62
63
63
# Training Data Transformation
@@ -72,7 +72,7 @@ def download_transform_to_numpy(self, time_steps):
72
72
73
73
total_data = pd .concat ((training_data , test_data ), axis = 0 )
74
74
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 )
76
76
77
77
# Testing Data Transformation
78
78
x_test = []
@@ -83,16 +83,16 @@ def download_transform_to_numpy(self, time_steps):
83
83
84
84
x_test , y_test = np .array (x_test ), np .array (y_test )
85
85
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 )
87
87
88
- def __daterange (self , start_date , end_date ):
88
+ def __date_range (self , start_date , end_date ):
89
89
for n in range (int ((end_date - start_date ).days )):
90
90
yield start_date + timedelta (n )
91
91
92
92
def generate_future_data (self , time_steps , min_max , start_date , end_date ):
93
93
x_future = []
94
94
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 ):
96
96
x_future .append (single_date )
97
97
y_future .append (random .uniform (10 , 100 ))
98
98
0 commit comments