예제 #1
0
 def get_sma(self,
             data: list,
             prices: int,
             parameter: str,
             round_value: bool = True) -> float:
     data = data[len(data) - prices:]
     sma = get_sma(data, prices, parameter)
     return round(sma, self.precision) if round_value else sma
예제 #2
0
    def get_sma(self, prices: int, parameter: str, shift: int = 0, round_value: bool = True,
                update: bool = True) -> float:
        """
        Returns the simple moving average with run-time data and prices provided.
        :param update: Boolean for whether function should call API and get latest data or not.
        :param boolean round_value: Boolean that specifies whether return value should be rounded
        :param int prices: Number of values for average
        :param int shift: Prices shifted from current price
        :param str parameter: Parameter to get the average of (e.g. open, close, high or low values)
        :return: SMA
        """
        if not self.is_valid_average_input(shift, prices):
            raise ValueError('Invalid average input specified.')

        data = [self.get_current_data()] + self.data if update else self.get_total_non_updated_data()
        data = data[shift: prices + shift]  # Data now starts from shift and goes up to prices + shift
        sma = get_sma(data, prices, parameter)

        if round_value:
            return round(sma, self.precision)
        return sma