Exemplo n.º 1
0
    def test_most_recent_date(self):
        # Most recent date should be the most recent candle in the db
        num_symbols = len(get_symbols())
        num_candles = 10 * num_symbols
        max_date = get_max_from_column(column='open_date')
        from_date = max_date - timedelta(hours=10)

        engineered_data = core.engineer_data(from_date=from_date)
        assert engineered_data.open_date.max() == max_date
Exemplo n.º 2
0
    def test_num_candles(self):
        # Number of candles should be proportional to number of hours from from_date
        num_symbols = len(get_symbols())
        num_candles = 11 * num_symbols
        max_date = get_max_from_column(column='open_date')
        from_date = max_date - timedelta(hours=10)

        engineered_data = core.engineer_data(from_date=from_date)
        assert len(engineered_data) == num_candles
Exemplo n.º 3
0
    def test_earliest_date(self):
        # Earliest engineered date should be from_date
        num_symbols = len(get_symbols())
        num_candles = 10 * num_symbols
        max_date = get_max_from_column(column='open_date')
        from_date = max_date - timedelta(hours=10)

        engineered_data = core.engineer_data(from_date=from_date)
        assert engineered_data.open_date.min() == from_date
Exemplo n.º 4
0
def insert_engineered_data(verbose=True):

    # Get indicators from subclasses
    indicators = list(CustomIndicator.__subclasses__())

    # Get columns for comparison to incoming indicators
    sql = 'SHOW COLUMNS IN engineered_data;'
    candle_cols = list(Database().execute(sql).Field)

    # TODO add_column assumes
    for indicator in indicators:
        if indicator.__name__ not in candle_cols:
            db.add_column('engineered_data', indicator.__name__, 'float(20,9)')

    # Get starting date for insert
    from_date = db.get_max_from_column(table='engineered_data',
                                       column='open_date')

    # If there's nothing in the table, populate the entire thing
    if not from_date:
        from_date = db.get_min_from_column(column='open_date')

    ins = engineer_data(from_date=from_date, verbose=verbose)

    # Convert to sql-friendly dates
    convert_to_sql = lambda x: DateConvert(x).date
    ins.open_date = ins.open_date.map(convert_to_sql)
    ins.close_date = ins.close_date.map(convert_to_sql)

    if verbose:
        print('Inserting engineered data into database...')

    Database().insert('engineered_data',
                      ins,
                      verbose=verbose,
                      auto_format=True)
Exemplo n.º 5
0
 def test_most_recent_date(self):
     # Most recent date should be the most recent candle in the db
     max_date = get_max_from_column(column='open_date')
     engineered_data = core.engineer_data()
     assert engineered_data.open_date.max() == max_date