diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-05-12 20:06:31 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-05-12 20:06:31 +0200 |
commit | 6ab709531700c64dee835b2662bbd59e558628c8 (patch) | |
tree | 9d28bc985278b86b9ee4606198c63dde4ee5b860 | |
parent | 19b83ed059102f369a0c84e7f2c1e06b5c9ea106 (diff) | |
download | dmc-6ab709531700c64dee835b2662bbd59e558628c8.tar.gz dmc-6ab709531700c64dee835b2662bbd59e558628c8.tar.bz2 dmc-6ab709531700c64dee835b2662bbd59e558628c8.zip |
Add a interval based regression
But its actually a very ugly prediction.
-rw-r--r-- | regress_interval_pred.m | 26 | ||||
-rw-r--r-- | run_tests.m | 1 |
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); |