Skip to content

Commit 87ba43a

Browse files
committed
des
1 parent a2cd357 commit 87ba43a

14 files changed

+10113
-0
lines changed

Code/2000-03-06_1_day_1.csv

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Date,Open,High,Low,Close,Adj Close,Volume,Label
2+
2000-02-07,5.9375,6.0625,5.75,6.0625,6.0625,27400,1
3+
2000-02-08,6.0,6.0625,5.75,6.0,6.0,69700,2
4+
2000-02-09,5.875,6.125,5.875,6.0,6.0,108700,0
5+
2000-02-10,6.0,6.0625,5.875,6.0625,6.0625,91100,1
6+
2000-02-11,5.875,6.0,5.75,6.0,6.0,72300,0
7+
2000-02-14,6.125,6.75,5.875,6.4375,6.4375,100300,1
8+
2000-02-15,6.5625,6.5625,6.125,6.125,6.125,82100,2
9+
2000-02-16,6.3125,6.375,5.625,6.125,6.125,59100,1
10+
2000-02-17,6.125,6.1875,5.9375,6.0,6.0,26800,1
11+
2000-02-18,5.9375,5.9375,5.9375,5.9375,5.9375,6800,1
12+
2000-02-22,6.0,6.0,5.5,5.875,5.875,11300,1
13+
2000-02-23,6.0,6.1875,5.5625,5.75,5.75,18200,0
14+
2000-02-24,5.625,5.875,5.625,5.875,5.875,9500,1
15+
2000-02-25,5.875,5.9375,5.75,5.8125,5.8125,15700,0
16+
2000-02-28,5.75,6.0,5.6875,6.0,6.0,41600,1
17+
2000-02-29,5.75,6.0,5.625,5.75,5.75,64100,0
18+
2000-03-01,6.0,6.125,5.9375,6.0625,6.0625,37200,1
19+
2000-03-02,5.75,6.0,5.625,5.625,5.625,30900,0
20+
2000-03-03,5.625,5.9375,5.5625,5.75,5.75,17200,0
21+
2000-03-06,5.875,6.1875,5.875,6.0,6.0,44200,1

Code/2000-03-06_1_day_1_GAF.png

74.1 KB
Loading

Code/2000-03-06_1_day_2.csv

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Date,Open,High,Low,Close,Adj Close,Volume,Label
2+
2000-02-04/2000-02-07,5.875,6.0625,5.75,6.0625,6.0625,47300,1
3+
2000-02-07/2000-02-08,5.9375,6.0625,5.75,6.0,6.0,97100,2
4+
2000-02-08/2000-02-09,6.0,6.125,5.75,6.0,6.0,178400,0
5+
2000-02-09/2000-02-10,5.875,6.125,5.875,6.0625,6.0625,199800,1
6+
2000-02-10/2000-02-11,6.0,6.0625,5.75,6.0,6.0,163400,0
7+
2000-02-11/2000-02-14,5.875,6.75,5.75,6.4375,6.4375,172600,1
8+
2000-02-14/2000-02-15,6.125,6.75,5.875,6.125,6.125,182400,2
9+
2000-02-15/2000-02-16,6.5625,6.5625,5.625,6.125,6.125,141200,1
10+
2000-02-16/2000-02-17,6.3125,6.375,5.625,6.0,6.0,85900,1
11+
2000-02-17/2000-02-18,6.125,6.1875,5.9375,5.9375,5.9375,33600,1
12+
2000-02-18/2000-02-22,5.9375,6.0,5.5,5.875,5.875,18100,1
13+
2000-02-22/2000-02-23,6.0,6.1875,5.5,5.75,5.75,29500,0
14+
2000-02-23/2000-02-24,6.0,6.1875,5.5625,5.875,5.875,27700,1
15+
2000-02-24/2000-02-25,5.625,5.9375,5.625,5.8125,5.8125,25200,0
16+
2000-02-25/2000-02-28,5.875,6.0,5.6875,6.0,6.0,57300,1
17+
2000-02-28/2000-02-29,5.75,6.0,5.625,5.75,5.75,105700,0
18+
2000-02-29/2000-03-01,5.75,6.125,5.625,6.0625,6.0625,101300,1
19+
2000-03-01/2000-03-02,6.0,6.125,5.625,5.625,5.625,68100,0
20+
2000-03-02/2000-03-03,5.75,6.0,5.5625,5.75,5.75,48100,0
21+
2000-03-03/2000-03-06,5.625,6.1875,5.5625,6.0,6.0,61400,1

