示例#1
0
def evaluate(strategy, type, files):
    strategy.clear()
    data = MarketData()

    ts = TradingSystem()

    for instrument, file in files.items():
        ts.createBook(instrument)
        ts.subscribe(instrument, strategy)
        if type == MarketData.TICK:
            data.loadBBGTick(file, instrument)
        elif type == MarketData.HIST:
            data.loadYAHOOHist(file, instrument)
        elif type == MarketData.INTR:
            data.loadBBGIntr(file, instrument)

    data.run(ts)

    ts.submit(strategy.id, strategy.close())
    return strategy.summary()
示例#2
0
def evaluateMult(strategies, instruments_list, var):
    #print('types: ', types)
    #print('files: ', files)
    #print('strategies: ', strategies)

    if (len(strategies) != len(instruments_list)):
        return (
            "ERROR! - evaluateMult arguments require the same number of items")

    for s in strategies:
        s.clear()

    data = MarketData()
    ts = TradingSystem()

    ts.createRisk(var)

    for i in range(0, len(strategies)):
        for instrument in instruments_list[i]:
            ts.createBook(instrument)
            ts.subscribe(instrument, strategies[i])
            '''
      if(types[i] == MarketData.TICK):
        data.loadBBGTick(file, instrument)
      if(types[i] == MarketData.HIST):
        data.loadYAHOOHist(file, instrument)
      if(types[i] == MarketData.INTR):
        data.loadBBGIntr(file, instrument)
      '''

    #data.loadBBGTick('2018-03-07.csv', "PETR4")
    data.loadFTP()

    data.run(ts)

    summary = []

    for strategy in strategies:
        print("strategy")
        ts.submit(strategy.id, strategy.close())
        summary.append(strategy.summary(name=strategy.name))

    return summary
示例#3
0
def evaluate(strategy, type, files, *, has_config=False):
    strategy.clear()
    data = MarketData()

    ts = TradingSystem()

    for instrument, file_data in files.items():
        ts.createBook(instrument)
        ts.subscribe(instrument, strategy)
        if type == MarketData.TICK:
            data.loadBBGTick(file_data, instrument)
        elif type == MarketData.HIST:
            data.loadYAHOOHist(file_data, instrument)
        elif type == MarketData.INTR:
            if has_config:
                data.loadBBGIntr(file_data[0],
                                 instrument,
                                 separator=file_data[1],
                                 date_format=file_data[2])
            else:
                data.loadBBGIntr(file_data, instrument)

    data.run(ts)

    ts.submit(strategy.id, strategy.close())
    return strategy.summary()
示例#4
0
                },
                'close': {
                    'type': 'float'
                },
                'volume': {
                    'type': 'float'
                },
                'product_id': {
                    'type': 'keyword'
                }
            }
        }
    }
    es.indices.create(index=index, body=es_settings)

    md = MarketData(exchange)
    products = ['BTC-USD']
    granularities = md.available_granularity().values
    start = datetime.datetime(year=2019, month=1, day=1)
    end = datetime.datetime(year=2019, month=6, day=1)

    for granularity in granularities:
        slices = TimeSlice.time_slice(start, end, granularity)
        for product_id in products:
            for _start, _end in slices:
                try:
                    Elasticsearch.bulk(
                        es,
                        md.es_candle_generator(index, product_id, _start, _end,
                                               granularity))
                except InvalidArgument as err: