-
Notifications
You must be signed in to change notification settings - Fork 0
/
stock.m
77 lines (67 loc) · 3.69 KB
/
stock.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
classdef stock < handle
% handle might be necessary to reference from optionTable and
% histTable classes (or use @)
%STOCK Class with variables (including names of option tables) that can
%instantia objects to get option or hist tables
properties
symbol;
portfolio; % useful for intermarket spreads. Needed to get interest rate
% correlationSpy; % should be used for intermarket spread and
% portfolio risk (reduce with unit puts). Can be calculated given
% enough hist data
IVLevel = '';
IVToHV = '';
IVDirection = '';
HVLevel = '';
HVDirection = '';
IntraMonthSkew = '';
TermStructure = '';
UnderlyingDirection = '';
end
methods
function obj = stock (symbol, portfolio)
fprintf('Constructing stock.\n')
obj.symbol = symbol;
obj.portfolio = portfolio;
end
% FIXME DEPRECIATED
function stockSpec = getSpec (obj, volNrDays, varargin)
[~, dividendData] = obj.getDividend ();
if ~exist('volNrDays', 'var') || isempty(volNrDays)
volNrDays = namedConst.defaultVolNrDays;
end
if ~isempty(dividendData)
[type, amounts, dates] = dividendData{:};
stockSpec = stockspec(obj.getPrice1dVar(['SD' num2str(volNrDays)], varargin{:}), obj.getPrice1dVar('last', varargin{:}), type, amounts, dates);
else
stockSpec = stockspec(obj.getPrice1dVar(['SD' num2str(volNrDays)], varargin{:}), obj.getPrice1dVar('last', varargin{:}));
if isnan(stockSpec.Sigma)
error('sigma not calculated')
end
end
end
function filteredSpreads = filterSpreads(obj)
cheatSheet = namedConst.cheatSheet();
names = keys(cheatSheet);
spreadTypes = values(cheatSheet);
filteredSpreads = containers.Map();
% filter out only spreads that match inputs (ie current market
% conditions)
for i = 1:numel(names)
spread = spreadTypes{i};
qualifies = true;
qualifies = qualifies && (isempty(obj.IVLevel) || isempty(spread.IVLevel) || ~isempty(intersect(obj.IVLevel, spread.IVLevel)));
qualifies = qualifies && (isempty(obj.IVToHV) || isempty(spread.IVToHV) || ~isempty(intersect(obj.IVToHV, spread.IVToHV)));
qualifies = qualifies && (isempty(obj.IVDirection) || isempty(spread.IVDirection) || ~isempty(intersect(obj.IVDirection, spread.IVDirection)));
qualifies = qualifies && (isempty(obj.HVLevel) || isempty(spread.HVLevel) || ~isempty(intersect(obj.HVLevel, spread.HVLevel)));
qualifies = qualifies && (isempty(obj.HVDirection) || isempty(spread.HVDirection) || ~isempty(intersect(obj.HVDirection, spread.HVDirection)));
qualifies = qualifies && (isempty(obj.UnderlyingDirection) || isempty(spread.UnderlyingDirection) || ~isempty(intersect(obj.UnderlyingDirection, spread.UnderlyingDirection)));
qualifies = qualifies && (isempty(obj.IntraMonthSkew) || isempty(spread.IntraMonthSkew) || ~isempty(intersect(obj.IntraMonthSkew, spread.IntraMonthSkew)));
qualifies = qualifies && (isempty(obj.TermStructure) || isempty(spread.TermStructure) || ~isempty(intersect(obj.TermStructure, spread.TermStructure)));
if qualifies
filteredSpreads(names{i}) = spread;
end
end
end
end
end