-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbigMacExample.m
65 lines (50 loc) · 2.07 KB
/
bigMacExample.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
%% Big Mac in USD vs Big Mac in Gold
% Download the data
initDate = '1-Jan-2000';
bigmac_quanl_raw = getMarketDataViaQuandl('ECONOMIST/BIGMAC_USA', initDate);
bigmac_quanl= timeseries([bigmac_quanl_raw.local_price], datestr(bigmac_quanl_raw(:,1).Date)); %
bigmac_quanl.TimeInfo.Format = "dd-mm-yyyy";
oz_in_grams = 31.1034768;
gold_yahoo_raw = getMarketDataViaYahoo('GC=F', initDate);
gold_yahoo_ts = timeseries([gold_yahoo_raw.Close/oz_in_grams], datestr(gold_yahoo_raw.Date));
gold_yahoo_ts.TimeInfo.Format = "dd-mm-yyyy";
% match dates
for k = 1:size(bigmac_quanl_raw,1)
[~, ind] = min(abs(datenum(gold_yahoo_raw.('Date')(:)) - datenum(bigmac_quanl_raw.Date(k))));
bigmac_price_in_gold(k) = bigmac_quanl_raw.local_price(k)/gold_yahoo_ts.Data(ind);
end
bigmac_price_in_gold_ts = timeseries(bigmac_price_in_gold, datestr(bigmac_quanl_raw(:,1).Date));
bigmac_price_in_gold_ts.TimeInfo.Format = "dd-mm-yyyy";
% plot
figure('color', 'white');
yyaxis left
plot(bigmac_quanl, 'linewidth', 2), hold on;
ylabel('USD')
yyaxis right
plot(bigmac_price_in_gold_ts, 'linewidth', 2);
ylabel('g of Gold')
title('Big Mac');
grid on, grid minor
%% Big Mac in USD vs Big Mac in BTC
initDate = '2014-09-17';
btc_yahoo_raw = getMarketDataViaYahoo('BTC-USD', initDate);
bigmac_quanl_raw = getMarketDataViaQuandl('ECONOMIST/BIGMAC_USA', initDate);
bigmac_quanl= timeseries([bigmac_quanl_raw.local_price], datestr(bigmac_quanl_raw(:,1).Date)); %
bigmac_quanl.TimeInfo.Format = "dd-mm-yyyy";
for k = 1:size(bigmac_quanl_raw,1)
[val, ind] = min(abs(datenum(btc_yahoo_raw.('Date')(:)) - datenum(bigmac_quanl_raw.Date(k))));
bigmac_price_in_btc(k) = bigmac_quanl_raw.local_price(k)/btc_yahoo_raw.Close(ind);
end
bigmac_price_in_btc_ts = timeseries(bigmac_price_in_btc, datestr(bigmac_quanl_raw(:,1).Date));
bigmac_price_in_btc_ts.TimeInfo.Format = "dd-mm-yyyy";
bigmac_price_in_btc_ts.DataInfo.Units = "BTC";
figure('color', 'white');
yyaxis left
plot(bigmac_quanl, 'linewidth', 2), hold on;
ylabel('USD')
yyaxis right
plot(bigmac_price_in_btc_ts, 'linewidth', 2);
ylabel('BTC')
title('Big Mac')
grid on
grid minor