是从免费软件提取,如:通达信、大智慧、飞狐等软件中提取。
自己写程序的话,一种方法是从已提供的信息源,例如webservice获取数据。还有种办法就是去连接提供即时信息的网页硬解析。代码举例如下:Created on Thu Jul 23 09:17:27 2015@author: jet"""DAY_PRICE_COLS = ["date", "open", "high", "close", "low", "volume", "chg", "%chg", "ma5", "ma10", "ma20", "vma5", "vma10", "vma20", "turnover"]DAY_PRICE_URL = "%sapi.finance.%s/%s/?code=%s&type=last"INDEX_KEY = ["SH", "SZ", "HS300", "SZ50", "GEB", "SMEB"]INDEX_LIST = {"SH": "sh000001", "SZ": "sz399001", "HS300": "sz399300","SZ50": "sh000016", "GEB": "sz399006", "SMEB": "sz399005"}INDEX_DAY_PRICE_COLS= ["date", "open", "high", "close", "low", "volume","chg", "%chg", "ma5", "ma10", "ma20","vma5", "vma10", "vma20"] K_TYPE_KEY = ["D", "W", "M"]K_TYPE_MIN_KEY = ["5", "15", "30", "60"]K_TYPE = {"D": "akdaily", "W": "akweekly", "M": "akmonthly"}MIN_PRICE_URL = "%sapi.finance.%s/akmin?scode=%s&type=%s" PAGE_TYPE = {"http": "http://", "ftp": "ftp://"}PAGE_DOMAIN = {"sina": "sina.com.cn", "ifeng": "ifeng.com"}URL_ERROR_MSG = "获取失败,请检查网络状态,或者API端口URL已经不匹配!"get_hist_data.py# -*- coding: utf-8 -*-"""Created on Thu Jul 23 09:15:40 2015@author: jet"""import const as ctimport pandas as pdimport jsonfrom urllib2 import urlopen,Requestdef get_hist_data:"""功能:获取个股历史交易数据--------输入:--------code:string股票代码 比如:601989start:string开始日期 格式:YYYY-MM-DD 为空时取到API所提供的最早日期数据end:string结束日期 格式:YYYY-MM-DD 为空时取到最近一个交易日数据ktype:string数据类型 D=日K线,W=周K线,M=月K线,5=5分钟,15=15分钟30=30分钟,60=60分钟 输出:--------DataFramedate 日期open 开盘价high 最高价close 收盘价low 最低价chg 涨跌额 p_chg 涨跌幅ma5 5日均价ma10 10日均价ma20 20日均价vma5 5日均量vma10 10日均量vma20 20日均量turnover换手率""" code = code_to_APIcode)ktype = ktype.upperurl = "" url = get_url printjs = json.loads)cols = []if len == 14:cols = ct.INDEX_DAY_PRICE_COLSelse:cols = ct.DAY_PRICE_COLSdf = pd.DataFrameif ktype in ct.K_TYPE_KEY:df = df.applymap)for col in cols[1:]:df[col]=df[col].astypeif start is not None:df = df [df.date >= start]if end is not None:df = df[df.date <= end]df = df.set_indexreturn df def code_to_APIcode:"""功能:验证输入的股票代码是否正确,若正确则返回API对应使用的股票代码"""printif code in ct.INDEX_KEY:return ct.INDEX_LIST[code]else:if len != 6:raise IOErrorelse:return "sh%s"%code if code[:1] in ["5", "6"] else "sz%s"%codedef get_url:"""功能:验证输入的K线类型是否正确,若正确则返回url""" if ktype in ct.K_TYPE_KEY:url = ct.DAY_PRICE_URL % return urlelif ktype in ct.K_TYPE_MIN_KEY:url = ct.MIN_PRICE_URL % return urlelse:raise IOErrordef ping_API:"""功能:向API发送数据请求,若链接正常返回数据"""text = ""try:req = Requesttext = urlopen.read if len < 15:raise IOError except Exception as e:printelse:return text#测试入口
print)
“ 金 融 点 评 网 ” 有 大 量 关 于 此 类 的 问 题 解 答 , 您 可 以 去 查 看 !