replace real with double. replace Real with Double. srecord noeq MPM2(real[] ticker) { // how much percentual slippage we have for each position on // average dependent on the market (trading site) we are using record Market(real adversity) {} record Juicer(real lossTolerance, real pullback /*, real smoothing*/) {} //class OpenOrder { real openingTime, direction; } //class Position { OpenOrder openOrder; real crest, profit; } record Position(real openingTime, real direction) { real openingPrice() { ret ticker(openingTime); } } record Eye(real width, real height, real interval) {} real ticker(real time) { ret ticker(iceil(time)); } // all "profit" functions return a positive or negative percent value real profit(Position p, real time, Market m) { ret (ticker(time)/p.openingPrice()*100-100)*p.direction - m.adversity; } real closingTime(Position p, Juicer j, Market m) { int time = iceil(p.openingTime); real openingPrice = ticker(time); real crest = -infinity(); while (time < ticker.length-1) { real profit = profit(p, time, m); crest = max(crest, profit); if (profit < (profit < 0 ? -j.lossTolerance : crest-j.pullback)) break; ++time; } ret time; } real profit(Position p, Juicer j, Market m) { ret profit(p, closingTime(p, j, m), m); } // How profitable is it to open a position of any direction // at a certain point in time? real profitability(real time, Juicer j, Market m) { ret max( profit(new Position(time, -1), j, m), profit(new Position(time, 1), j, m)); } abstract class Convergent extends ItIt { Real value; bool stepped, done; public bool hasNext() { if (done) false; if (!stepped) { stepped = true; step(); } ret !done; } public Real next() { assertTrue(hasNext()); stepped = false; ret value; } abstract void step(); } record noeq JuicerBacktest(Juicer j, Market m/*, real[] ticker*/) extends Convergent { // TODO: use randomized "weightless" shuffling iterator Iterator openingTimes = shuffledIterator(intRangeList(ticker.length)); new Average profitPerPosition; void step { if (!openingTimes.hasNext()) ret with done = true; real openingTime = openingTimes.next(); profitPerPosition.addSample(profitability(openingTime, j, m)); value = profitPerPosition!; } } }