import pandas as ps
import tushare as ts
code = 'IXIC'
pro = ts.pro_api('ee5c0e991e17949cdafbcf8ec42321ef4bac94e9ca3474e4d62313a3')
df = pro.index_global(ts_code=code)
df.to_csv(code + ".csv", encoding='utf_8_sig')
def date2week(date):
y = int(date[0:4])
m = int(date[4:6])
d = int(date[6:])
if m < 3:
m = m + 12
y = y-1
w = (d + 2*m + int(3*(m+1)/5) + y + int(y%4==0) - int(y%100==0) + int(y%400==0)) % 7
#print(date+ " " + str(w))
return w
def testPLusSub(week1):
plus = 0
sub = 0
weekcount = 0
weeks = 0
start = 0
num = 1000
end = start +num
seriesStart = data.loc[start]
seriesEnd = data.loc[end]
print(str(int(seriesStart[1])) + " " + str(int(seriesStart[0])))
print(str(int(seriesEnd[1])) + " " + str(int(seriesEnd[0])))
for i in range(start, end):
s1 = data.loc[i+1]
pct1 = s1[2]
#if(pct1 > 0):
# print(pct1)
# continue
series = data.loc[i]
date = str(int(series[0]))
pct = series[2]
w = date2week(date)
if w == week1:
weekcount = weekcount + pct
if pct > 0:
plus += 1
else:
sub += 1
return weekcount, plus, sub
def testZuiZhangShanDie():
countPct = 0
count = 1
start = 0
end = 10
m = 1
for i in range(start, end):
s1 = data.loc[end - i]
pct1 = s1[2]
# if(pct1 > 0):
# print(pct1)
# continue
series = data.loc[end - i - 1]
date = str(int(series[0]))
pct = series[2]
w = date2week(date)
if float(pct1) < -0.8:
m = -1
elif float(pct1) > 0.8:
m = 1
print(str(m) +" " + str(pct1) +" " + str(pct))
countPct += m * pct
if pct1 * pct < 0:
count += 1
print(countPct)
print(count)
code = "DJI"
file = 'D:/csv/' + code + '.csv'
df = ps.read_csv(file)
data = df[['trade_date', 'close', 'pct_chg', 'vol']]
weekcount1, plus1, sub1 = testPLusSub(1)
weekcount2, plus2, sub2 = testPLusSub(2)
weekcount5, plus5, sub5 = testPLusSub(5)
weekcount = weekcount1 + weekcount2# + weekcount5
plus = plus1 + plus2 + plus5
sub = sub1 + sub2 + sub5
print(weekcount)
print(plus)
print(sub)