# Path: speculator/features/TechnicalAnalysis.py
# class TechnicalAnalysis(abc.ABC):
#     """ Abstract class for calculating technical analysis indicators """
#     
#     @staticmethod
#     @abc.abstractmethod
#     def eval_algorithm(*args, **kwargs):
#         """ Evaluates TA algorithm """
# 
#     @staticmethod
#     @abc.abstractmethod
#     def eval_from_json(json):
#         """ Evaluates TA algorithm from JSON
# 
#         Args:
#             json: List of dates where each entry is a dict of raw market data.
#         """
# 
# Path: speculator/utils/poloniex.py
# def json_to_url(json, symbol):
# def chart_json(start, end, period, symbol):
# def parse_changes(json):
# def get_gains_losses(changes):
# def get_attribute(json, attr):
# def get_json_shift(year, month, day, unit, count, period, symbol):


from speculator.features.TechnicalAnalysis import TechnicalAnalysis
from speculator.utils import poloniex
    %K follows the speed/momentum of a price in a market
    """

    def eval_algorithm(closing, low, high):
        """ Evaluates the SO algorithm

        Args:
            closing: Float of current closing price.
            low: Float of lowest low closing price throughout some duration.
            high: Float of highest high closing price throughout some duration.

        Returns:
            Float SO between 0 and 100.
        """
        if high - low == 0: # High and low are the same, zero division error
            return 100 * (closing - low)
        else:
            return 100 * (closing - low) / (high - low)

    def eval_from_json(json):
        """ Evaluates SO from JSON (typically Poloniex API response)

        Args:
            json: List of dates where each entry is a dict of raw market data.

        Returns:
            Float SO between 0 and 100.
        """
        close  = json[-1]['close'] # Latest closing price
        low    = min(poloniex.get_attribute(json, 'low')) # Lowest low

# Path: speculator/features/TechnicalAnalysis.py
# class TechnicalAnalysis(abc.ABC):
#     """ Abstract class for calculating technical analysis indicators """
#     
#     @staticmethod
#     @abc.abstractmethod
#     def eval_algorithm(*args, **kwargs):
#         """ Evaluates TA algorithm """
# 
#     @staticmethod
#     @abc.abstractmethod
#     def eval_from_json(json):
#         """ Evaluates TA algorithm from JSON
# 
#         Args:
#             json: List of dates where each entry is a dict of raw market data.
#         """
# 
# Path: speculator/utils/poloniex.py
# def json_to_url(json, symbol):
# def chart_json(start, end, period, symbol):
# def parse_changes(json):
# def get_gains_losses(changes):
# def get_attribute(json, attr):
# def get_json_shift(year, month, day, unit, count, period, symbol):


# Path: speculator/features/SO.py
from speculator.features.TechnicalAnalysis import TechnicalAnalysis
from speculator.utils import poloniex

    %K follows the speed/momentum of a price in a market
    """

    def eval_algorithm(closing, low, high):
        """ Evaluates the SO algorithm

        Args:
            closing: Float of current closing price.
            low: Float of lowest low closing price throughout some duration.
            high: Float of highest high closing price throughout some duration.

        Returns:
            Float SO between 0 and 100.
        """
        if high - low == 0: # High and low are the same, zero division error
            return 100 * (closing - low)
        else:
            return 100 * (closing - low) / (high - low)

    def eval_from_json(json):
        """ Evaluates SO from JSON (typically Poloniex API response)

        Args:
            json: List of dates where each entry is a dict of raw market data.

        Returns:
            Float SO between 0 and 100.
        """
        close  = json[-1]['close'] # Latest closing price
        low    = min(poloniex.get_attribute(json, 'low')) # Lowest low

        high   = max(poloniex.get_attribute(json, 'high')) # Highest high