Simple Moving Average (SMA) in a sequence of numbers is a function that returns average of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Simple Moving Average (SMA) in a sequence of numbers is a function that returns average of k data points back at every index of sequence. You may consider as you are calculating everyday average temperature for the last k days. For example, for the list [0, 1, -1, -2, -2] SMA of 2 points should return [None, 0.5, 0.0, 1.5, -2.0]. The first point is None because you dont have enough data to calculate back. Write a function named ama_2 to calculate moving average that takes input a list of numbers, returns a list numbers that includes SMA of 2 points. Note: Input and output should be of same length and first point in the output should be None. [23]: tmp [0, 1, -1, -2, -2] def sma_2(data): #Write the implementation pass 2 # Check if it works sma_2(tmp) Simple Moving Average (SMA) in a sequence of numbers is a function that returns average of k data points back at every index of sequence. You may consider as you are calculating everyday average temperature for the last k days. For example, for the list [0, 1, -1, -2, -2] SMA of 2 points should return [None, 0.5, 0.0, 1.5, -2.0]. The first point is None because you dont have enough data to calculate back. Write a function named ama_2 to calculate moving average that takes input a list of numbers, returns a list numbers that includes SMA of 2 points. Note: Input and output should be of same length and first point in the output should be None. [23]: tmp [0, 1, -1, -2, -2] def sma_2(data): #Write the implementation pass 2 # Check if it works sma_2(tmp)
Expert Answer:
Answer rating: 100% (QA)
Here is the implementation of the sma2 function in Python to calcula... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
How are direct and indirect materials costs distinguished?
-
Jim received a six-month extension (to October 15, 2018) to file his 2017 tax return. Jim actually filed the return on October 20, 2018, paying the $20,000 amount due at that time. He has no...
-
Assume that all assumptions of the single-index model hold, except that the covariance between residuals is a constant K instead of zero. Derive the covariance between the two securities and the...
-
a. Which states of a hydrogen atom can be excited by a collision with an electron with kinetic energy \(K=12.5 \mathrm{eV}\) ? Explain. b. After the collision the atom is not in its ground state....
-
The normal capacity of a factory is 8,000 units per month. Cost and production data follow: Standard application rate for fixed overhead . . . . . . . . . . . . ... $0.50 per unit Standard...
-
1. A wholesaler plans to double their retail sales team and sell more to their existing customers 2. A shoe manufacturer is considering developing other products that may be of interest to their...
-
The AGRI Venture: An Integrated Marketing Communications Program. Chapter 16 states that there are three major forms of cooperative advertising: horizontal, ingredient-sponsored and vertical. Discuss...
-
DC Voltage = 600V DC Voltage Ripple = 1V AC RMS Voltage = 240V AC Current Ripple = 0.5A Rated Power = 2.4kW Inverter Switching Frequency = 10kHz Loss in the inductor at rated power = 0.5%P 1. Design...
-
Discuss three examples of ethical challenges that HR professionals may encounter as they apply to modern organizations. How you would address each situation? How could you approach the problem?
-
Assume that annual interest rates are 6% in the United States and 9% in Switzerland. An FI can borrow (by issuing CDs) or lend (by purchasing CDs) at these rates. The spot rate is Sf1.35/$ a. If the...
-
On January 1, 2021, Bard Ltd. has a Class 8 (20% rate) UCC balance of $32,400. The Class 8 property are used in the company's business. The only transaction involving Class 8 property during 2021 was...
-
Amanda and George are married filing jointly. For 2022, they have the following: 46,000 Salary Tips 11,000 Cash gift from George's mom 13,000 8,000 Alimony from Amanda's x-husband* Income from...
-
Joe and Jill Bean, married taxpayers, expect to be subject to the ANT again this year. Near the end of the year, their ANT liability exceeds their regular tax liability by $30,000. Currently, Joe and...
-
Titrations for the total hardness of the mud and mud filtrate require 5.0 and 0.5 mL of 0.02 N versenate solution, respectively. If the volume fraction of water in the mud is 0.85, determine the...
-
What are the before image (BFIM) and after image (AFIM) of a data item? What is the difference between in-place updating and shadowing, with respect to their handling of BFIM and AFIM?
-
Consider the following continuous-time signal 1-t 0st <1 x(t) = otherwise
-
Let ¤ t ¤ 1 ¤ t ¤ 1, and zero otherwise, be the input to a 2 bit analog-to-digital converter. (a) For a sampling period T s = 0.025 sec. determine and plot using MATLAB...
-
We wish to design a discrete Butterworth filter that can be used in filtering a continuous-time signal. The frequency components of interest in this signal are between 0and 1 kHz, so we would like...
-
The exhaust gases of a compression-ignition engine are to be used to drive an exhaust gas turbo-supercharger. Estimate the mean pressure ratio of expansion and the isentropic enthalpy drop per kmol...
-
The following data refer to an analysis of a dual combustion cycle with a gas having specific heats varying linearly with temperature: The pressure and temperature of the gas at the end of...
-
The exhaust gas from a two-stroke cycle compression-ignition engine is exhausted at an elevated pressure into a large chamber. The gas from the chamber is subsequently expanded in a turbine. If the...
Study smarter with the SolutionInn App