timeseries-julia-python

random julia and python scripts analyzing stock timeseries data

git clone https://9o.is/git/timeseries-julia-python.git

randomwalk.py

(523B)


      1 import numpy as np
      2 import matplotlib.pyplot as plt
      3 
      4 # Probability to move up or down
      5 prob = [0.05, 0.95]
      6 
      7 # statically defining the starting position
      8 start = 2
      9 positions = [start]
     10 
     11 # creating the random points
     12 rr = np.random.random(1000)
     13 downp = rr < prob[0]
     14 upp = rr > prob[1]
     15 
     16 
     17 for idownp, iupp in zip(downp, upp):
     18     down = idownp and positions[-1] > 1
     19     up = iupp and positions[-1] < 4
     20     positions.append(positions[-1] - down + up)
     21 
     22 # plotting down the graph of the random walk in 1D
     23 plt.plot(positions)
     24 plt.show()