-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbacktester.py
57 lines (48 loc) · 1.82 KB
/
backtester.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import json
import time
import calendar
import matplotlib.pyplot as plt
import collections
TslaAskPrice = []
TslaVolume=[]
TslaFiftyDay=[]
TslaTwoHundredDay=[]
VTIAskPrice = []
VTIVolume=[]
VTIFiftyDay=[]
VTITwoHundredDay=[]
VIXAskPrice = []
VIXVolume=[]
VIXFiftyDay=[]
VIXTwoHundredDay=[]
stamps = []
with open("filed.json","r") as filed:
for i in enumerate(filed):
try:
data = json.loads(i[1])
except ValueError:
pass
timeStamp = data["query"]["created"]
timeStamp = calendar.timegm(time.strptime(timeStamp,"%Y-%m-%dT%H:%M:%SZ"))
stamps.append(timeStamp)
TslaAskPrice.append(float(data["query"]["results"]["quote"][0]["Ask"]))
TslaVolume.append(float(data["query"]["results"]["quote"][0]["Volume"]))
TslaFiftyDay.append(float(data["query"]["results"]["quote"][0]["FiftydayMovingAverage"]))
VTITwoHundredDay.append(float(data["query"]["results"]["quote"][0]["TwoHundreddayMovingAverage"]))
# VTIAskPrice.append(float(data["query"]["results"]["quote"][1]["Ask"]))
# VTIVolume.append(float(data["query"]["results"]["quote"][1]["Volume"]))
# VTIFiftyDay.append(float(data["query"]["results"]["quote"][1]["FiftydayMovingAverage"]))
# VTIAskPrice.append(float(data["query"]["results"]["quote"][1]["TwoHundreddayMovingAverage"]))
#
# VIXAskPrice.append(float(data["query"]["results"]["quote"][2]["Ask"]))
# VIXVolume.append(float(data["query"]["results"]["quote"][2]["Volume"]))
# VIXFiftyDay.append(float(data["query"]["results"]["quote"][2]["FiftydayMovingAverage"]))
# VIXAskPrice.append(float(data["query"]["results"]["quote"][2]["TwoHundreddayMovingAverage"]))
plt.plot(stamps,TslaAskPrice)
plt.show()
plt.plot(stamps,TslaVolume)
plt.show()
plt.plot(stamps,TslaFiftyDay)
plt.show()
plt.plot(stamps,TwoHundredDay)
plt.show()