Code/2000-03-06_1_day_2_GAF.png

74.1 KB
Loading

Code/2000-03-06_1_day_4.csv

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Date,Open,High,Low,Close,Adj Close,Volume,Label
2+
2000-02-02/2000-02-07,6.375,6.375,5.625,6.0625,6.0625,106600,1
3+
2000-02-03/2000-02-08,6.25,6.25,5.625,6.0,6.0,143300,2
4+
2000-02-04/2000-02-09,5.875,6.125,5.75,6.0,6.0,225700,0
5+
2000-02-07/2000-02-10,5.9375,6.125,5.75,6.0625,6.0625,296900,1
6+
2000-02-08/2000-02-11,6.0,6.125,5.75,6.0,6.0,341800,0
7+
2000-02-09/2000-02-14,5.875,6.75,5.75,6.4375,6.4375,372400,1
8+
2000-02-10/2000-02-15,6.0,6.75,5.75,6.125,6.125,345800,2
9+
2000-02-11/2000-02-16,5.875,6.75,5.625,6.125,6.125,313800,1
10+
2000-02-14/2000-02-17,6.125,6.75,5.625,6.0,6.0,268300,1
11+
2000-02-15/2000-02-18,6.5625,6.5625,5.625,5.9375,5.9375,174800,1
12+
2000-02-16/2000-02-22,6.3125,6.375,5.5,5.875,5.875,104000,1
13+
2000-02-17/2000-02-23,6.125,6.1875,5.5,5.75,5.75,63100,0
14+
2000-02-18/2000-02-24,5.9375,6.1875,5.5,5.875,5.875,45800,1
15+
2000-02-22/2000-02-25,6.0,6.1875,5.5,5.8125,5.8125,54700,0
16+
2000-02-23/2000-02-28,6.0,6.1875,5.5625,6.0,6.0,85000,1
17+
2000-02-24/2000-02-29,5.625,6.0,5.625,5.75,5.75,130900,0
18+
2000-02-25/2000-03-01,5.875,6.125,5.625,6.0625,6.0625,158600,1
19+
2000-02-28/2000-03-02,5.75,6.125,5.625,5.625,5.625,173800,0
20+
2000-02-29/2000-03-03,5.75,6.125,5.5625,5.75,5.75,149400,0
21+
2000-03-01/2000-03-06,6.0,6.1875,5.5625,6.0,6.0,129500,1

Code/2000-03-06_1_day_4_GAF.png

74.1 KB
Loading

