-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathGetBasicInfo_Mat.m
More file actions
107 lines (85 loc) · 2.62 KB
/
GetBasicInfo_Mat.m
File metadata and controls
107 lines (85 loc) · 2.62 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
function [DataOutput, Status] = GetBasicInfo_Mat(Code,BeginDate,EndDate,Type,Field)
% 获取基本信息 比如IPOdate
% by LiYang_faruto
% Email:farutoliyang@foxmail.com
% 2015/03/01
% % Input:
%
% Type
% Stock:获取股票数据 Future:获取期货数据
% StockIndex:获取股票相关指数数据
% FutureIndex:获取期货相关指数数据
% Field
% IPOdate
% Name
%% 输入输出预处理
DataOutput = [];
Status = [];
Status = 0;
if nargin < 5 || isempty(Field)
Field = 'IPOdate';
end
if nargin < 4|| isempty(Type)
Type = 'Stock';
end
if nargin < 3 || isempty(EndDate)
EndDate = '20150101';
end
if nargin < 2 || isempty(BeginDate)
BeginDate = '20140101';
end
if nargin < 1 || isempty(Code)
Code = 'sh600588';
end
if strcmpi(Type,'Stock') || strcmpi(Type,'gp') ...
|| strcmpi(Type,'gupiao') || strcmpi(Type,'s')
% 代码预处理,目标代码demo 'sh600588'
if Code(1,1) == '6'
Code = ['sh',Code];
end
if Code(1,1) == '0'|| Code(1,1) == '3'
Code = ['sz',Code];
end
end
% 日期时间预处理,目标形式 '20140101'
BeginDate(BeginDate == '-') = [];
EndDate(EndDate == '-') = [];
BeginDate = str2double(BeginDate);
EndDate = str2double(EndDate);
if BeginDate>EndDate
str = ['开始日期需要小于等于结束日期,请检查输入参数!'];
disp(str);
return;
end
%% 获取股票数据
if strcmpi(Type,'Stock') || strcmpi(Type,'gp') ...
|| strcmpi(Type,'gupiao') || strcmpi(Type,'s')
CodeInput = Code;
% % 获取上市日期
if strcmpi(Field, 'IPOdate')
IPOdate = [];
FolderStr_StockInfo = ['./DataBase/Stock/StockInfo_mat'];
FileString_StockInfo = [FolderStr_StockInfo,'/',CodeInput,'_StockInfo.mat'];
if exist(FileString_StockInfo, 'file') == 2
str = ['load ',FileString_StockInfo];
eval(str);
IPOdate = StockInfo.IPOdate;
end
DataOutput = IPOdate;
end
% % 获取股票名称
if strcmpi(Field, 'Name')
FileString = 'StockList.mat';
MatObj = matfile(FileString,'Writable',true);
[nrows, ncols]=size(MatObj,'StockList');
if nrows>1
CodeDouble = str2num( CodeInput(3:end) );
SearchIndex = MatObj.StockList(:,3);
SearchIndex = cell2mat(SearchIndex);
ind = find( SearchIndex==CodeDouble,1 );
if ~isempty(ind)
DataOutput = MatObj.StockList(ind,1);
end
end
end
end