コード例 #1
0
ファイル: test_keras.py プロジェクト: yoraba/fx_rnn
    def test_predict(self):
        import io
        technical = TAlibWrapper().get_technicals_of_series(self._data)
        pre = self.rnn_wrapper.preprocess(technical)
        pre = TAlibWrapper().add_high_low_data(pre)
        Xall, yall = self.rnn_wrapper.make_data_and_label(pre)
        model = self.rnn_wrapper.loadModelFfile()
        prediction = model.predict(Xall)
        import matplotlib.pyplot as plt
        x = range(100)
        y = yall[-100:, 5]
        pred_y = prediction[-100:, 5]
        plt.ylim(-0.1, 1.1)
        plt.plot(x, [0.5] * len(y), label='border')
        plt.plot(x, y, label='answer')
        plt.plot(x, pred_y, label='prediction_prob')
        plt.plot(x, yall[-100:, 0], label='price')
        plt.legend()

        buffer = io.BytesIO()
        plt.savefig(buffer, format='png')
        buffer.seek(0)
        image = self.rnn_wrapper.plot2image(buffer, 0)
        self.rnn_wrapper.add_image2board("image", image)

        plt.show()
コード例 #2
0
ファイル: test_keras.py プロジェクト: yoraba/fx_rnn
 def test_make_data_and_label(self):
     technical = TAlibWrapper().get_technicals_of_series(self._data)
     pre = self.rnn_wrapper.preprocess(technical)
     pre = TAlibWrapper().add_high_low_data(pre)
     X, y = self.rnn_wrapper.make_data_and_label(pre)
     print(np.shape(X), np.shape(y))
     return True
コード例 #3
0
ファイル: test_keras.py プロジェクト: yoraba/fx_rnn
 def test_high_low_price(self):
     technical = TAlibWrapper().get_technicals_of_series(self._data)
     pre = self.rnn_wrapper.preprocess(technical)
     pre = TAlibWrapper().add_high_low_data(pre)
     Xall, yall = self.rnn_wrapper.make_data_and_label(pre)
     model = self.rnn_wrapper.loadModelFfile()
     prediction = model.predict(Xall)
     match = self.rnn_wrapper.high_low_score(yall, prediction)
     print(f"{match} / {len(yall)}")
コード例 #4
0
ファイル: test_keras.py プロジェクト: yoraba/fx_rnn
 def test_fit(self):
     technical = TAlibWrapper().get_technicals_of_series(self._data)
     pre = self.rnn_wrapper.preprocess(technical)
     pre = TAlibWrapper().add_high_low_data(pre)
     Xall, yall = self.rnn_wrapper.make_data_and_label(pre)
     partition = round(len(pre) * 0.7)
     Xtrain, ytrain = Xall[:partition], yall[:partition]
     model = self.rnn_wrapper.create_basic_lstm_model(Xtrain)
     result = self.rnn_wrapper.fit(model, Xtrain, ytrain)
     self.rnn_wrapper.save2file(result)
コード例 #5
0
ファイル: test_keras.py プロジェクト: yoraba/fx_rnn
 def test_test_sprit(self):
     technical = TAlibWrapper().get_technicals_of_series(self._data)
     pre = self.rnn_wrapper.preprocess(technical)
     pre = TAlibWrapper().add_high_low_data(pre)
     Xall, yall = self.rnn_wrapper.make_data_and_label(pre)
     partition = round(len(pre) * 0.7)
     Xtrain, ytrain = Xall[:partition], yall[:partition]
     print(np.shape(Xall), np.shape(yall), np.shape(Xtrain),
           np.shape(ytrain))
     self.assertEqual(partition, len(Xtrain))
コード例 #6
0
ファイル: test_keras.py プロジェクト: yoraba/fx_rnn
 def test_high_low_probability_with_border(self):
     technical = TAlibWrapper().get_technicals_of_series(self._data)
     pre = self.rnn_wrapper.preprocess(technical)
     pre = TAlibWrapper().add_high_low_data(pre)
     Xall, yall = self.rnn_wrapper.make_data_and_label(pre)
     model = self.rnn_wrapper.loadModelFfile()
     prediction = model.predict(Xall)
     match, total = self.rnn_wrapper.high_low_probavility_score_with_border(
         yall, prediction, 19)
     print(f"all data count:{len(yall)}")
     print(f"{match} / {total} {match/total}%")
コード例 #7
0
ファイル: test_keras.py プロジェクト: yoraba/fx_rnn
 def test_rmse(self):
     technical = TAlibWrapper().get_technicals_of_series(self._data)
     pre = self.rnn_wrapper.preprocess(technical)
     pre = TAlibWrapper().add_high_low_data(pre)
     Xall, yall = self.rnn_wrapper.make_data_and_label(pre)
     partition = round(len(pre) * 0.7)
     Xtrain, ytrain = Xall[:partition], yall[:partition]
     Xtest, ytest = Xall[partition:], yall[partition:]
     model = self.rnn_wrapper.loadModelFfile()
     rmse_train, rmse_test = self.rnn_wrapper.rmse_score(
         model, Xtrain, Xtest, ytrain, ytest, 0)
     print(f"RMSE train: {rmse_train} RMSE test: {rmse_test}")
コード例 #8
0
ファイル: test_keras.py プロジェクト: yoraba/fx_rnn
 def test_preprocess(self):
     answer = TAlibWrapper().get_technicals_of_series(self._data)
     before = np.shape(answer)
     answer = self.rnn_wrapper.preprocess(answer)
     answer = TAlibWrapper().add_high_low_data(answer)
     after = np.shape(answer)
     print(before, after)
     # self.assertEqual(before, after)
     # print(answer)
     print(f'min={np.min(answer)} max={np.max(answer)}')
     self.assertTrue(np.round(np.min(answer), 5) >= 0.)
     self.assertTrue(np.round(np.max(answer), 5) <= 1.)
     frame = pd.DataFrame(answer).iloc[:, :5]
     print(np.shape(frame))
     plotting.scatter_matrix(frame)
     import matplotlib.pyplot as plt
     plt.show()
     return True
コード例 #9
0
ファイル: keras_api.py プロジェクト: yoraba/fx_rnn
 def create_data(self):
     api = TAlib_API(self._context)
     data = api.get_technicals()
     data = self.rnn_wrapper.preprocess(data)
     data = TAlibWrapper().add_high_low_data(data)
     Xall, yall = self.rnn_wrapper.make_data_and_label(data)
     partition = round(len(yall) * 0.7)
     Xtrain, ytrain = Xall[:partition], yall[:partition]
     Xtest, ytest = Xall[partition:], yall[:partition]
     return Xall, yall, Xtrain, ytrain, Xtest, ytest
コード例 #10
0
class TAlib_API:

    def __init__(self, context):
        self.context = context
        self.wrapper = TAlibWrapper()

    def get_technicals(self):
        df =IndicativeDocument().docs2df()
        result = None
        for idx1, item in enumerate(df.columns.values[1:]):
            answer = self.wrapper.get_technicals_of_series(df.loc[:, item])
            if result is None:
                result = answer
            else:
                result = np.hstack((result, answer))
        # print(np.shape(result))
        return result
コード例 #11
0
ファイル: test_talib.py プロジェクト: yoraba/fx_rnn
 def test_technicals(self):
     answer = TAlibWrapper().get_technicals_of_series(self._data)
     print(answer)
コード例 #12
0
 def __init__(self, context):
     self.context = context
     self.wrapper = TAlibWrapper()