-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplot_sharpe.py
More file actions
45 lines (36 loc) · 1.44 KB
/
plot_sharpe.py
File metadata and controls
45 lines (36 loc) · 1.44 KB
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# plot_sharpe.py
import matplotlib.pyplot as plt
import numpy as np
def create_data_matrix(csv_ref, col_index):
data = np.zeros((3, 3))
for i in range(0, 3):
for j in range(0, 3):
data[i][j] = float(csv_ref[i*3+j][col_index])
return data
if __name__ == "__main__":
# Open the CSV file and obtain only the lines
# with a lookback value of 100
csv_file = open("/home/adrian/Documents/AlgoTradingSystem/Data/opt.csv", "r").readlines()
csv_ref = [c.strip().split(",") for c in csv_file if c[:3] == "100"]
data = create_data_matrix(csv_ref, 5)
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap=plt.cm.Blues)
row_labels = [0.5, 1.0, 1.5]
column_labels = [2.0, 3.0, 4.0]
for y in range(data.shape[0]):
for x in range(data.shape[1]):
plt.text(x + 0.5, y + 0.5, '%.2f' % data[y, x],
horizontalalignment='center',
verticalalignment='center',
)
plt.colorbar(heatmap)
ax.set_xticks(np.arange(data.shape[0])+0.5, minor=False)
ax.set_yticks(np.arange(data.shape[1])+0.5, minor=False)
ax.set_xticklabels(row_labels, minor=False)
ax.set_yticklabels(column_labels, minor=False)
plt.suptitle('Sharpe Ratio Heatmap', fontsize=18)
plt.xlabel('Z-Score Exit Threshold', fontsize=14)
plt.ylabel('Z-Score Entry Threshold', fontsize=14)
plt.show()