Advertisement
Guest User

stocks

a guest
Mar 27th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. # Stock Market Data
  2. from urllib import request
  3. import turtle
  4. turtle.setup(550,360)
  5. turtle.screensize(550,360)
  6. turtle.setworldcoordinates(-40,-25,510,335)
  7. turtle.hideturtle()
  8. def turtlegraph(x,y, x1, x2, y1, y2, title):
  9. turtle.setpos(0,0)
  10. turtle.clear()
  11. turtle.tracer(0)
  12. turtle.seth(0)
  13. turtle.pendown()
  14. turtle.seth(0)
  15. turtle.fd(500)
  16. turtle.bk(500)
  17. turtle.seth(90)
  18. turtle.fd(300)
  19. turtle.bk(300)
  20. maxnum = max(y)
  21. maxin = max(x)
  22. minnum = min(y)
  23. minin = min(x)
  24. turtle.penup()
  25. turtle.setpos(-10,290)
  26. turtle.write(y2, False, align="right")
  27. turtle.setpos(-10,-10)
  28. turtle.write(y1, False, align="right")
  29. turtle.setpos(500,-20)
  30. turtle.write(x2, False, align="right")
  31. turtle.setpos(0,-20)
  32. turtle.write(x1, False, align="left")
  33. turtle.setpos(0,320)
  34. turtle.write(title, False, align="left")
  35. turtle.update()
  36. # Now sort points
  37. count = 0
  38. points = []
  39. for valx in x:
  40. points.append([valx,y[count]])
  41. count += 1
  42. points.sort()
  43. # Now add points
  44. turtle.setpos(0,0)
  45. for point in points:
  46. newx = (point[0]-minin)*500/(maxin-minin)
  47. newy = (point[1]-minnum)*300/(maxnum-minnum)
  48. turtle.setpos(newx,newy)
  49. turtle.pendown()
  50. turtle.update()
  51. def dosymbol(s):
  52. s = s.upper()
  53. a = str(int(input("Start Month: "))-1)
  54. b = str(int(input("Start Day: ")))
  55. c = str(int(input("Start Year: ")))
  56. d = str(int(input("End Month: "))-1)
  57. e = str(int(input("End Day: ")))
  58. f = str(int(input("End Year: ")))
  59. info = request.urlopen("http://ichart.finance.yahoo.com/table.csv?s="+s+"&a="+a+"&b="+b+"&c="+c+"&d="+d+"&e="+e+"&f="+f)
  60. info.readline()
  61. x = []
  62. y = []
  63. count = 1
  64. monthvals = [0,31,59,90,120,151,181,212,243,273,304,334]
  65. for line in info:
  66. line = line.decode()
  67. vals = line.split(',')
  68. dats = vals[0].split('-')
  69. date = float(dats[0])*365.25+monthvals[int(dats[1])-1]+float(dats[2])
  70. close = vals[4]
  71. x.append(float(date))
  72. y.append(float(close))
  73. if(count==1):
  74. x2=vals[0]
  75. count += 1
  76. x1 = vals[0]
  77. y2 = max(y)
  78. y1 = min(y)
  79. turtlegraph(x,y,x1,x2,y1,y2,s)
  80. ticker = input("Ticker Symbol: ")
  81. while(ticker!=''):
  82. dosymbol(ticker)
  83. ticker = input("Ticker Symbol: ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement