Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-033

MA(1) Process Generation

Problem

Generate a seeded MA(1) process. Call random.seed(seed), draw n standard normal innovations e[t] with random.gauss(0.0, 1.0), and return y[t] = e[t] + theta * e[t-1] for t >= 1 with y[0] = e[0].

Return an empty list when n is not positive.

Hint

Seeding inside the function keeps the output reproducible.

Test cases

case 1
in: [5,0.5,42]
expected: [-0.14409032957792836,-0.24494876512048347,-0.1977676617334221,0.6463257943150319,0.22340357876654446]
case 2
in: [4,-0.3,7]
expected: [-0.2558802884476004,0.5881955990507941,-0.3795256185380589,-0.24723957289625403]
case 3
in: [3,0,1]
expected: [1.2881847531554629,1.4494456086997711,0.06633580893826191]
case 4
in: [0,0.5,3]
expected: []
Starter codePython
import random
def ma1_generate(n, theta, seed):
    # Your code here
    pass

4 test cases · run your code against them in the editor