以华中智能股票软件为例:(以Think pad X13 锐龙版笔记本电脑,Windows 10 操作为例)首先切换到要下载数据的股票K线形态,按“F1”进入“日线某某股票历史成交”,点击鼠标右键->数据导出->导出所有数据->在“请选择导出的类型”中选择excel或txt
补充资料:
如何获取所有股票历史数据:
如果要对股市进行分析,首先就要获取所有股票的历史数据,只有通过股票的历史数据,我们才能分析出股市的规律。
(以Think pad X13 锐龙版笔记本电脑,Windows 10 操作为例)
一、工具/原料
1、EXCEL2007或者以上版本,不能使用WPS
2、电脑1g内存1核处理器及以上配置
3、拥有较强逻辑分析能力以及少量智慧及以上的大脑一颗
方法/步骤:
第一步,获取股票代码,复制其中一部分到第一个工作表A4到A127,然后通过程序把每一个代码写入到不同的工作表A2位置,并对该工作表以该股票代码命名。程序如下:
Sub 工作表命名()
For i = 4 To 127
Sheets(i).Range("a2") = "'" & Sheets(1).Range("a" & i)
Next i
For i = 4 To Sheets.Count
Sheets(i).Name = Sheets(i).Range("a2").Value
Next
End Sub
第二步,获取股票历史数据。代码如下:
Private Function GetSource(sURL As String) As String
Dim oXHTTP As Object
Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
oXHTTP.Open "GET", sURL, False
oXHTTP.Send
GetSource = oXHTTP.responsetext
Set oXHTTP = Nothing
End Function
Sub 历史数据()
Dim objXML As Object
Dim txtContent As String
Dim i As Integer
Dim strCode As String
Dim gp As String
Dim kaishihang
Dim arr, arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8, arr9, arr10, arr11
On Error Resume Next
EndRow = Range("a65536").End(xlUp).Row
startRow = 4
If startRow Range(Cells(startRow, 1), Cells(EndRow, 11)).Value = ""
Else
Exit Sub
End If
Set objXML = CreateObject("Microsoft.XMLHTTP")
gp = [A2]
For h = 1 To 4
For m = 1 To 4
kaishihang = [A65535].End(xlUp).Row
nian = Replace(Str(Year(Now) + 1 - h), " ", "")
jidu = Replace(Str(4 + 1 - m), " ", "")
With objXML
.Open "GET", "http://quotes.money.163.com/trade/lsjyj_" + gp + ".html?year=" + nian + "&season=" + jidu + "", False
.Send
If objXML.Status = 200 Then
txtContent = .responsetext
arr = Split(txtContent, "'>
") For i = 1 To UBound(arr) arr1 = Split(arr(i), " |
| Cells(i + kaishihang, 1) = Right(Left(arr1(0), 10), 10)
arr2 = Split(arr1(1), Chr(60))
Cells(i + kaishihang, 2) = Mid(arr2(0), InStr(arr2(0), ">") + 1)
arr3 = Split(arr1(2), Chr(60))
Cells(i + kaishihang, 3) = Mid(arr3(0), InStr(arr3(0), ">") + 1)
arr4 = Split(arr1(3), Chr(60))
Cells(i + kaishihang, 4) = Mid(arr4(0), InStr(arr4(0), ">") + 1)
arr5 = Split(arr1(4), Chr(60))
Cells(i + kaishihang, 5) = Mid(arr5(0), InStr(arr5(0), ">") + 1)
arr6 = Split(arr1(5), Chr(60))
Cells(i + kaishihang, 6) = Mid(arr6(0), InStr(arr6(0), ">") + 1)
arr7 = Split(arr1(6), Chr(60))
Cells(i + kaishihang, 7) = Mid(arr7(0), InStr(arr7(0), ">") + 1)
arr8 = Split(arr1(7), Chr(60))
Cells(i + kaishihang, 8) = Mid(arr8(0), InStr(arr8(0), ">") + 1)
arr9 = Split(arr1(8), Chr(60))
Cells(i + kaishihang, 9) = Mid(arr9(0), InStr(arr9(0), ">") + 1)
arr10 = Split(arr1(9), Chr(60))
Cells(i + kaishihang, 10) = Mid(arr10(0), InStr(arr10(0), ">") + 1)
arr11 = Split(arr1(10), Chr(60))
Cells(i + kaishihang, 11) = Mid(arr11(0), InStr(arr11(0), ">") + 1)
Next i
End If
End With
Next m
Next h
Set objXML = Nothing
End Sub
第三步,获取上证历史数据,并获取所有股票的历史数据。程序如下:
Sub 所有股票历史数据获取()
Application.ScreenUpdating = False
Dim s As String, gp As String, nian As String, jidu As String, s1 As String
Dim arr, arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8, arr9
Dim i, h As Long
Dim kaishihang
Dim LastRow As Long, r As Long
On Error Resume Next
EndRow = Sheet2.Range("a65536").End(xlUp).Row
startRow = 4
If startRow Sheet2.Range(Sheet2.Cells(startRow, 1), Sheet2.Cells(EndRow, 9)).Value = ""
Else
Exit Sub
End If
For h = 1 To 5
For m = 1 To 4
kaishihang = Sheet2.[A65535].End(xlUp).Row
nian = Replace(Str(Year(Now) + 1 - h), " ", "")
jidu = Replace(Str(4 + 1 - m), " ", "")
s1 = "http://quotes.money.163.com/trade/lsjysj_zhishu_000001.html?year=" + nian + "&season=" + jidu + ""
s = GetSource(s1)
arr = Split(s, "'>
") For i = 1 To UBound(arr) arr1 = Split(arr(i), " |
| Sheet2.Cells(i + kaishihang, 1) = Right(Left(arr1(0), 4), 4) & "-" & Right(Left(arr1(0), 6), 2) & "-" & Right(Left(arr1(0), 10), 2)
arr2 = Split(arr1(1), Chr(60))
Sheet2.Cells(i + kaishihang, 2) = Mid(arr2(0), InStr(arr2(0), ">") + 1)
arr3 = Split(arr1(2), Chr(60))
Sheet2.Cells(i + kaishihang, 3) = Mid(arr3(0), InStr(arr3(0), ">") + 1)
arr4 = Split(arr1(3), Chr(60))
Sheet2.Cells(i + kaishihang, 4) = Mid(arr4(0), InStr(arr4(0), ">") + 1)
arr5 = Split(arr1(4), Chr(60))
Sheet2.Cells(i + kaishihang, 5) = Mid(arr5(0), InStr(arr5(0), ">") + 1)
arr6 = Split(arr1(5), Chr(60))
Sheet2.Cells(i + kaishihang, 6) = Mid(arr6(0), InStr(arr6(0), ">") + 1)
arr7 = Split(arr1(6), Chr(60))
Sheet2.Cells(i + kaishihang, 7) = Mid(arr7(0), InStr(arr7(0), ">") + 1)
arr8 = Split(arr1(7), Chr(60))
Sheet2.Cells(i + kaishihang, 8) = Mid(arr8(0), InStr(arr8(0), ">") + 1)
arr9 = Split(arr1(8), Chr(60))
Sheet2.Cells(i + kaishihang, 9) = Mid(arr9(0), InStr(arr9(0), ">") + 1)
Next i
Next m
Next h
Application.ScreenUpdating = True
n = Worksheets.Count
For i = 4 To n
Worksheets(i).Activate
历史数据
Next
End Sub
第四步,保存工作簿,并对该工作簿命名为1,然后复制该工作簿27份,把所有股票代码写入每一个工作簿第一个工作表的A3到A127列。然后根据第一步对工作簿内的工作表命名,并在每一个工作表A2单元格内写入股票代码。
第五步,把这些工作簿存放到炒股文件夹下的数据库文件下。然后在炒股文件夹下新建一个工作簿,命名为“一键更新表格”,写入如下代码:
Sub 所有股票历史数据更新()
Dim wb As Workbook
For i = 1 To 27
Set wb = Workbooks.Open(ThisWorkbook.Path & "\数据库\" & i & "".xlsb"")
Application.Run ""'"" & wb.Path & ""\"" & i & "".xlsb'!所有股票历史数据获取""
wb.Save
wb.Close
Next i
End sub
当启动这一段代码以后,程序会自动一个一个的打开对应的工作簿然后获取里面所有股票的历史数据,存放在对应的工作表当中。
第六步,对相应的程序添加按钮,这样,我们在启动对应程序时,只需要点一下对应的按钮就可以实现了。这样,我们通过多个工作簿就实现了获取所有股票历史数据的方法。而后面,我们只需要通过获取对应股票每一天的历史数据,我们就能够在任意一天很快速的能够拥有所有股票的历史数据了。
注意事项
1、在后续需要对这些数据进行分析,里面会加入很多计算,所以启动所有历史数据更新时,我们应该要关闭自动更新。
2、因为历史数据很大,所以这里只获取四年的数据,想要获取更多数据,可以更改程序里面 “For h = 1 To 5”的那个5即可。
3、历史数据的获取需要较长的时间,要提前做好准备。
4、如果你想要弄清楚用EXCEL建立炒股系统的整套方法,请看后续内容。"