我使用国家证券交易所(印度)EOD数据进行个人投资 决定。我通过软件下载每日结束日报价文件 Utility NSE EOD Data Downloader v3.0。下载的文件是csv格式文本 文件并包含日期作为文本字符串。该文件的长度可变 取决于特定日期的有效报价。我处理下载的文件 通过excel宏启用文件,可以将日期文本字符串转换为 日期格式并将其转换为适合的格式以在Access Data Base中处理 投资决策基于移动平均线,高低最大值和 最小值平均值等输入Amibroker交易程序。方法 以下概述如下。
I was facing some difficulty in up-loading the files . Hence providing a drop box link to the following files samples in "EOD_Data,zip"
Sample EOD_Data.txt "EQ_03AUG2015.txt"
Sample of EOD_Formatting.xlsm
Sample file dly_nsedly_conversion.xlsx
Sample of EOD_Converted.xlsx
[EOD_Data,zip]
<https://www.dropbox.com/sh/256mvvcnj6fhu20/AAD7nZpTHBuHfCpMNznr93PDa?dl=0>
1。)Excel启用宏文件&#34; EOD_Formatting&#39;打开,包含链接到宏open_text_file
的命令按钮a)打开一个输入框,输入文件名,如&#34; EQ_03AUG2015.txt&#34;每天都会有所不同。用户可以根据其目录修改路径以存储此类文件。打开此文件并复制内容。
b)为了不扰乱宏文件,它打开另一个文件&#34; dly_nsedly_conversion.xlsx&#34; 。首先,从Cell A1开始,将在上一步中复制的文本文件的内容粘贴到Sheet3上。其次,它清除以前的内容&#34; NSE_DLY_RAW&#34;表格,否则可能有重复的行。选择范围高达H2000,因为国家证券交易所的一般价格文件包含少于2000个报价。然后它移动到sheet3并确定填充单元格的范围并移动到&#34; NSE_DLY_RAW&#34;从单元格A2开始粘贴选定范围,以便不打扰标题行。日期列也从文本字符串转换为日期格式。
c。.xlsx格式的转换文件作为EOD_Converted.xlsx文件保存到mydir \ EOD_Converted_Date文件夹,该文件可以直接导入Access数据库,也可以通过Access导出为csv文件输入到Amibroker Trader程序。 EOD_Formatting.xlsm的代码附在下面。
Public fname As String
Public Sub open_text_file()
Dim wb1 As Excel.Workbook
Dim wb2 As Excel.Workbook
Dim filepath As String
Dim r As Range, i As Long
'path of the file whcih contains the file as
'received 'from 'software utility NSE EOD Data Downloader v3.0
filepath = "C:\mydir\EOD_Data\"
'Input filename like "EQ_04AUG2015.txt" to be processed by excel
'macro file
On Error Resume Next
fname = Application.InputBox("Enter the Filename", Type:=2)
On Error GoTo 0
Workbooks.OpenText Filename:=filepath & fname, _
StartRow:=1, DataType:=xlDelimited, Comma:=True
Cells.Select
Selection.Copy
'File no. of quotes vary daily. Further processing to transform
'date string from text to date format and variable length files
Set wb2 = Workbooks.Open("C:\mydir\dly_nsedly_conversion.xlsx")
Sheets("Sheet3").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("NSE_DLY_RAW").Select
'It is desired to clear previous content otherwise there can be
'duplicate rows. H2000 chosen because general Price file _
' of National Stock Exchange contains less than 2000 quotes
ActiveSheet.Range("A2:H2000").Select
Selection.ClearContents
Sheets("Sheet3").Select
Dim rng1 As Range
Dim rng2 As Range
Dim rng3 As Range
Set rng1 = Cells.Find("*", [A1], , , xlByRows, xlPrevious)
Set rng2 = Cells.Find("*", [A1], , , xlByColumns, xlPrevious)
If Not rng1 Is Nothing Then
Set rng3 = Range([A1], Cells(rng1.Row, rng2.Column))
Range([A1], Cells(rng1.Row, rng2.Column)).Select
Selection.Copy
End If
Sheets("NSE_DLY_RAW").Select
Range("A2").Select
ActiveSheet.Paste
LR = Cells(rows.Count, "B").End(xlUp).Row
Range("B2:B" & LR).Select
Dim c As Range
For Each c In Selection.Cells
c.value = DataSerial(Left(c.Value,4), Mid(c.Value, 5,2), Right_
(c.Value,2))
'Following line added only to enforce the format.
c.NumberFormat = "dd/mm/yyyy"
Next
' EOD_Converted File is suitable for input to Access Data base
' and Amibroker with minor working
ActiveWorkbook.SaveAs Filename:= _
"C:\mydir\EOD_Converted_Data\EOD_Converted.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
Workbooks.Close
End Sub
虽然这个程序对我有用,但我仍在努力解决以下问题。 一个)。如果收到的数据少于1500个引号,则在数据填充范围结束后仍保留空白行。这些空行阻碍在Access 2007中选择安全符号作为关键字段,因为它不允许关键字段中的重复值或空白字段。 b)我希望转换后的输出文件从输入框中输入的文件名中取出文件名而不是通用文件名。 我是Excel VBA的初学者。我很感激任何帮助,使这个程序更专业和用户友好,并指导我一些解决上述问题的线索。该计划对普通非技术投资者有帮助。 感谢。
PS: Internet connection has started working normally in our area now. As
'such uploading pictures of sample files.