# Path: pyti/catch_errors.py
# def check_for_period_error(data, period):
# def check_for_input_len_diff(*args):
# 
# Path: pyti/function_helper.py
# def fill_for_noncomputable_vals(input_data, result_data):
#     non_computable_values = np.repeat(
#         np.nan, len(input_data) - len(result_data)
#         )
#     filled_result_data = np.append(non_computable_values, result_data)
#     return filled_result_data
# 
# Path: pyti/simple_moving_average.py
# def simple_moving_average(data, period):
#     """
#     Simple Moving Average.
# 
#     Formula:
#     SUM(data / N)
#     """
#     catch_errors.check_for_period_error(data, period)
#     # Mean of Empty Slice RuntimeWarning doesn't affect output so it is
#     # supressed
#     with warnings.catch_warnings():
#         warnings.simplefilter("ignore", category=RuntimeWarning)
#         sma = [np.mean(data[idx-(period-1):idx+1]) for idx in range(0, len(data))]
#     sma = fill_for_noncomputable_vals(data, sma)
#     return sma


import numpy as np
from pyti import catch_errors
from pyti.function_helper import fill_for_noncomputable_vals
from pyti.simple_moving_average import (
    simple_moving_average as sma
    )
from six.moves import range
    """
    Middle Bollinger Band.

    Formula:
    m_bb = sma()
    """
    catch_errors.check_for_period_error(data, period)

    period = int(period)
    mid_bb = sma(data, period)

    return mid_bb


def lower_bollinger_band(data, period, std=2.0):
    """
    Lower Bollinger Band.

    Formula:
    u_bb = SMA(t) - STD(SMA(t-n:t)) * std_mult
    """
    catch_errors.check_for_period_error(data, period)

    period = int(period)
    simple_ma = sma(data, period)[period-1:]

    lower_bb = []
    for idx in range(len(data) - period + 1):
        std_dev = np.std(data[idx:idx + period])
        lower_bb.append(simple_ma[idx] - std_dev * std)

# Path: pyti/catch_errors.py
# def check_for_period_error(data, period):
# def check_for_input_len_diff(*args):
# 
# Path: pyti/function_helper.py
# def fill_for_noncomputable_vals(input_data, result_data):
#     non_computable_values = np.repeat(
#         np.nan, len(input_data) - len(result_data)
#         )
#     filled_result_data = np.append(non_computable_values, result_data)
#     return filled_result_data
# 
# Path: pyti/simple_moving_average.py
# def simple_moving_average(data, period):
#     """
#     Simple Moving Average.
# 
#     Formula:
#     SUM(data / N)
#     """
#     catch_errors.check_for_period_error(data, period)
#     # Mean of Empty Slice RuntimeWarning doesn't affect output so it is
#     # supressed
#     with warnings.catch_warnings():
#         warnings.simplefilter("ignore", category=RuntimeWarning)
#         sma = [np.mean(data[idx-(period-1):idx+1]) for idx in range(0, len(data))]
#     sma = fill_for_noncomputable_vals(data, sma)
#     return sma


# Path: pyti/bollinger_bands.py
import numpy as np
from pyti import catch_errors
from pyti.function_helper import fill_for_noncomputable_vals
from pyti.simple_moving_average import (
    simple_moving_average as sma
    )
from six.moves import range

    """
    Middle Bollinger Band.

    Formula:
    m_bb = sma()
    """
    catch_errors.check_for_period_error(data, period)

    period = int(period)
    mid_bb = sma(data, period)

    return mid_bb


def lower_bollinger_band(data, period, std=2.0):
    """
    Lower Bollinger Band.

    Formula:
    u_bb = SMA(t) - STD(SMA(t-n:t)) * std_mult
    """
    catch_errors.check_for_period_error(data, period)

    period = int(period)
    simple_ma = sma(data, period)[period-1:]

    lower_bb = []
    for idx in range(len(data) - period + 1):
        std_dev = np.std(data[idx:idx + period])
        lower_bb.append(simple_ma[idx] - std_dev * std)

    lower_bb = fill_for_noncomputable_vals(data, lower_bb)