def get_wma(self, prices: int, parameter: str, shift: int = 0, round_value: bool = True, update: bool = True) -> float: """ Returns the weighted 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 shift: Prices shifted from current period. :param boolean round_value: Boolean that specifies whether return value should be rounded :param int prices: Number of prices to loop over for average :param parameter: Parameter to get the average of (e.g. open, close, high or low values) :return: WMA """ 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] wma = get_wma(data, prices, parameter) if round_value: return round(wma, self.precision) return wma
def get_wma(self, data: list, prices: int, parameter: str, round_value: bool = True) -> float: data = data[len(data) - prices:] wma = get_wma(data, prices, parameter, desc=False) return round(wma, self.precision) if round_value else wma
def test_wma(dummy_data: DATA_HINT, prices: int, parameter: str, desc: bool, expected: float): """ Test WMA. """ assert get_wma(data=dummy_data, prices=prices, parameter=parameter, desc=desc) == expected
def test_wma(dummy_data: List[Dict[str, float]], prices: int, parameter: str, desc: bool, expected: float): assert get_wma(data=dummy_data, prices=prices, parameter=parameter, desc=desc) == expected