logo search
Avtomatizatsia_ekonomicheskih_raschetov_v_Excel

Текст макроса для генерации временного ряда

Private Sub CommandButton1_Click()

Randomize Timer

Tip = Int(1 + 4 * Rnd(Timer))

Cells(2, 12) = Tip: 'Tip = 4

For i = 1 To 50

If Tip = 1 Then y = 60 + 200 * i + 600 * Sin(i / 2) + (-300 + 600 * Rnd(Timer))

If Tip = 2 Then y = 50 * Log(i) + 20 * Sin(i / 2) + (-10 + 20 * Rnd(Timer))

If Tip = 3 Then y = 20 + 5 * 2 ^ (i / 10) + 20 * Sin(i / 2) + (-10 + 20 * Rnd(Timer))

If Tip = 4 Then y = 50 + 300 * 2 ^ (-i / 5) + 30 * Sin(i / 2) + (-20 + 40 * Rnd(Timer))

Cells(i + 4, 2) = i

Cells(i + 4, 3) = y

Next

End Sub