ImDerekD

Total % Return + Range Accuracy

Jan 21st, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. #!/usr/bin/bash/python
  2.  
  3. import csv
  4. import datetime
  5. from datetime import datetime
  6. from colorama import Back, Fore, Style
  7. import sys
  8. from termcolor import colored, cprint
  9. from colorama import init
  10. import numbers
  11. import time
  12. import itertools
  13. from itertools import zip_longest
  14. from time import sleep
  15. import pathlib
  16. import os
  17. import os.path
  18. from pathlib import Path
  19. import glob
  20. from progress.bar import Bar
  21. import hashlib
  22.  
  23.  
  24. ref_Num = int(0)
  25. Liquidity = float()
  26.  
  27. Balance = 1000
  28. prevPrice = float(1)
  29. Long = bool
  30. Short = bool
  31. LN = float()
  32. NewBalance = float(1)
  33. range_ref_Str = str()
  34.  
  35. Highs_Found = int(0)
  36. Lows_Found = int(0)
  37. Highs_Filled = int(0)
  38. Lows_Filled = int(0)
  39. LowAccuracy = float()
  40. HighAccuracy = float()
  41. Start = bool
  42. Stop = bool
  43. tHigh = bool
  44. tLow = bool
  45.  
  46. Filled = bool
  47. indent = str(' | ')
  48.  
  49. prevPrice = float(1)
  50. prevFlow = float(1)
  51. prevVol = int(1)
  52.  
  53. with open('/Users/King/iFiles/SPY1.csv', 'r') as csv_file:
  54. reader = csv.reader(csv_file)
  55. header = next(reader)
  56. for row in reader:
  57. ref_Num += 1 # Starting at 0
  58. dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
  59. Time = dTime[-14:]
  60. Open_Price = float(row[1]) # Price Data Dictionary
  61. Close_Price = float(row[2]) # Price Data Dictionary
  62. High_Price = float(row[3]) # Price Data Dictionary
  63. Low_Price = float(row[4]) # Price Data Dictionary
  64. Money_Flow = float(row[6]) # Price Data Dictionary
  65. Vol = row[5] # Price Data Dictionary
  66. f_Vol = float(Vol[:-1]) # Price Data Dictionary
  67. m_Vol = str(Vol[-1:]) # Price Data Dictionary
  68. if m_Vol == "K": # Price Data Dictionary
  69. f_Vol = f_Vol * 1000 # Price Data Dictionary
  70. if m_Vol == "M": # Price Data Dictionary
  71. f_Vol = f_Vol * 1000000
  72. if m_Vol != "K" and m_Vol != "M":
  73. f_Vol = float(row[5]) # Price Data Dictionary
  74. if f_Vol < 1:
  75. M_Price = HLCC
  76. else:
  77. M_Price = round(float(Money_Flow) / f_Vol, 2)
  78. HLCC = float(High_Price + Low_Price + Close_Price + Close_Price)/4 # Price Data Dictionary & RangeReference Dictionary # Price Data Dictionary & RangeReference Dictionary
  79. Diff = round(HLCC - M_Price, 2) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  80. MMM = float(f_Vol * HLCC) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  81. Liq_change = float(Money_Flow - MMM) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  82. Liquidity += Liq_change # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  83. Date = str(Time[:5]) # Important
  84. military_time = str(Time[-8:])
  85. criteria = abs(HLCC*.003)
  86. Profit = 100*round(Close_Price - Open_Price, 2) / Open_Price
  87.  
  88. if Money_Flow > 0:
  89. MIV_Index = round(100 * (f_Vol / prevVol) - 100 * ((Money_Flow * HLCC) / (prevFlow * prevPrice)), 3)
  90. prevPrice = Close_Price
  91. prevFlow = Money_Flow
  92. prevVol = f_Vol
  93.  
  94.  
  95. if abs(M_Price - HLCC) >= criteria:
  96. Range_Clause = True
  97. diff = M_Price - HLCC
  98. r_Price = HLCC + diff
  99. t_Price = r_Price + diff
  100. else:
  101. Range_Clause = False
  102. range_ref_Str = ('')
  103. if Range_Clause == True:
  104. Low_Range = round(HLCC - abs(float(M_Price - HLCC)), 2)
  105. High_Range = round(HLCC + abs(float(M_Price - HLCC)), 2)
  106. Low_Target = round(Low_Range - abs(float(M_Price - HLCC)), 2)
  107. High_Target = round(High_Range + abs(float(M_Price - HLCC)), 2)
  108. if r_Price > HLCC and Range_Clause == True:
  109. if MIV_Index < 0:
  110. tHigh = True
  111. tLow = False
  112. Filled = False
  113. indent = ' '
  114. HighrefStr = Fore.CYAN+"HIGH TARGET"
  115. '''print(indent,HighrefStr)
  116. time.sleep(2)'''
  117. Highs_Found += 1
  118. if r_Price < HLCC and Range_Clause == True:
  119. tHigh = False
  120. tLow = True
  121. Filled = False
  122. Lows_Found += 1
  123. indent = ' '
  124. LowrefStr = Fore.RED+"LOW TARGET"
  125. '''print(indent,LowrefStr)
  126. time.sleep(2)'''
  127.  
  128.  
  129. if tHigh == True and Range_Clause == False:
  130. LN += Profit
  131. '''print(' '+Fore.CYAN,LN,'%'+Style.RESET_ALL)'''
  132. if Filled == False:
  133. if High_Price >= r_Price:
  134. Filled = True
  135. Highs_Filled += 1
  136. '''time.sleep(1)
  137. print(Fore.CYAN+'HIGH RANGE FILLED'+Style.RESET_ALL)'''
  138. else:
  139. Filled = False
  140.  
  141. if tLow == True and Range_Clause == False:
  142. LN += Profit*-1
  143. '''print(' '+Fore.RED,LN,'%'+Style.RESET_ALL)'''
  144. if Filled == False:
  145. if Low_Price <= r_Price:
  146. Filled = True
  147. Lows_Filled += 1
  148. '''time.sleep(1)
  149. print(Fore.YELLOW+'LOW RANGE FILLED'+Style.RESET_ALL)'''
  150. else:
  151. Filled = False
  152.  
  153. '''time.sleep(.001)
  154. print(Date, Close_Price)'''
  155.  
  156. if Lows_Found > 0 or Highs_Found > 0:
  157. if Lows_Filled > 0 or Highs_Filled > 0:
  158. LowAccuracy = 100*round(Lows_Filled / Lows_Found, 2)
  159. HighAccuracy = 100*round(Highs_Filled / Highs_Found, 2)
  160.  
  161. print('Lows Found: ',Lows_Found,indent+'Lows Filled: ',Lows_Filled,indent+'Low Accuracy',LowAccuracy,'%')
  162. print('Highs Found: ',Highs_Found,indent+'Highs Filled: ',Highs_Filled,indent+'High Accuracy: ',HighAccuracy,'%')
  163. TotalReturn = Profit*100
  164. print('Total Return: ',TotalReturn,'%')
Advertisement
Add Comment
Please, Sign In to add comment