-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_overlaid_series.py
74 lines (47 loc) · 1.52 KB
/
plot_overlaid_series.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from csv import reader
from datetime import datetime
import matplotlib.pyplot as plt
from os.path import join
def string_to_datetime_object(string):
# Convert timestamps to seconds precision (Prune 8 trailing digits)
return datetime.fromtimestamp(int(string) / 100000000)
def load_timestamps_and_prices_from_csv_file(
source_file_path,
out_list_of_timestamps,
out_list_of_prices):
lines = []
with open(source_file_path, 'r') as f:
# Create a parsing iterator and skip the CSV header
parsing_iterator = reader(f, delimiter=',')
next(parsing_iterator, None)
for line in parsing_iterator:
out_list_of_timestamps.append(string_to_datetime_object(line[0]))
out_list_of_prices.append(float(line[1]))
if __name__ == '__main__':
### Settings ###
chart_data_folder = 'stocks/bars/1_day/'
chart_data_files = [ 'OXGN.csv', 'RYT.csv', 'VOCS.csv' ]
### Create the plot ###
for file_name in chart_data_files:
### Load the timestamps and opening prices from the current file ###
list_of_timestamps = []
list_of_prices = []
source_file_path = join(chart_data_folder, file_name)
load_timestamps_and_prices_from_csv_file(
source_file_path,
list_of_timestamps,
list_of_prices
)
### Write the data to the plot instance ###
plt.xlabel('Timestamp (Securities Information Processor)')
plt.ylabel('Price (U.S. Dollars)')
plt.plot(
list_of_timestamps,
list_of_prices,
linewidth=1,
markersize=1
)
### Show the plot ###
plt.title('Overlaid Series')
plt.tight_layout()
plt.show()