summaryrefslogtreecommitdiff
path: root/regress_interval_pred.m
blob: 035bbb420cc7344947772c152b982e6c591095c9 (plain)
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
function pred = regress_interval_pred(price, quantity, interval)
	assert(mod(size(price,  1),   interval) == 0);
	assert(mod(size(quantity, 1), interval) == 0);

	days = size(price, 1) - size(quantity, 1);
	product_count = size(price, 2);
	test_count = size(quantity, 1);

	test_interval_count = size(quantity, 1) / interval;
	pred_interval_count = days / interval;
	test_base = [0:test_interval_count-1] * interval;
	pred_base = [0:pred_interval_count-1] * interval;

	pred = zeros(days, product_count);
	for i = 1:product_count
		for j = 1:interval
			test_set = test_base + j;
			pred_set = pred_base + j;

			regress_quad = @(x, y) [ log(x) x.^0 ] \ y;
			abc = regress_quad(price(test_set, i), quantity(test_set, i));
			pred(pred_set, i) = polyval(abc, log(price(test_count+pred_set, i)));
		end
	end

endfunction