summaryrefslogtreecommitdiff
path: root/quad_regress_pred.m
blob: d9e3b6ee6f8c9e84bac2ec657d5876017f6ed430 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function pred = quad_regress_pred(price, quantity)

	days = size(price, 1) - size(quantity, 1);
	product_count = size(price, 2);
	test_count = size(quantity, 1);
	test_set = 1:test_count;
	pred_set = test_count+1:size(price, 1);

	pred = zeros(days, product_count);
	for i = 1:product_count
		abc = regress2(price(test_set, i), quantity(test_set, i));
		pred(:, i) = polyval(abc, price(pred_set, i));
	end

endfunction


function abc = regress2(x, y)
	abc = [ x.^2 x ones(length(x), 1) ] \ y;
endfunction