def _get_most_probable_outcome(self, day_index): | |
previous_data_start_index = max(0, day_index - self.n_latency_days) | |
previous_data_end_index = max(0, day_index - 1) | |
previous_data = self._test_data.iloc[previous_data_end_index: previous_data_end_index] | |
previous_data_features = StockPredictor._extract_features( | |
previous_data) | |
outcome_score = [] | |
for possible_outcome in self._possible_outcomes: | |
total_data = np.row_stack( | |
(previous_data_features, possible_outcome)) | |
outcome_score.append(self.hmm.score(total_data)) | |
most_probable_outcome = self._possible_outcomes[np.argmax( | |
outcome_score)] | |
return most_probable_outcome | |
def predict_close_price(self, day_index): | |
open_price = self._test_data.iloc[day_index]['open'] | |
predicted_frac_change, _, _ = self._get_most_probable_outcome( | |
day_index) | |
return open_price * (1 + predicted_frac_change) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment