I have a five period of data with their probabilities and I would like to simulate it with 20000 times with the Poisson distribution, I want the x-axis start from 0-1, I tried but I stock with that my code here: And is there any way to code it easy than what I did
import numpy
import matplotlib.pyplot
import pylab
import numpy as np
from pylab import *
data = []
inventory = 0
for j in range(4000):
totalOrder= 0
totalProduction = 0
for i in range (5):
# calculate order
mean = 105
order = np.random.gamma(mean, 20000)
totalOrder = totalOrder+order
# calculate production
production = numpy.random.choice([80, 100, 130, 150], p = [0.2, 0.50 ,0.20, 0.1])
totalProduction = totalProduction + production
# calcculate new inventory
inventory = inventory + production - order
if inventory < 0:
inventory = 0
# calculate fill rate for last 5 orders
fr = float(totalProduction) / float(totalOrder)
if fr > 1:
fr = 1
# append FR to dataset
data.append(fr)
grid(True)
xlabel('Fill Rate')
ylabel('Density')
title('Simulate the system for 20000 week')
matplotlib.pyplot.hist(data, normed = True)
pylab.show()