jeudi 26 octobre 2017

Random data between start value and end value with min and max as well as standard deviation

How can i generate random walk data between a start value and an end value as well as limiting the minimum/maximum value and the standard deviation/fluctuations?

Here is my attempt to do this but for some reason the min and the max values are broken and sometimes the series goes over or under these values. It seems that the Start and the End value are respected but not the minimum and the maximum value. How can this be fixed? Also i would like to give the standard deviation of the fluctuations. How would that be achieved?

import numpy as np
import matplotlib.pyplot as plt

def generateRandomData(length,randomPerc, min,max,start, end):
    data_np = (np.random.random(length) - randomPerc).cumsum()
    data_np *= (max - min) / (data_np.max() - data_np.min())
    data_np += np.linspace(start - data_np[0], end - data_np[-1], len(data_np))
    return data_np

randomData=generateRandomData(length = 1000, randomPerc = 0.5, min = 50, max = 100, start = 66, end = 80)

## print values
print("Max Value",randomData.max())
print("Min Value",randomData.min())
print("Start Value",randomData[0])
print("End Value",randomData[len(randomData)-1])

## plot values
plt.figure()
plt.plot(range(randomData.shape[0]), randomData)
plt.show()
plt.close()




Aucun commentaire:

Enregistrer un commentaire