Code/2000-03-06_1_day_5.csv

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Date,Open,High,Low,Close,Adj Close,Volume,Label
2+
2000-02-01/2000-02-07,6.375,6.40625,5.625,6.0625,6.0625,111500,1
3+
2000-02-02/2000-02-08,6.375,6.375,5.625,6.0,6.0,176300,2
4+
2000-02-03/2000-02-09,6.25,6.25,5.625,6.0,6.0,252000,0
5+
2000-02-04/2000-02-10,5.875,6.125,5.75,6.0625,6.0625,316800,1
6+
2000-02-07/2000-02-11,5.9375,6.125,5.75,6.0,6.0,369200,0
7+
2000-02-08/2000-02-14,6.0,6.75,5.75,6.4375,6.4375,442100,1
8+
2000-02-09/2000-02-15,5.875,6.75,5.75,6.125,6.125,454500,2
9+
2000-02-10/2000-02-16,6.0,6.75,5.625,6.125,6.125,404900,1
10+
2000-02-11/2000-02-17,5.875,6.75,5.625,6.0,6.0,340600,1
11+
2000-02-14/2000-02-18,6.125,6.75,5.625,5.9375,5.9375,275100,1
12+
2000-02-15/2000-02-22,6.5625,6.5625,5.5,5.875,5.875,186100,1
13+
2000-02-16/2000-02-23,6.3125,6.375,5.5,5.75,5.75,122200,0
14+
2000-02-17/2000-02-24,6.125,6.1875,5.5,5.875,5.875,72600,1
15+
2000-02-18/2000-02-25,5.9375,6.1875,5.5,5.8125,5.8125,61500,0
16+
2000-02-22/2000-02-28,6.0,6.1875,5.5,6.0,6.0,96300,1
17+
2000-02-23/2000-02-29,6.0,6.1875,5.5625,5.75,5.75,149100,0
18+
2000-02-24/2000-03-01,5.625,6.125,5.625,6.0625,6.0625,168100,1
19+
2000-02-25/2000-03-02,5.875,6.125,5.625,5.625,5.625,189500,0
20+
2000-02-28/2000-03-03,5.75,6.125,5.5625,5.75,5.75,191000,0
21+
2000-02-29/2000-03-06,5.75,6.1875,5.5625,6.0,6.0,193600,1

Code/2000-03-06_1_day_5_GAF.png

73.6 KB
Loading

Code/Gadf.py

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import matplotlib.pyplot as plt
2+
from pyts.image import GramianAngularField
3+
import pandas as pd
4+
5+
# Load the CSV file into a pandas dataframe
6+
df = pd.read_csv('2000-03-06_1_day_1.csv', parse_dates=['Date'])
7+
8+
# Get the values from the dataframe
9+
X = df.iloc[:, 1:].values.T
10+
11+
# Compute Gramian angular fields
12+
gasf = GramianAngularField(method='summation')
13+
X_gasf = gasf.fit_transform(X)
14+
15+
gadf = GramianAngularField(method='difference')
16+
X_gadf = gadf.fit_transform(X)
17+
18+
# Plot the Gramian angular fields
19+
fig, ax = plt.subplots(ncols=2, figsize=(12, 6))
20+
ax[0].imshow(X_gasf[0], cmap='rainbow', origin='lower')
21+
ax[0].set_title('Gramian Angular Summation Field')
22+
ax[1].imshow(X_gadf[0], cmap='rainbow', origin='lower')
23+
ax[1].set_title('Gramian Angular Difference Field')
24+
plt.show()
25+
26+
fig.savefig('2000-03-06_1_day_1_GAF.png', dpi=300, bbox_inches='tight')
27+
28+
# Load the CSV file into a pandas dataframe
29+
df = pd.read_csv('2000-03-06_1_day_2.csv', parse_dates=['Date'])
30+
31+
# Get the values from the dataframe
32+
X = df.iloc[:, 1:].values.T
33+
34+
# Compute Gramian angular fields
35+
gasf = GramianAngularField(method='summation')
36+
X_gasf = gasf.fit_transform(X)
37+
38+
gadf = GramianAngularField(method='difference')
39+
X_gadf = gadf.fit_transform(X)
40+
41+
# Plot the Gramian angular fields
42+
fig, ax = plt.subplots(ncols=2, figsize=(12, 6))
43+
ax[0].imshow(X_gasf[0], cmap='rainbow', origin='lower')
44+
ax[0].set_title('Gramian Angular Summation Field')
45+
ax[1].imshow(X_gadf[0], cmap='rainbow', origin='lower')
46+
ax[1].set_title('Gramian Angular Difference Field')
47+
plt.show()
48+
49+
fig.savefig('2000-03-06_1_day_2_GAF.png', dpi=300, bbox_inches='tight')
50+
51+
# Load the CSV file into a pandas dataframe
52+
df = pd.read_csv('2000-03-06_1_day_4.csv', parse_dates=['Date'])
53+
54+
# Get the values from the dataframe
55+
X = df.iloc[:, 1:].values.T
56+
57+
# Compute Gramian angular fields
58+
gasf = GramianAngularField(method='summation')
59+
X_gasf = gasf.fit_transform(X)
60+
61+
gadf = GramianAngularField(method='difference')
62+
X_gadf = gadf.fit_transform(X)
63+
64+
# Plot the Gramian angular fields
65+
fig, ax = plt.subplots(ncols=2, figsize=(12, 6))
66+
ax[0].imshow(X_gasf[0], cmap='rainbow', origin='lower')
67+
ax[0].set_title('Gramian Angular Summation Field')
68+
ax[1].imshow(X_gadf[0], cmap='rainbow', origin='lower')
69+
ax[1].set_title('Gramian Angular Difference Field')
70+
plt.show()
71+
72+
fig.savefig('2000-03-06_1_day_4_GAF.png', dpi=300, bbox_inches='tight')
73+
74+
# Load the CSV file into a pandas dataframe
75+
df = pd.read_csv('2000-03-06_1_day_5.csv', parse_dates=['Date'])
76+
77+
# Get the values from the dataframe
78+
X = df.iloc[:, 1:].values.T
79+
80+
# Compute Gramian angular fields
81+
gasf = GramianAngularField(method='summation')
82+
X_gasf = gasf.fit_transform(X)
83+
84+
gadf = GramianAngularField(method='difference')
85+
X_gadf = gadf.fit_transform(X)
86+
87+
# Plot the Gramian angular fields
88+
fig, ax = plt.subplots(ncols=2, figsize=(12, 6))
89+
ax[0].imshow(X_gasf[0], cmap='rainbow', origin='lower')
90+
ax[0].set_title('Gramian Angular Summation Field')
91+
ax[1].imshow(X_gadf[0], cmap='rainbow', origin='lower')
92+
ax[1].set_title('Gramian Angular Difference Field')
93+
plt.show()
94+
95+
fig.savefig('2000-03-06_1_day_5_GAF.png', dpi=300, bbox_inches='tight')

