-
Notifications
You must be signed in to change notification settings - Fork 0
/
mymethod.m
39 lines (32 loc) · 1.16 KB
/
mymethod.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
function [sellUSD, sellBitcoin] = mymethod(file, usdWallet, btcWallet)
%MYMETHOD Implements trading strategy. Returns selling/buying decision
%for next day
arguments
file {mustBeFile}
usdWallet {mustBeNonnegative}
btcWallet {mustBeNonnegative}
end
data = readtimetable(file, MissingRule="error", ExpectedNumVariables=5, ...
DecimalSeparator=".", ExtraColumnsRule="error");
mustBeInOhlcFormat(data)
shortTermWindow = 20;
longTermWindow = 50;
shortTermMA = movmean(data.Close, shortTermWindow);
longTermMA = movmean(data.Close, longTermWindow);
lastShortTermMA = shortTermMA(end);
lastLongTermMA = longTermMA(end);
sellUSD = 0;
sellBitcoin = 0;
if lastShortTermMA > lastLongTermMA
sellUSD = usdWallet * 0.1;
elseif lastShortTermMA < lastLongTermMA
sellBitcoin = btcWallet * 0.1;
end
end
function mustBeInOhlcFormat(timetbl)
correct_columns = {"Close","High","Low", "Open"};
if ~isequal(sort(timetbl.Properties.VariableNames), correct_columns)
msg = "The timetable must have following columns: Close, High, Low, and Open";
error(msg)
end
end