Beispiel #1
0
def _avoid_pacing_violation(last_call_datetime: datetime.datetime,
                            log: logger = logtoscreen("")):
    printed_warning_already = False
    while _pause_for_pacing(last_call_datetime):
        if not printed_warning_already:
            log.msg(
                "Pausing %f seconds to avoid pacing violation" %
                (datetime.datetime.now() - last_call_datetime).total_seconds())
            printed_warning_already = True
        pass
def _avoid_pacing_violation(last_call_datetime: datetime.datetime,
                            log: logger = logtoscreen("")):
    printed_warning_already = False
    while _pause_for_pacing(last_call_datetime):
        if not printed_warning_already:
            log.msg("Pausing %f seconds to avoid pacing violation" %
                    (last_call_datetime +
                     datetime.timedelta(seconds=PACING_INTERVAL_SECONDS) -
                     datetime.datetime.now()).total_seconds())
            printed_warning_already = True
        pass
def _is_imbalance_ratio_exceeded(current_tick_analysis: analysisTick,
                                 log: logger) -> bool:
    latest_imbalance_ratio = current_tick_analysis.imbalance_ratio
    latest_imbalance_ratio_exceeded = latest_imbalance_ratio > IMBALANCE_THRESHOLD

    if latest_imbalance_ratio_exceeded:
        log.msg("Imbalance ratio for ticker %s %f exceeds threshold %f" %
                (str(current_tick_analysis), latest_imbalance_ratio,
                 IMBALANCE_THRESHOLD))

    return latest_imbalance_ratio_exceeded
Beispiel #4
0
def calculate_buffers(instrument_code: str,
                      position: pd.Series,
                      config: Config,
                      vol_scalar: pd.Series,
                      instr_weights: pd.DataFrame = arg_not_supplied,
                      idm: pd.Series = arg_not_supplied,
                      log: logger = logtoscreen("")) -> pd.Series:

    log.msg(
        "Calculating buffers for %s" % instrument_code,
        instrument_code=instrument_code,
    )

    buffer_method = config.buffer_method

    if buffer_method == "forecast":
        log.msg(
            "Calculating forecast method buffers for %s" % instrument_code,
            instrument_code=instrument_code,
        )
        if instr_weights is arg_not_supplied:
            instr_weight_this_code = arg_not_supplied
        else:
            instr_weight_this_code = instr_weights[instrument_code]

        buffer = get_forecast_method_buffer(instr_weight_this_code=instr_weight_this_code,
                                            vol_scalar=vol_scalar,
                                            idm=idm,
                                            position=position,
                                            config=config)

    elif buffer_method == "position":
        log.msg(
            "Calculating position method buffer for %s" % instrument_code,
            instrument_code=instrument_code,
        )

        buffer = get_position_method_buffer(config=config,
                                                 position=position)
    elif buffer_method == "none":
        log.msg(
            "None method, no buffering for %s" % instrument_code,
            instrument_code=instrument_code,
        )

        buffer = get_buffer_if_not_buffering(
                                                  position=position)
    else:
        log.critical(
            "Buffer method %s not recognised - not buffering" % buffer_method
        )
        buffer = get_buffer_if_not_buffering(
                                                  position=position)

    return buffer
Beispiel #5
0
def _is_insufficient_size_on_our_preferred_side(
        ticker_object: tickerObject, current_tick_analysis: analysisTick,
        log: logger) -> bool:
    abs_size_we_wish_to_trade = abs(ticker_object.qty)
    size_we_require_to_trade_limit = IMBALANCE_ADJ_FACTOR * abs_size_we_wish_to_trade
    available_size_on_our_preferred_side = abs(current_tick_analysis.side_qty)

    insufficient_size_on_our_preferred_side = (
        available_size_on_our_preferred_side < size_we_require_to_trade_limit)

    if insufficient_size_on_our_preferred_side:
        log.msg(
            "On ticker %s we require size of %f (our trade %f * adjustment %f) for a limit order but only %f available"
            % (str(current_tick_analysis), size_we_require_to_trade_limit,
               abs_size_we_wish_to_trade, IMBALANCE_ADJ_FACTOR,
               available_size_on_our_preferred_side))

    return insufficient_size_on_our_preferred_side