Code/createCsv_v1.py

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import pandas as pd
2+
from datetime import datetime
3+
4+
# tolgo solo il primo elemento della lista, tolgo count e uso len(lista)
5+
# funzione per prendere la prima riga in base ad un anno dato in input
6+
def takeIndex(dates, dateStart):
7+
i = 0
8+
for date in dates:
9+
dtObj = datetime.strptime(date, '%Y-%m-%d').date()
10+
if dateStart == dtObj:
11+
break
12+
i += 1
13+
14+
return i
15+
16+
# funzione per creare il CSV da un giorno
17+
def createCsv (data, start, finish, name):
18+
csv1g = pd.DataFrame(columns=['Date', 'Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume'])
19+
for i in range(start, finish + 1):
20+
csv1g = csv1g.append(data.iloc[i], ignore_index = True)
21+
csv1g.to_csv(name, index = False)
22+
23+
# funzione per prendere il massimo il minimo e la somma dei volumi
24+
def getHLS (list):
25+
highest = list[0].iloc[2]
26+
lowest = list[0].iloc[3]
27+
sumVolume = list[0].iloc[6]
28+
i = 0
29+
for item in list:
30+
if i != 0:
31+
if highest < item.iloc[2]:
32+
highest = item.iloc[2]
33+
34+
if lowest > item.iloc[3]:
35+
lowest = item.iloc[3]
36+
37+
sumVolume += item.iloc[6]
38+
i += 1
39+
return highest, lowest, sumVolume
40+
41+
# funzione per creare i cvs divisi per giorni
42+
def createCSV_V2 (data, start, finish, name, div, flag):
43+
csv = pd.DataFrame(columns=['Date', 'Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume'])
44+
45+
list = [data.iloc[start]]
46+
for i in range(start + 1, finish + 1):
47+
list.append(data.iloc[i])
48+
if len(list) == div:
49+
highest, lowest, sumVolume = getHLS(list)
50+
row = {'Date': [list[0].iloc[0] + "/" + list[len(list) - 1].iloc[0]], 'Open': [list[0].iloc[1]],
51+
'High': [highest], 'Low': [lowest], 'Close': [list[len(list) - 1].iloc[4]],
52+
'Adj Close': [list[len(list) - 1].iloc[5]], 'Volume': [sumVolume]}
53+
dataFrame = pd.DataFrame(row)
54+
csv = csv.append(dataFrame, ignore_index=True)
55+
list.pop(0)
56+
57+
'''
58+
if flag:
59+
for item in list:
60+
highest, lowest, sumVolume = getHLS(list)
61+
row = {'Date': [list[0].iloc[0] + "/" + list[len(list) - 1].iloc[0]], 'Open': [list[0].iloc[1]],
62+
'High': [highest], 'Low': [lowest], 'Close': [list[len(list) - 1].iloc[4]],
63+
'Adj Close': [list[len(list) - 1].iloc[5]], 'Volume': [sumVolume]}
64+
dataFrame = pd.DataFrame(row)
65+
csv = csv.append(dataFrame, ignore_index=True)
66+
list.pop(0)
67+
68+
'''
69+
if len(list) and flag:
70+
highest, lowest, sumVolume = getHLS(list)
71+
row = {'Date': [list[0].iloc[0] + "/" + list[len(list) - 1].iloc[0]], 'Open': [list[0].iloc[1]],
72+
'High': [highest], 'Low': [lowest], 'Close': [list[len(list) - 1].iloc[4]],
73+
'Adj Close': [list[len(list) - 1].iloc[5]], 'Volume': [sumVolume]}
74+
dataFrame = pd.DataFrame(row)
75+
csv = csv.append(dataFrame, ignore_index=True)
76+
77+
csv.to_csv(name, index=False)
78+
79+
# MAIN
80+
# leggo il cvs
81+
data = pd.read_csv("DXYN.csv")
82+
# estrazione date
83+
dates = data.loc[:, "Date"]
84+
85+
div = int(input("Scegliere il numero di giorni per cui dividere: "))
86+
while div > 0:
87+
# leggo la data di inizio e converto la stringa in data
88+
dateStart = input("Da che data iniziare: ")
89+
start = takeIndex(dates, datetime.strptime(dateStart, '%Y-%m-%d').date())
90+
91+
dateFinish = input("A che data finire: ")
92+
finish = takeIndex(dates, datetime.strptime(dateFinish, '%Y-%m-%d').date())
93+
94+
flag = int(input("Aggiungere le ultime date che possono rimanere alla fine della divisione ? (Si = 1, No = 0): "))
95+
96+
name = input("Scrivere il nome (ricordarsi il .csv): ")
97+
98+
print("Creazione csv...")
99+
if div == 1:
100+
createCsv(data, start, finish, name)
101+
else:
102+
createCSV_V2(data, start, finish, name, div, flag)
103+
104+
print("Creazione conclusa.")
105+
div = int(input("Creare altri file? (scrivere 0 per dire NO, il numero dei giorni per cui vuoi dividere per dire SI): "))

