Complete the code to calculate the simple moving average of a list of numbers.
def simple_moving_average(data, window_size): moving_averages = [] for i in range(len(data) - window_size + 1): window = data[i:i + window_size] average = sum(window) / [1] moving_averages.append(average) return moving_averages
The simple moving average divides the sum of the window by the window size to get the average.
Complete the code to calculate the exponential moving average (EMA) smoothing factor.
def calculate_ema_smoothing_factor(window_size): smoothing_factor = 2 / ([1] + 1) return smoothing_factor
The smoothing factor for EMA is calculated as 2 divided by (window size plus 1).
Fix the error in the code to update the EMA value correctly.
def update_ema(current_value, previous_ema, smoothing_factor): ema = [1] * current_value + (1 - smoothing_factor) * previous_ema return ema
The EMA update formula multiplies the current value by the smoothing factor.
Fill both blanks to create a dictionary of moving averages for each window size.
def moving_averages_dict(data, window_sizes): averages = {size: simple_moving_average(data, [1]) for size in [2] return averages
The dictionary comprehension uses 'size' as the window size for each key and iterates over 'window_sizes'.
Fill all three blanks to filter data points and compute their moving averages.
filtered_data = [x for x in data if x [1] threshold] moving_avg = simple_moving_average(filtered_data, [2]) result = {i: moving_avg[i] for i in range(len(moving_avg)) if moving_avg[i] [3] 0}
The code filters data points greater than the threshold, uses the window size to compute moving averages, and selects positive averages.