-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQ3_Show_Wave_Current.py
More file actions
83 lines (70 loc) · 3.13 KB
/
Copy pathQ3_Show_Wave_Current.py
File metadata and controls
83 lines (70 loc) · 3.13 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
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
75
76
77
78
79
80
81
82
83
# -*- coding:utf8 -*-
import numpy as np
import time
import talib as ta
import datetime
import HuobiServices as hb
import matplotlib.pyplot as plt
import math
import copy
import tushare as ts
import pymysql
def Signal(coin_symbol,end_dt):
cons = ts.get_apis()
temp_day = ts.tick(code=coin_symbol, conn=cons, date=end_dt)
print(temp_day)
amount = []
vol = []
close = []
for i in range(len(temp_day)):
temp_list = temp_day.ix[i]
amount.append(float(temp_list[1])*float(temp_list[2]))
vol.append(float(temp_list[2]))
close.append(float(temp_list[1]))
amount = np.array(amount)
vol = np.array(vol)
close = np.array(close)
price_avg_long = []
price_avg_short = []
price_close = []
delt_list = []
for i in range(1,len(amount)):
price_avg_long.append(float(amount[:i+1].mean()/vol[:i+1].mean()))
price_avg_short.append(float(amount[i]/vol[i]))
price_close.append(close[i])
delt_list.append(float(amount[:i+1].mean()/vol[:i+1].mean()) / float(amount[i-1:i].mean()/vol[i-1:i].mean()))
return price_avg_long,price_avg_short,price_close,delt_list
if __name__ == '__main__':
stock_list = ['002008']
para_list = [(2.5, 2.5), (1.5, 4.5)]
#para_list = [(4.5, 4), (3.5, 2)]
para_min = '15min'
show_len = 200
db = pymysql.connect(host='127.0.0.1', user='root', passwd='admin', db='stock', charset='utf8')
cursor = db.cursor()
end_dt = datetime.datetime.now().strftime('%Y-%m-%d')
# date_seq_len = 100
# sql = "select calendarDate from stock_tradecalall where exchangeCD = 'XSHE' and isOpen = 1 and calendarDate < '%s' order by calendarDate desc limit %s"%(end_dt,date_seq_len)
# cursor.execute(sql)
# done_set = cursor.fetchall()
# date_seq = [x[0] for x in done_set]
# date_seq = date_seq[::-1]
fig = plt.figure(figsize=(20, 12))
for i in range(len(stock_list)):
#signal,resu,color,up_limit,low_limit = Signal(str(coin_list[i])+'usdt',para_min,para_list[i][0],para_list[i][1])
price_avg_long,price_avg_short,close,delt_list = Signal(str(stock_list[i]),end_dt)
print('Stock : ' + str(stock_list[i])+' AVG_LONG : ' + str(round(price_avg_long[-1]*100)/100) + ' AVG_SHORT : ' + str(round(price_avg_short[-1]*100)/100) + ' CLOSE : ' + str(round(close[-1]*100)/100))
a = 221+ i
ax = fig.add_subplot(a)
#plt.bar(range(len(resu)), resu)
plt.plot(range(len(price_avg_long)),price_avg_long,color='blue')
plt.plot(range(len(close)),close,color='red')
plt.plot(range(len(price_avg_short)),price_avg_short,color='green')
# resu_bar = []
# for j in range(len(price_avg_long)):
# resu_bar.append((price_avg_short[j]-price_avg_long[j])*delt_list[j])
ax2 = fig.add_subplot(a+2)
plt.bar(range(len(price_avg_long)), np.array(price_avg_short)-np.array(price_avg_long))
#plt.bar(range(len(price_avg_long)), np.array(price_avg_short) - np.array(close))
#plt.bar(range(len(price_avg_long)), resu_bar)
plt.show()