【问题标题】:How to generate random time series data with noise in python 3?如何在 python 3 中生成带有噪声的随机时间序列数据?
【发布时间】:2021-08-30 18:31:26
【问题描述】:

这个python 2代码生成带有一定噪声的随机时间序列数据:

from common import arbitrary_timeseries
from commonrandom import  generate_trendy_price
from matplotlib.pyplot import show

ans=arbitrary_timeseries(generate_trendy_price(Nlength=180, Tlength=30, Xamplitude=10.0, Volscale=0.1))
ans.plot()
show()

输出:

有人知道我如何在 python 3 中生成这些数据吗?

【问题讨论】:

  • 当您尝试在 Python 3 中使用相同的代码时发生了什么?
  • 这能回答你的问题吗? Generate random timeseries data with dates
  • @mkrieger1 Python 3 不支持 commoncommonrandom 模块。
  • 它们到底是什么?
  • @crissal 不是真的我不能用那种方法产生噪音。但也许我可以稍后添加噪音嗯。

标签: python python-3.x python-2.7


【解决方案1】:

您可以使用像这样的简单马尔可夫过程:

import random

def random_timeseries(initial_value: float, volatility: float, count: int) -> list:
    time_series = [initial_value, ]
    for _ in range(count):
        time_series.append(time_series[-1] + initial_value * random.gauss(0, 1) * volatility)
    return time_series

ts = random_timeseries(1.2, 0.15, 100)

现在您有了可以使用任何时间戳压缩的随机值列表。

【讨论】:

    猜你喜欢
    • 2011-03-20
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 2017-12-31
    • 2019-12-24
    相关资源
    最近更新 更多