-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathfGetIndex.m
More file actions
155 lines (107 loc) · 4.48 KB
/
fGetIndex.m
File metadata and controls
155 lines (107 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
classdef fGetIndex < handle
%% fGetIndex
% 获取指数相关数据
% 获取指数成分股
% by LiYang_faruto
% Email:farutoliyang@foxmail.com
% 2015/6/1
%% properties
properties
isSave = 1;
Code = '000300';
end
%% properties(SetAccess = private, GetAccess = public)
properties(SetAccess = private, GetAccess = public)
end
%% properties(Access = protected)
properties(Access = protected)
end
%% properties(Access = private)
properties(Access = private)
end
%% methods
methods
%% fGetIndex()
function obj = fGetIndex( varargin )
end
%% Fun()
function [OutputData,dStr] = GetCons(obj,varargin )
OutputData = [];
dStr = [];
% %===输入参数检查 开始===
Flag = ParaCheck(obj);
if 0 == Flag
str = ['请检查输入参数是否正确!'];
disp(str)
return;
end
% %===输入参数检查 完毕===
% 399704深证上游 399705深证中游 399706深证下游
% 399701深证F60 399702深证F120 399703深证F200
SpecialList = {'399704';'399705';'399706';'399701';'399702';'399703';};
CustomList = {};
FolderStr = ['./IndexCons'];
if ~isdir( FolderStr )
mkdir( FolderStr );
end
FileName = [obj.Code,'成分股'];
FileString = [FolderStr,'/',FileName,'.xls'];
FileExist = 0;
if exist(FileString, 'file') == 2
FileExist = 1;
end
if 1 == FileExist
FileString = [FolderStr,'/',FileName,'(1)','.xls'];
end
if obj.Code(1) == '3' && ~ismember(obj.Code,SpecialList)
% http://www.cnindex.com.cn/docs/yb_399005.xls
URL = ['http://www.cnindex.com.cn/docs/yb_',obj.Code,'.xls'];
try
outfilename = websave(FileString,URL);
catch
str = ['数据获取失败,请检查输入的指数代码!',obj.Code];
disp(str);
return;
end
[num,txt,raw] = xlsread(outfilename);
dStr = raw{1,8};
OutputData = raw(:,3:6);
OutputData(1,:) = {'Code','Name','Weight','Industry'};
else
URL = ['http://www.csindex.com.cn/sseportal/ps/zhs/hqjt/csi/',obj.Code,'cons.xls'];
try
outfilename = websave(FileString,URL);
catch
str = ['数据获取失败,请检查输入的指数代码!',obj.Code];
disp(str);
return;
end
[status,sheets] = xlsfinfo(outfilename);
dStr = ['更新时间:',sheets{1,1}];
[num,txt,raw] = xlsread(outfilename);
OutputData = raw;
OutputData(1,:) = {'Code','Name','Name(Eng)','Exchange'};
end
if obj.isSave == 0
delete(FileString);
else
str = [obj.Code,'指数成分股数据已保存至',FileString];
disp(str);
end
end
%% 输入参数检查函数
function Flag = ParaCheck(obj, varargin )
Flag = 1;
% %===输入参数检查 开始===
% checkflag = ismember( lower(obj.DownUpSampling),lower(obj.DownUpSampling_ParaList) );
% if checkflag ~= 1
% str = ['DownUpSampling参数输入错误请检查!可选的参数列表为(大小写都行):'];
% disp(str);
% ParaList = obj.DownUpSampling_ParaList
% Flag = 0;
% return;
% end
% %===输入参数检查 完毕===
end
end
end