-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoptionparse.m
56 lines (35 loc) · 1.84 KB
/
optionparse.m
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
function out = optionparse(path2csv,provider,underlying)
%optionparse() parses option data file to matlab table
% This is supplementary function which parses data file with historical
% option chains for given equity into matlab table data type.
% INPUT:
% path2csv - path to .csv file with historical option chains
% provider - provider of data (different providers have different data file headers)
% underlying - type of the underlying (different types of the underlying can have different
% headers even if they are from same provider)
% OUTPUT:
% out - parsed data file to matlab table
% Petr Javorik (2016) [email protected]
% http://mmquant.net/introduction-to-volatility-models-iv
% Input check
providers = {'ivolatility'}; % more to be added
underlyings = {'equity'}; % more to be added
assert(nargin == 3,'Valid arguments are optionparse(path2csv,provider,underlying).');
assert(exist(path2csv, 'file') == 2,'Data file doesn''t exist.');
assert(ismember(provider,providers),'Unknown datafile provider.');
assert(ismember(underlying,underlyings),'Unknown datafile provider.');
switch provider
case 'ivolatility'
if strcmp(underlying,'equity')
header = {'symbol','exchange','date','adjusted_stock_close_price','option_symbol',...
'expiration','strike','call_put','style','ask','bid','volume','open_interest',...
'unadjusted_stock_price'};
% Parse
out.data = readtable(path2csv,'ReadVariableNames',false,'HeaderLines',1,...
'Format','%s%s%{MM/dd/yy}D%f32%s%{MM/dd/yy}D%f32%s%s%f32%f32%u16%u16%f32');
out.data.Properties.VariableNames = header;
end
case '' % new provider
% ...
end
end