2015-10-20 14:50:56 +00:00
|
|
|
# encoding: UTF-8
|
|
|
|
|
|
|
|
import MySQLdb
|
|
|
|
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
try:
|
|
|
|
#连接数据库
|
|
|
|
conn = MySQLdb.connect(host='vnpy.cloudapp.net', user='stockcn', passwd='7uhb*IJN', db='BackTest', port=3306)
|
|
|
|
|
|
|
|
#获取指针
|
|
|
|
cur = conn.cursor(MySQLdb.cursors.DictCursor)
|
|
|
|
|
|
|
|
symbol = 'a'
|
|
|
|
|
2015-10-22 02:40:59 +00:00
|
|
|
backtestingId = '20151021-170626'
|
2015-10-20 14:50:56 +00:00
|
|
|
|
2015-10-22 02:40:59 +00:00
|
|
|
#执行脚本,返回记录数
|
|
|
|
count = cur.execute('select open,high,low, close,datetime from TB_Bar where Id=\'{0}\''.format(backtestingId))
|
|
|
|
print 'there has %s rows bar record' % count
|
2015-10-20 14:50:56 +00:00
|
|
|
|
|
|
|
results = cur.fetchall()
|
|
|
|
|
2015-10-22 02:40:59 +00:00
|
|
|
t1 = []
|
2015-10-20 14:50:56 +00:00
|
|
|
o = []
|
|
|
|
i = 0
|
|
|
|
|
|
|
|
for r in results:
|
|
|
|
i = i+1
|
2015-10-22 02:40:59 +00:00
|
|
|
t1.append(i)
|
2015-10-20 14:50:56 +00:00
|
|
|
# t.append(r['datetime'])
|
|
|
|
o.append(r['open'])
|
|
|
|
|
2015-10-22 02:40:59 +00:00
|
|
|
count = cur.execute('select fastEMA,slowEMA,datetime from TB_Ema where Id=\'{0}\''.format(backtestingId))
|
|
|
|
print 'there has %s rows ema record' % count
|
|
|
|
|
|
|
|
results = cur.fetchall()
|
|
|
|
|
|
|
|
fastEma = []
|
|
|
|
slowEma = []
|
|
|
|
t2 = []
|
|
|
|
i = 0
|
|
|
|
|
|
|
|
for r in results:
|
|
|
|
i = i+1
|
|
|
|
t2.append(i)
|
|
|
|
|
|
|
|
fastEma.append(r['fastEMA'])
|
|
|
|
slowEma.append(r['slowEMA'])
|
|
|
|
|
2015-10-20 14:50:56 +00:00
|
|
|
|
|
|
|
#关闭指针,关闭连接
|
|
|
|
cur.close()
|
|
|
|
conn.close()
|
|
|
|
|
2015-10-22 02:40:59 +00:00
|
|
|
plt.plot(t1,o,label='data')
|
|
|
|
plt.plot(t2,fastEma,label='fastEma')
|
|
|
|
plt.plot(t2,slowEma,label='slowEma')
|
2015-10-20 14:50:56 +00:00
|
|
|
plt.xlabel('Time')
|
|
|
|
plt.ylabel('price')
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
except MySQLdb.Error, e:
|
|
|
|
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
|