Page 1 of 1

reorder vec2 so that +/((vec1-vec2)-scaler)*2 is minimized

Posted: Wed May 30, 2012 3:28 pm
by tclviiidyalog
the subject of the thread sorta says it all, but a little background

suppose i have 25 paired buys and sales of a single widget
sales
71 99 96 86 29 54 52 11 42 58 88 45 73 87 72 81 71 75 2 89 53 47 7 72 49
buys
67 69 20 92 87 90 55 14 46 99 22 45 32 52 89 44 47 81 37 22 100 16 64 62 1

Did I make money?
+/sales-buys
156
Yep. I did (though one shouldn't make the assumption of a positive result when forming the solution)

on average how much did I make?
(÷⍴sales) × +/sales-buys
6.24 (again, this might've been negative)

so the question is, how do I rearange the order of sales [or buys for that matter, or both]
such that the average difference twixt a buy and a sale is a 6.24 profit?

that of course begs the question, what is meant by ''close'' when
saying ''average profit'' . . . a couple o' candidate definitions

- minimize +/((sales-buys)-6.24)*2
this is a least squares problem, so I should be able to use domino, but I can't quite formulate the problem in terms of a regression

- minimize +/ | (sales-buys)-6.24
this is an ''entropy'' problem

- Maximize +/ (×6.24) = × sales-buys
this tries to get the maximal number of profitable pairings(or negative pairings, if we'd lost 6.24 on average
and thus the signum was negative), and stuffing the losses into as few pairings as possible
the problem with this are cases where one might get 23 small profitable pairings and
two giant negative pairings, such extremes are not particularly desirable