// http://www.haskell.org/haskellwiki/Programming_performance / arthur: x:|1_*(" F";" ")0:`gspc.txt f:{$[y;[b[z]+:(.1*x)%z;.9*x];[z*:+/b p@:&~z<1.06*p:!b;b::p_b;x+z]]} g:{b!:b::0#0.0;(last[x]*+/b)+f/[1e4;~.97<%':x;x]} g x / attila (revision): c:1e4;h:()!();d:|1_*(" F";" ")0:`gspc.txt c+/h*{$[~0.97y%i:!h;[c+:y*+/h i;h::i_h]];y}/d / arthur rewritten for clarity: D:|1_*(" F";" ")0:`gspc.txt / data H!:H::0#0.0 / holdings F:{$[y;B;S][x]z} / trade T:{(last[x]*+/H)+F/[1e4;~.97<%':x;x]} / trading strategy B:{H[y]+:(.1*x)%y;.9*x} / buy S:{y*:+/H p@:&~y<1.06*p:!H;H::p_H;x+y} / sell T D / run / attila rewritten for clarity: D:|1_*(" F";" ")0:`gspc.txt / data C:1e4 / cash H:()!() / holdings T:{$[~0.97y%i:!H;S[y]i];y} / trading strategy B:{C-:m:.1*C;H[x]:m%x} / buy S:{C+:x*+/H y;H::y_H} / sell C+/H*T/D / run / jason: D:|1_*(" F ";" ")0:`:gspc.txt / data C:10000.00 / cash P:(`u#0#0.)!0#0. / portfolio (price -> quantity) T:{if[~.97x%p:!P;P[p]:0.} (*D)T':D; / run on current, previous C++/.:[P]**-1#D / sell off remaining \ Simulate the following strategy on the GSPC data set: Whenever the closing cost is down 3% or more from the previous closing cost, buy shares with 10% of current cash. Whenever the closing cost is up 6% or more from the original purchase price, sell back the full amount of stock purchased at that price. Sell off any remaining assets after the last day. Run the strategy on the provided data starting with $10,000.00 in cash and no holdings. All purchases are made at the closing cost. Fractional shares may be purchased. Fractional pennies may be used. Do not simulate any trading costs, interest dividends or taxes. Percent change is 100 percent times the change (new price minus old price) divided by the old price.