コード例 #1
0
def _roll_adjusted_and_multiple_prices(data, instrument_code):
    """
    Roll multiple and adjusted prices

    THE POSITION MUST BE ZERO IN THE PRICED CONTRACT! WE DON'T CHECK THIS HERE

    :param data: dataBlob
    :param instrument_code: str
    :return:
    """
    print(landing_strip(80))
    print("")
    print("Rolling adjusted prices!")
    print("")

    diag_prices = diagPrices(data)

    current_multiple_prices = diag_prices.get_multiple_prices(instrument_code)

    # Only required for potential rollback
    current_adjusted_prices = diag_prices.get_adjusted_prices(instrument_code)

    try:
        updated_multiple_prices = update_multiple_prices_on_roll(data, current_multiple_prices, instrument_code)
        new_adj_prices = futuresAdjustedPrices.stich_multiple_prices(updated_multiple_prices)
    except Exception as e:
        data.log.warn("%s : went wrong when rolling: No roll has happened" % e)
        return failure

    # We want user input before we do anything
    compare_old_and_new_prices([current_multiple_prices, updated_multiple_prices,
                                current_adjusted_prices, new_adj_prices],
                               ["Current multiple prices", "New multiple prices",
                               "Current adjusted prices", "New adjusted prices"])
    print("")
    confirm_roll = input("Confirm roll adjusted prices for %s are you sure y/n:" % instrument_code)
    if confirm_roll!="y":
        print("\nUSER DID NOT WANT TO ROLL: Setting roll status back to previous state")
        return failure

    try:
        # Apparently good let's try and write rolled data
        price_updater = updatePrices(data)
        price_updater.add_adjusted_prices(instrument_code, new_adj_prices,
                                                                ignore_duplication=True)
        price_updater.add_multiple_prices(instrument_code, updated_multiple_prices,
                                                                ignore_duplication=True)

    except Exception as e:
        data.log.warn("%s went wrong when rolling: Going to roll-back to original multiple/adjusted prices" % e)
        rollback_adjustment(data, instrument_code, current_adjusted_prices, current_multiple_prices)
        return failure

    return success
コード例 #2
0
def display_roll_query_banner(current_roll_status, position_priced_contract, allowable_roll_states):
    print(landing_strip(80))
    print("Current State: %s" % current_roll_status)
    print("Current position in priced contract %d (if zero can Roll Adjusted prices)" % position_priced_contract)
    print("")
    print("These are your options:")
    print("")

    for state_number, state in enumerate(allowable_roll_states):
        print("%d) %s: %s" % (state_number, state, explain_roll_state(state)))

    print("")

    return success
コード例 #3
0
    def display_roll_query_banner(self):

        print(landing_strip(80))
        print("Current State: %s" % self.original_roll_status)
        print(
            "Current position in priced contract %d (if zero can Roll Adjusted prices)"
            % self.position_priced_contract)
        print("")
        print("These are your options:")
        print("")

        for state_number, state in enumerate(
                self.allowable_roll_states_as_list_of_str):
            print("%s: %s" % (state, explain_roll_state_str(state)))

        print("")
コード例 #4
0
def _roll_adjusted_and_multiple_prices(data: dataBlob,
                                       instrument_code: str) -> status:
    """
    Roll multiple and adjusted prices

    THE POSITION MUST BE ZERO IN THE PRICED CONTRACT! WE DON'T CHECK THIS HERE

    :param data: dataBlob
    :param instrument_code: str
    :return:
    """
    print(landing_strip(80))
    print("")
    print("Rolling adjusted prices!")
    print("")

    rolling_adj_and_mult_object = _rollingAdjustedAndMultiplePrices(
        data, instrument_code)

    # this will also do the roll calculations
    rolling_adj_and_mult_object.compare_old_and_new_prices()

    confirm_roll = input(
        "Confirm roll adjusted prices for %s are you sure y/n:" %
        instrument_code)
    if confirm_roll != "y":
        print(
            "\nUSER DID NOT WANT TO ROLL: Setting roll status back to previous state"
        )
        return failure

    try:
        rolling_adj_and_mult_object.write_new_rolled_data()
    except Exception as e:
        data.log.warn(
            "%s went wrong when rolling: Going to roll-back to original multiple/adjusted prices"
            % e)
        return failure

    return success