Code/createCsv_v2.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import pandas as pd
2+
from datetime import datetime
3+
4+
5+
def takeIndex(dates, dateStart):
6+
i = 0
7+
for date in dates:
8+
dtObj = datetime.strptime(date, '%Y-%m-%d').date()
9+
if dateStart == dtObj:
10+
break
11+
i += 1
12+
13+
return i
14+
15+
def getLabel(data, i, close):
16+
list = [data.iloc[i + 1]]
17+
closeNextDay = list[0].iloc[4]
18+
19+
if close == closeNextDay : return 2
20+
21+
if close > closeNextDay : return 1
22+
23+
if close < closeNextDay : return 0
24+
25+
def addLabel1g(data: pd.DataFrame, name):
26+
csv1g = pd.DataFrame(columns=['Date', 'Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume', 'Label'])
27+
28+
for i in range(0, data.shape[0]):
29+
list = [data.iloc[i]]
30+
if(i + 1 < data.shape[0]):
31+
row = {'Date': [list[0].iloc[0]], 'Open': [list[0].iloc[1]],
32+
'High': [list[0].iloc[2]], 'Low': [list[0].iloc[3]], 'Close': [list[0].iloc[4]],
33+
'Adj Close': [list[0].iloc[5]], 'Volume': [list[0].iloc[6]], 'Label' : [getLabel(data, i, list[0].iloc[4])]}
34+
35+
else:
36+
row = {'Date': [data.iloc[i].iloc[0]], 'Open': [data.iloc[i].iloc[1]],
37+
'High': [data.iloc[i].iloc[2]], 'Low': [data.iloc[i].iloc[3]], 'Close': [data.iloc[i].iloc[4]],
38+
'Adj Close': [data.iloc[i].iloc[5]], 'Volume': [data.iloc[i].iloc[6]],
39+
'Label': [None]}
40+
41+
dataFrame = pd.DataFrame(row)
42+
csv1g = csv1g.append(dataFrame, ignore_index=True)
43+
44+
csv1g.to_csv(name, index=False)
45+
46+
def getLabelNg(date, close, dates, data1g):
47+
lastDate = date[date.find('/') + 1 : len(date)]
48+
i = takeIndex(dates, datetime.strptime(lastDate, '%Y-%m-%d').date())
49+
50+
list = [data1g.iloc[i + 1]]
51+
closeNextDay = list[0].iloc[4]
52+
53+
if close == closeNextDay: return 2
54+
55+
if close > closeNextDay: return 1
56+
57+
if close < closeNextDay: return 0
58+
59+
def addLabelnG(data: pd.DataFrame, data1g: pd.DataFrame, name, dates):
60+
csv = pd.DataFrame(columns=['Date', 'Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume', 'Label'])
61+
62+
for i in range(0, data.shape[0]):
63+
list = [data.iloc[i]]
64+
65+
if(i + 1 < data.shape[0]):
66+
row = {'Date': [list[0].iloc[0]], 'Open': [list[0].iloc[1]],
67+
'High': [list[0].iloc[2]], 'Low': [list[0].iloc[3]], 'Close': [list[0].iloc[4]],
68+
'Adj Close': [list[0].iloc[5]], 'Volume': [list[0].iloc[6]],
69+
'Label': [getLabelNg(list[0].iloc[0], list[0].iloc[4], dates, data1g)]}
70+
else:
71+
row = {'Date': [data.iloc[i].iloc[0]], 'Open': [data.iloc[i].iloc[1]],
72+
'High': [data.iloc[i].iloc[2]], 'Low': [data.iloc[i].iloc[3]], 'Close': [data.iloc[i].iloc[4]],
73+
'Adj Close': [data.iloc[i].iloc[5]], 'Volume': [data.iloc[i].iloc[6]],
74+
'Label': [None]}
75+
76+
dataFrame = pd.DataFrame(row)
77+
csv = csv.append(dataFrame, ignore_index=True)
78+
79+
csv.to_csv(name, index=False)
80+
81+
data1g = pd.read_csv("div1.csv")
82+
dates = data1g.loc[:, "Date"]
83+
data2g = pd.read_csv("div2.csv")
84+
data4g = pd.read_csv("div4.csv")
85+
data5g = pd.read_csv("div5.csv")
86+
87+
addLabelnG(data4g, data1g, "div4Label.csv", dates)
88+
addLabelnG(data5g, data1g, "div5Label.csv", dates)
89+
#addLabelnG(data2g, data1g, "div2Label.csv", dates)
90+
#addLabel1g(data1g, "div1Label.csv")

0 commit comments

Comments
 (0)