SHARE
TWEET

Python code to generate random "technical analysis" charts

a guest Apr 16th, 2013 391 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from math import *
  2. import random
  3. import numpy as np
  4. import pylab as pl
  5. import sys
  6.  
  7. tries = int(sys.argv[1])
  8. increment = 1.0
  9.  
  10. values = np.empty(tries)
  11. values[0] = 0.0
  12.  
  13. for i in range(1,tries):
  14.     flip = random.randint(1, 2)
  15.     if flip == 1:
  16.         values[i] = values[i-1] + increment
  17.     else:
  18.         values[i] = values[i-1] - increment
  19.  
  20. #Group each 10 bases into a single day:
  21. day_int = 50
  22. ndays = tries / day_int
  23. day_mins = np.empty(ndays)
  24. day_maxs = np.empty(ndays)
  25.  
  26. day_open = values[::day_int]
  27. day_close = values[day_int-1::day_int]
  28.  
  29. for n in range(0,ndays,1):
  30.     tmp = np.array(values[day_int*n:day_int*n+day_int])
  31.     day_mins[n] = np.min(tmp)
  32.     day_maxs[n] = np.max(tmp)
  33.  
  34. deltas = day_maxs - day_mins
  35.  
  36. ax = pl.axes()
  37. rects1 = ax.bar(np.arange(ndays), deltas, 0, color = 'r', bottom = day_mins)
  38.  
  39. for opening, closing, bar in zip(day_open, day_close, rects1):
  40.     x, w = bar.get_x(), 0.2
  41.  
  42.     args = {}
  43.     ax.plot((x - w, x), (opening, opening), **args)
  44.     ax.plot((x, x + w), (closing, closing), **args)
  45.  
  46.  
  47. pl.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top