Advertisement
ImDerekD

Testme.py(Row count problem)_01_16

Jan 16th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.76 KB | None | 0 0
  1. #!/usr/bin/bash python
  2. # Insert test
  3.  
  4. ### iSpy.csv has 3 days where market was on a half day, affecting the row #'s having 0 as a remainder when divided by 390
  5. ### Off top of my head, having problems w/ row 28292, 28502. Thanksgiving day, Christmas Eve, and day of Bush memorial
  6. ### Current problem = after Christmas Eve, row count for finding 15:59 is off by 1 minute for each day thereafter
  7. ### Each day following would be recorded as 15:58, then 15:57, then 15:56 thereon
  8. ### Unsure of how to fix problem of using a counter & the 0 remainder of ref_Num (csv row #) % 390 w/ out deleting those days
  9.  
  10.  
  11. import datetime
  12. from datetime import datetime
  13. import time
  14. import csv
  15. import os
  16. import pathlib
  17. from pathlib import Path
  18. from termcolor import colored, cprint
  19. import glob
  20. import hashlib
  21. from hashlib import md5
  22.  
  23.  
  24.  
  25. # ref_Num = int(0)
  26. # minute_Count = int(0)
  27. # # Date
  28. # # military_time
  29. # #
  30. # # Open_Price = float()
  31. # # High_Price = float()
  32. # # Low_Price = Float()
  33. # # Close_Price = Float()
  34. #
  35. # Money_Flow = float()
  36. # TotalVolume = []
  37. # TotalFlow = []
  38. # # M_Price = Float()
  39. # # HLCC = Float()
  40. # #
  41. # # m_Vol
  42. # # m_Vol
  43. # #
  44. # # MMM = Float()
  45. # Liquidity = float()
  46. # # Liq_change = float()
  47. # prev_Change = float(1)
  48. #
  49. # Liq_Tick = int()
  50. # Price_Tick = int()
  51. # Strength = int(0)
  52. #
  53. # prevVol = float(1)
  54. # prevFlow = float(1)
  55. # prevIndexValue = float(1)
  56. # Open_Price = float(1)
  57. #
  58. # # Tick = []
  59. #
  60. #
  61. # ### NEW
  62. DailyStat = {}
  63. Stat = {}
  64. Liquidity = float()
  65. addLiq = float()
  66. addVol = int()
  67. addFlow = float()
  68. SketchIndex = float()
  69. HalfDay = False
  70.  
  71. Strength = int()
  72. lastString = ''
  73. ref_Num = int(0)
  74. count = int()
  75. with open('/Users/King/Desktop/iSpy.csv', 'r') as csv_file:
  76. data = csv.reader(csv_file)
  77. header = next(data)
  78. for row in data:
  79. ref_Num += 1
  80. dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
  81. Time = dTime[-14:]
  82. Open_Price = float(row[1]) # Price Data Dictionary
  83. Close_Price = float(row[2]) # Price Data Dictionary
  84. High_Price = float(row[3]) # Price Data Dictionary
  85. Low_Price = float(row[4]) # Price Data Dictionary
  86. Money_Flow = float(row[6]) # Price Data Dictionary
  87. Vol = row[5] # Price Data Dictionary
  88. f_Vol = float(Vol[:-1]) # Price Data Dictionary
  89. m_Vol = str(Vol[-1:]) # Price Data Dictionary
  90. if m_Vol == "K": # Price Data Dictionary
  91. f_Vol = f_Vol * 1000 # Price Data Dictionary
  92. if m_Vol == "M": # Price Data Dictionary
  93. f_Vol = f_Vol * 1000000
  94. if m_Vol != "K" and m_Vol != "M":
  95. f_Vol = float(row[5]) # Price Data Dictionary
  96. if f_Vol < 1:
  97. M_Price = HLCC
  98. else:
  99. M_Price = round(float(Money_Flow) / f_Vol, 2)
  100. HLCC = float(High_Price + Low_Price + Close_Price + Close_Price)/4 # Price Data Dictionary & RangeReference Dictionary # Price Data Dictionary & RangeReference Dictionary
  101. Diff = round(HLCC - M_Price, 2) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  102. MMM = float(f_Vol * HLCC) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  103. Liq_change = float(Money_Flow - MMM) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  104. Liquidity += Liq_change # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  105. Date = str(Time[:5]) # Important
  106. military_time = str(Time[-8:])
  107. Liq_Tick = int()
  108. Price_Tick = int()
  109. lastString = Date, military_time
  110. if Close_Price > Open_Price and Liq_change > 0:
  111. Price_Tick = 1
  112. Liq_Tick = 1
  113. elif Close_Price >= Open_Price and Liq_change < 0:
  114. Price_Tick = 0
  115. Liq_Tick = -1
  116. elif Close_Price <= Open_Price and Liq_change > 0:
  117. Price_Tick = -1
  118. Liq_Tick = 0
  119. elif Close_Price <= Open_Price and Liq_change < 0:
  120. Price_Tick = -1
  121. Liq_Tick = -1
  122.  
  123. Tick = Liq_Tick + Price_Tick
  124. # percent_Strength = round(Strength / ref_Num, 4)
  125.  
  126. if ref_Num % 390 != 0 and ref_Num < 20671:
  127. count += 1
  128. Strength += Tick
  129. addLiq += abs(Liq_change)
  130. addFlow += Money_Flow
  131. addVol += f_Vol
  132. if abs(Liq_change) >= 50000:
  133. SketchIndex += .5
  134. if abs(Liq_change) >= 100000:
  135. SketchIndex += 1
  136. if abs(Liq_change) >= 300000:
  137. SketchIndex += 2
  138. if abs(Liq_change) >= 500000:
  139. SketchIndex += 3
  140. if abs(Liq_change) >= 700000:
  141. SketchIndex += 5
  142. if abs(Liq_change) >= 900000:
  143. SketchIndex += 8
  144. if ref_Num > 20881:
  145. count += 1
  146. Strength += Tick
  147. addLiq += abs(Liq_change)
  148. addFlow += Money_Flow
  149. addVol += f_Vol
  150. if abs(Liq_change) >= 50000:
  151. SketchIndex += .5
  152. if abs(Liq_change) >= 100000:
  153. SketchIndex += 1
  154. if abs(Liq_change) >= 300000:
  155. SketchIndex += 2
  156. if abs(Liq_change) >= 500000:
  157. SketchIndex += 3
  158. if abs(Liq_change) >= 700000:
  159. SketchIndex += 5
  160. if abs(Liq_change) >= 900000:
  161. SketchIndex += 8
  162.  
  163.  
  164.  
  165. if count == 389:
  166. avg_LiqChange = addLiq / 390
  167. Stat = {'Date':Date,'Time':military_time,'Close:':Close_Price,'TotalVol:':'{:,.2f}'.format(addVol),'TotalFlow:':'{:,.2f}'.format(addFlow),'AvgLiqChange:':'{:,.2f}'.format(avg_LiqChange),'Tick':Strength,'SkIndex:':SketchIndex}
  168. print(Stat)
  169. count = 0
  170. addLiq = addLiq* 0
  171. addFlow = addFlow * 0
  172. addVol = addVol * 0
  173. SketchIndex = SketchIndex * 0
  174. Strength = Strength * 0
  175.  
  176.  
  177.  
  178. if ref_Num == 20881 or ref_Num == 28501:
  179. if count == 209:
  180. Stat = {'Date':Date,'Time':military_time,'Close:':Close_Price,'TotalVol:':'{:,.2f}'.format(addVol),'TotalFlow:':'{:,.2f}'.format(addFlow),'AvgLiqChange:':'{:,.2f}'.format(avg_LiqChange),'Tick':Strength,'SkIndex:':SketchIndex}
  181. print(Stat)
  182. count = 0
  183. addLiq = addLiq* 0
  184. addFlow = addFlow * 0
  185. addVol = addVol * 0
  186. SketchIndex = SketchIndex * 0
  187. Strength = Strength * 0
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216. # Liquidity = float()
  217. # addLiq = float()
  218. # addVol = int()
  219. # addFlow = float()
  220. #
  221. # ref_Num = int(0)
  222. # count = int(0)
  223. # with open('/Users/King/Desktop/iSpy.csv', 'r') as csv_file:
  224. # data = csv.reader(csv_file)
  225. # header = next(data)
  226. # for row in data:
  227. # ref_Num += 1
  228. # Day = 392
  229. # dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
  230. # Time = dTime[-14:]
  231. # Open_Price = float(row[1]) # Price Data Dictionary
  232. # Close_Price = float(row[2]) # Price Data Dictionary
  233. # High_Price = float(row[3]) # Price Data Dictionary
  234. # Low_Price = float(row[4]) # Price Data Dictionary
  235. # Money_Flow = float(row[6]) # Price Data Dictionary
  236. # Vol = row[5] # Price Data Dictionary
  237. # f_Vol = float(Vol[:-1]) # Price Data Dictionary
  238. # m_Vol = str(Vol[-1:]) # Price Data Dictionary
  239. # if m_Vol == "K": # Price Data Dictionary
  240. # f_Vol = f_Vol * 1000 # Price Data Dictionary
  241. # if m_Vol == "M": # Price Data Dictionary
  242. # f_Vol = f_Vol * 1000000
  243. # if m_Vol != "K" and m_Vol != "M":
  244. # f_Vol = float(row[5]) # Price Data Dictionary
  245. # if f_Vol < 1:
  246. # M_Price = HLCC
  247. # else:
  248. # M_Price = round(float(Money_Flow) / f_Vol, 2)
  249. # HLCC = float(High_Price + Low_Price + Close_Price + Close_Price)/4 # Price Data Dictionary & RangeReference Dictionary # Price Data Dictionary & RangeReference Dictionary
  250. # Diff = round(HLCC - M_Price, 2) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  251. # MMM = float(f_Vol * HLCC) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  252. # Liq_change = float(Money_Flow - MMM) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  253. # Liquidity += Liq_change # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  254. # Date = str(Time[:5]) # Important
  255. # military_time = str(Time[-8:])
  256. # if ref_Num % 390 != 0:
  257. # count += 1
  258. # addLiq += abs(Liq_change)
  259. # addFlow += Money_Flow
  260. # addVol += f_Vol
  261. # if count == 390:
  262. # print(addLiq, addFlow, addVol)
  263. # count = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement