コード例 #1
0
 def test_cdatafame_with_data_inside_should_be_valid(self):
     cdataframe = COHLCDataFrame(self.dataframe1)
     self.assertTrue(cdataframe.is_valid())
     self.assertTrue(
         list(cdataframe.dataframe.columns) ==
         ["time", "open", "high", "low", "close", "volume"])
     self.assertEqual(cdataframe.dataframe.iloc[0].time,
                      pd.to_datetime("2020-05-14"))
コード例 #2
0
 def test_cdatafame_should_be_valid(self):
     df = pd.DataFrame([{
         "open": 1,
         "high": 5,
         "low": 2,
         "close": 3,
         "volume": 15000,
         "time": pd.to_datetime("2020-05-18"),
         "ticker": "PETR4"
     }])
     cdataframe = COHLCDataFrame(df)
     self.assertTrue(cdataframe.is_valid())
     self.assertTrue(
         list(cdataframe.dataframe.columns) ==
         ["time", "open", "high", "low", "close", "volume"])
コード例 #3
0
    def setUp(self):
        dataframe1 = pd.DataFrame([
            {"open": 1, "high":5, "low": 2, "close":3, "volume": 15000, 
                "time": pd.to_datetime("2020-05-18"), "ticker": "PETR4", "timeframe": "M15"},
            {"open": 1, "high":5, "low": 2, "close":3, "volume": 15000, 
                "time": pd.to_datetime("2020-05-19"), "ticker": "PETR4", "timeframe": "M15"},
            {"open": 14, "high":14, "low": 14, "close":14, "volume": 14, 
                "time": pd.to_datetime("2020-05-14"), "ticker": "PETR4", "timeframe": "M15"},
            {"open": 14, "high":14, "low": 14, "close":5, "volume": 14, 
                "time": pd.to_datetime("2020-05-20"), "ticker": "PETR4", "timeframe": "M15"},
            {"open": 14, "high":14, "low": 14, "close":8, "volume": 14, 
                "time": pd.to_datetime("2020-05-21"), "ticker": "PETR4", "timeframe": "M15"},
        ])
        cdataframe = COHLCDataFrame(dataframe1)
        self.indicator = IndicatorsFactory().build_from_dict({
            "indicator": "roc",
            "params": {
                "period": 2
            }
        })
        self.indicator1 = IndicatorsFactory().build_from_dict({
            "indicator": "roc",
            "params": {
                "period": 1
            }
        })
        self.calculator = Calculator(cdataframe)

        self.calculator.add_indicator(self.indicator)
        self.calculator.add_indicator(self.indicator1)
コード例 #4
0
    def test_create_a_collection_of_indicators_should_only_accept_indicators(
            self):
        collection = CDataFrameCollection()

        df = pd.DataFrame([{
            "open": 1,
            "high": 5,
            "low": 2,
            "close": 3,
            "volume": 15000,
            "time": pd.to_datetime("2020-05-18"),
            "ticker": "PETR4"
        }])
        cdataframe = COHLCDataFrame(df)
        self.assertTrue(cdataframe.is_valid())

        self.assertTrue(collection.add(cdataframe))
        with self.assertRaises(Exception):
            collection.add("should not accept string")
コード例 #5
0
ファイル: get_data.py プロジェクト: Janderson/algo_trading
 def get_stocks(self, stock_timeframes, qtd_bars=5000):
     _collection = CDataFrameCollection()
     with MT5Connection() as mt5_conn:
         for ticker, timeframe in stock_timeframes:
             bars_df = mt5_conn.get_bars_to_df(ticker,
                                               timeframe,
                                               qtd=qtd_bars)
             _collection.add(
                 COHLCDataFrame(bars_df,
                                info={
                                    "ticker": ticker,
                                    "timeframe": timeframe
                                }))
     return _collection
コード例 #6
0
 def test_cdatafame_with_ticker_columns_should_get_this_info(self):
     cdataframe = COHLCDataFrame(self.dataframe1)
     self.assertTrue(cdataframe.is_valid())
     self.assertEqual(cdataframe.info["ticker"], "PETR4")
     self.assertEqual(cdataframe.info["timeframe"], "M15")
コード例 #7
0
 def test_cdatafame_should_return_a(self):
     df = pd.DataFrame()
     dataframe = COHLCDataFrame(df)
     self.assertEqual(type(dataframe.get()), pd.DataFrame)
     self.assertFalse(dataframe.is_valid())
コード例 #8
0
 def from_csv(self, csv_path):
     return COHLCDataFrame(
         pd.read_csv(csv_path).rename({"tick_volume": "volume"}, axis=1))