jeudi 30 juin 2022

How to run one type of simulation for multiple times under one loop to get a series of different results?

Py newbie here (really though, I literally started yesterday) Im basically trying to do a coin flip simulation, and its based on a BIASED distribution! Following are the inputs needed for the sim

#prob_up (success) = 0.472835862
#prob_down(fail) =  0.527164138
#up_scale(rate of increase) =   0.091889211
#down_scale(rate of decrease) = -0.061319729
#value = 1

Below is what I did

```for i in range(30):
  toss_outcome = np.random.random()
  if toss_outcome <= prob_up:
    value += value*(up_scale)

  if toss_outcome > 1-prob_up:
    value += value*(down_scale)
print(value)```

So this one works for me, but I would like to ask you how I could repeat this simulation for 100 times under one loop so that I can get something like 1.1, 1.09, 2.1, 0.98, 1.7, 0.89...

This is what I tried

#value =1
#count = 0


```for i in range(10):
  count = 0
  sims = []
  for x in range(20):
    toss_outcome = np.random.random()

    if toss_outcome <= prob_up:
      value+= value*(up_scale)
    if toss_outcome > 1-prob_down:
      value+= value*(down_scale)

    if count == 20:
      break
    sims.append(value)
  print(sims) ```

This is what I got

1.0918892105282665, 1.192222048068041, 1.3017743908394064, 1.2219499374001699, 1.1470202978485873, 1.0766853235214044, 1.1756210878871576, 1.1035323208530166, ...1.5467124250543491, 1.4518684376272906, 1.362840257848346, 1.4880705732181698 #Series 1

1.6248082034015325, 1.7741105464719504, 1.9371321639771295, 1.8183477437909779, 1.7068471521124233, 1.602183746548087, 1.5039382726953088, 1.4117171847179661, 1.541438762310887... #Series 2

So what happened here is that the new series simply continued from the previous one, instead of starting a new series of simulation from value = 1...

Id sincerely appreciate your help! Have a wonderful day.




Aucun commentaire:

Enregistrer un commentaire