def falling_snippet(parameters: Dict):
    split_point = parameters[SPLIT_POINT]
    quotes = parameters[QUOTES]
    growth_to_fall_power = -round(
        is_growth_to_fall(quotes[split_point - 2:split_point + 4]), 3)
    if growth_to_fall_power == 0:
        return None
    parameters[CUSTOM_FILE_NAME] = str(
        quotes[split_point - NUMBER_OF_ROWS_IN_SNIPPET_FILE].date) + "_" + str(
            quotes[split_point].date) + "." + str(growth_to_fall_power)
    amplitude_of_fall = quotes[split_point].close_price * (
        1 - PERCENT_OF_GROWTH_OR_FALL_AFTER_SNIPPET / 100)
    amplitude_of_rollback = quotes[split_point].high_price * (
        1 + PERCENT_OF_MAXIMUM_ALLOWED_ROLLBACK / 100)
    for pointer in range(split_point + 1,
                         split_point + PREDICTION_SIZE_IN_BUSINESS_DAYS + 1):
        # if graphic goes in the direction where we don't want
        if quotes[pointer].high_price > amplitude_of_rollback and is_green(
                quotes[pointer]):
            parameters[SNIPPET_TYPE] = SnippetTypes.hold
            return create_snippet(parameters)
        if quotes[pointer].close_price < amplitude_of_fall and is_red(
                quotes[pointer]):
            parameters[SNIPPET_TYPE] = SnippetTypes.sell
            return create_snippet(parameters)
        pointer += 1
    parameters[SNIPPET_TYPE] = SnippetTypes.hold
    return create_snippet(parameters)
def check_snippet(parameters: Dict):
    list_quotes = parameters[QUOTES]
    i = parameters[SPLIT_POINT]
    change_percent = round(list_quotes[i + PREDICTION_SIZE_IN_BUSINESS_DAYS].close_price / list_quotes[i].close_price - 1,3)
    parameters[CUSTOM_FILE_NAME] = str(list_quotes[i - NUMBER_OF_ROWS_IN_SNIPPET_FILE].date) + "_" + str(
        list_quotes[i].date) + "." + str(change_percent)
    return create_snippet(parameters)
Ejemplo n.º 3
0
def falling_snippet(parameters: Dict):
    split_point = parameters[SPLIT_POINT]
    quotes = parameters[QUOTES]
    amplitude_of_fall = quotes[split_point].close_price * (
        1 - PERCENT_OF_GROWTH_OR_FALL_AFTER_SNIPPET / 100)
    amplitude_of_rollback = quotes[split_point].high_price * (
        1 + PERCENT_OF_MAXIMUM_ALLOWED_ROLLBACK / 100)
    for pointer in range(split_point + 1,
                         split_point + PREDICTION_SIZE_IN_BUSINESS_DAYS + 1):
        # if graphic goes in the direction where we don't want
        if quotes[pointer].high_price > amplitude_of_rollback and is_green(
                quotes[pointer]):
            parameters[SNIPPET_TYPE] = SnippetTypes.hold
            return create_snippet(parameters)
        if quotes[pointer].close_price < amplitude_of_fall and is_red(
                quotes[pointer]):
            parameters[SNIPPET_TYPE] = SnippetTypes.sell
            return create_snippet(parameters)
        pointer += 1
    parameters[SNIPPET_TYPE] = SnippetTypes.hold
    return create_snippet(parameters)
def growing_snippet(parameters: Dict):
    split_point = parameters[SPLIT_POINT]
    quotes = parameters[QUOTES]
    if DecisionMaker.should_buy(parameters[QUOTES][0:split_point]) is None:
        return None
    amplitude_of_growth = quotes[split_point].close_price * (
        1 + PERCENT_OF_GROWTH_OR_FALL_AFTER_SNIPPET / 100)
    amplitude_of_rollback = quotes[split_point].low_price * (
        1 - PERCENT_OF_MAXIMUM_ALLOWED_ROLLBACK / 100)
    for pointer in range(split_point + 1,
                         split_point + PREDICTION_SIZE_IN_BUSINESS_DAYS + 1):
        # if graphic goes in the direction where we don't want
        if quotes[pointer].low_price < amplitude_of_rollback and is_red(
                quotes[pointer]):
            parameters[SNIPPET_TYPE] = SnippetTypes.hold
            return create_snippet(parameters)
        if quotes[pointer].close_price > amplitude_of_growth and is_green(
                quotes[pointer]):
            parameters[SNIPPET_TYPE] = SnippetTypes.buy
            return create_snippet(parameters)
        pointer += 1
    parameters[SNIPPET_TYPE] = SnippetTypes.hold
    return create_snippet(parameters)