factor_values.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from jqdatasdk import *
  2. from jqdatasdk.technical_analysis import *
  3. from sqlalchemy import create_engine
  4. import pandas as pd
  5. import pymysql
  6. import datetime
  7. auth('18616891214', 'Ea?*7f68nD.dafcW34d!')
  8. strattime = datetime.datetime.now()
  9. print(get_query_count())
  10. stocks = list(get_all_securities(['stock']).index)
  11. qihuo = get_price(['IF9999.CCFX', 'IC9999.CCFX','IH9999.CCFX', 'IM9999.CCFX'], start_date='2015-01-01', end_date='2015-12-31', frequency='daily', fields=None, skip_paused=False, fq='pre' ,panel=True)
  12. print(qihuo)
  13. for fre in ['30m', '1d']:
  14. print(fre)
  15. # 连接数据库
  16. db = pymysql.connect(host='localhost',
  17. user='root',
  18. port=3307,
  19. password='r6kEwqWU9!v3',
  20. database='hlfx')
  21. cursor = db.cursor()
  22. cursor.execute("show tables like '%%%s%%' " % fre)
  23. table_list = [tuple[0] for tuple in cursor.fetchall()]
  24. print('取得 table_list %s' % fre)
  25. time = datetime.datetime(2010, 1, 4)
  26. print(time)
  27. for stock in table_list:
  28. print(stock)
  29. sql = ("select date_format(date, '%%Y-%%m-%%d') from `%s` where HL='L'" % stock)
  30. cheak_time = cursor.execute(sql)
  31. print(cheak_time)
  32. time_list = [''.join(time) for time in cursor.fetchall()]
  33. print(time_list)
  34. break
  35. #stock = normalize_code(stock[3:9])
  36. # 定义股票池列表
  37. security_list1 = '000001.XSHE'
  38. # security_list2 = ['000001.XSHE','000002.XSHE','601211.XSHG','603177.XSHG']
  39. # # 计算并输出 security_list1 的 MACD 值
  40. macd_dif, macd_dea, macd_macd = MACD(security_list1, check_date=time_list[1], SHORT = 12, LONG = 26, MID = 9)
  41. print(macd_dif[security_list1])
  42. print(macd_dea[security_list1])
  43. print(macd_macd[security_list1])
  44. # 输出 security_list2 的 MACD 值
  45. macd_dif, macd_dea, macd_macd = MACD(security_list2,check_date=datetime.datetime.today(), SHORT = 12, LONG = 26, MID = 9)
  46. for stock in security_list2:
  47. print(macd_dif[stock])
  48. print(macd_dea[stock])
  49. print(macd_macd[stock])
  50. df = get_bars(stocks, count=10, unit='30m',
  51. fields=['date','open','close','high','low','volume','money'],include_now=False,end_dt=datetime.date.today())
  52. print(df)
  53. endtime = datetime.datetime.now()
  54. print('单次时长为:', (endtime - strattime).seconds)
  55. #get_ticks("000001.XSHE", "2022-01-01", datetime.datetime.today())