features.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:CryptoBot 作者: AdeelMufti 项目源码 文件源码
def get_trend(books, trades):
    '''
    Returns the linear trend in previous trades for each data point in DataFrame
    of book data
    '''

    def trend(x):
        trades_n = trades.iloc[x.trades_indexes[0]:x.trades_indexes[1]]
        if len(trades_n) < 3:
            return 0
        else:
            return linregress(trades_n.index.values, trades_n.price.values)[0]
    return books.apply(trend, axis=1)


# def get_tick_df(min_ts, max_ts, live, convert_timestamps=False):
#     '''
#     Returns a DataFrame of ticks in time range
#     '''
#     if not live:
#         query = {'_id': {'$gt': min_ts, '$lt': max_ts}}
#         cursor = ticks_db.find(query).sort('_id', pymongo.ASCENDING)
#     else:
#         cursor = ticks_db.find({}).sort('$natural', pymongo.DESCENDING).limit(1)
#
#     ticks = pd.DataFrame(list(cursor))
#
#     if not ticks.empty:
#         ticks = ticks.set_index('_id')
#         if convert_timestamps:
#             ticks.index = pd.to_datetime(ticks.index, unit='s')
#     return ticks
#
# def get_ticks_indexes(books, ticks):
#     '''
#     Returns indexes of ticks closest to each data point in DataFrame
#     of book data
#     '''
#     def ticks_indexes(ts):
#         ts = int(ts)
#         return ticks.index.get_loc(ts, method='nearest')
#     return books.index.map(ticks_indexes)
#
# def get_buys_from_ticks(books, ticks):
#     '''
#     Returns a count of trades for each data point in DataFrame of book data
#     '''
#     def get_buy(x):
#         return ticks.iloc[x.ticks_indexes].buy
#     return books.apply(get_buy, axis=1)
#
# def get_sells_from_ticks(books, ticks):
#     '''
#     Returns a count of trades for each data point in DataFrame of book data
#     '''
#     def get_sell(x):
#         return ticks.iloc[x.ticks_indexes].sell
#     return books.apply(get_sell, axis=1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号