3ab2df2decdc3ffe39f1dca511f11a39cee7f1704f57e8442a



주식수학: 가격과 호가





Python Code


up_bound_map = {2000:5, 5000:10, 20000:50, 50000:100, 200000:500, 500000:1000}

down_bound_map = {500000:500, 200000:100, 50000:50, 20000:10, 5000:5, 2000:1}


def get_hoga_won_delta(my_price, direction="up"):

    if my_price < 2000:

        return 1

    elif 2000 < my_price and my_price < 5000:

        return 5

    elif 5000 < my_price and my_price < 20000:

        return 10

    elif 20000 < my_price and my_price < 50000:

        return 50

    elif 50000 < my_price and my_price < 200000:

        return 100

    elif 200000 < my_price and my_price < 500000:

        return 500

    elif 500000 < my_price:

        return 1000

    elif direction=="up":

        return up_bound_map[my_price]

    elif direction=="down":

        return down_bound_map[my_price]


def get_hoga_won(close_price, hoga):

    """

    현재가 기준, 원하는 호가에 해당하는 금액을 리턴

    :param hoga: +1, +2, +3, +4, +5, 0, -1, -2, -3, -4, -5

    :param close_price: 

    :return:

    """


    if hoga == 0:

        return close_price


    # print(f"현재가: {close_price}")

    hoga_price = close_price


    if hoga > 0:

        for i in range(0, hoga):

            hoga_won_delta = get_hoga_won_delta(hoga_price, direction="up")

            hoga_price = hoga_price + hoga_won_delta

            # print(f"+{i+1}호가: {hoga_price}")

    elif hoga < 0:

        for i in range(hoga, 0):

            hoga_won_delta = get_hoga_won_delta(hoga_price, direction="down")

            hoga_price = hoga_price - hoga_won_delta

            # print(f"{-(i+5) - 1}호가: {hoga_price}")


    return hoga_price