summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--regress_interval_pred.m26
-rw-r--r--run_tests.m1
2 files changed, 27 insertions, 0 deletions
diff --git a/regress_interval_pred.m b/regress_interval_pred.m
new file mode 100644
index 0000000..035bbb4
--- /dev/null
+++ b/regress_interval_pred.m
@@ -0,0 +1,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
diff --git a/run_tests.m b/run_tests.m
index e33f19b..71bd07e 100644
--- a/run_tests.m
+++ b/run_tests.m
@@ -17,6 +17,7 @@ pred_methods = [
% m('norm rand.',@rand_pred)
% m('chi rand.',@chi_pred)
m('regress2', @regress_frequency_removal)
+% m('reg 7day', @(p,q) regress_interval_pred(p, q, 7))
];
num_methods = size(pred_methods, 1);