set flag Reparse. replace real with double. replace Real with Double. replace price with float. srecord noeq MPM3 { // MARKET (trading platform) // How much percentual slippage we have for each position on // average plus the fees for the position. // Obviously dependent on the market (trading site) we are using. settable double marketAdversity = 0.1; // POSITIONS // An open(ed) position record Position(TickerSequence ticker, real openingTime, real direction) { real openingPrice() { ret ticker.priceAtTimestamp(openingTime); } real profitAtTime(real time) { ret (ticker.priceAtTimestamp(time)/openingPrice()*100-100)*direction - marketAdversity; } record ClosedPosition(Position p, real closingTime) { settable real profit; MPM3 mpm() { ret MPM3.this; } TickerSequence ticker() { ret p.ticker; } real openingPrice() { ret p.openingPrice(); } real closingPrice() { ret ticker().priceAtTimestamp(closingTime); } } // BOT (Eye + Juicer) srecord Juicer(real lossTolerance, real pullback) {} abstract sclass Eye { abstract real adviseDirection(Ticker ticker); } // time = ms to look back srecord SimpleEye(long time, real minMove) extends Eye { real adviseDirection(Ticker ticker) { Real currentPrice = ticker.currentPrice(); if (currentPrice == null) ret 0; Real before = ticker.lookback(time); if (before == null) ret 0; real move = currentPrice/before*100-100; if (abs(move) >= minMove) ret (real) sign(move); ret 0; } } srecord TradingBot(Eye eye, Juicer juicer) {} /* ClosedPosition runJuicer(Position p, Juicer j) { 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)) ret (real) time; ++time; } null; }*/ // eye can be null, then we just test the juicer record noeq Backtest(TradingBot bot) extends Convergent { void step { done = true; } } }