0

This python 2 code generates random time series data with a certain noise:

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()

Output:
enter image description here

Does someone know how I can generate this data in python 3?

poop
  • 49
  • 6
  • What happened when you tried to use the same code in Python 3? – mkrieger1 Jun 14 '21 at 21:09
  • Does this answer your question? [Generate random timeseries data with dates](https://stackoverflow.com/questions/56310849/generate-random-timeseries-data-with-dates) – crissal Jun 14 '21 at 21:24
  • @mkrieger1 That the `common` and `commonrandom` modules aren't supported in Python 3. – poop Jun 14 '21 at 21:24
  • What are they, anyway? – mkrieger1 Jun 14 '21 at 21:25
  • @crissal Not really I can't generate noise using that method. But maybe I can add noise later hmmm. – poop Jun 14 '21 at 21:27
  • @mkrieger1 I guess a library with common (random) functions for python 2. I've never used python2 to be fair. – poop Jun 14 '21 at 21:28
  • I thought you were just using it to create this example. – mkrieger1 Jun 14 '21 at 21:29
  • @mkrieger1 Found this example in an [interesting article](https://qoppac.blogspot.com/2015/11/using-random-data.html) and I wanted to recreate it in python 3. – poop Jun 14 '21 at 21:31
  • No but this [answer](https://stackoverflow.com/a/48359952/15673454) did help me out. Thanks to you guys I found this answer! – poop Jun 14 '21 at 21:43

1 Answers1

1

You can use simple Markov process like this one:

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)

Now you have list with random values which can be zipped with any timestamps. enter image description here

Andy Pavlov
  • 316
  • 2
  • 8