public override void setUp() { base.setUp(); emailer.allowMessages(); liveSystem = OneSystemTest <TestSystem> .fakeLiveSystem(new Parameters { { "LeadBars", 0.0 } }, false); data = new FakeBarLoader(SYMBOL); simulator = data.simulator(new SystemArguments(SYMBOL, parameters(liveSystem)), "TEST"); system = simulator.theSymbolSystem <TestSystem>(SYMBOL); SYMBOL.setCloseTimeForTest("14:00:00", 300); bar(0, 0, 0, 0); }
public void testIntraDayLiveBars() { var siv5Minute = new Siv("TestSystem1", "second", "1.0"); var liveSystem = new LiveSystem(siv5Minute, FAST); liveSystem.insertParameter("LeadBars", "0"); var args = arguments(O.list(SYMBOL, SYMBOL2), liveSystem, RunMode.LIVE, typeof(EmptySystem)); var loader = new FakeBarLoader(SYMBOL, SYMBOL2); var simulator = loader.simulator(args, OrderTable.prefix); try { Action <int, int> bar = (close, minutesAfter9) => { var barTime = Dates.minutesAhead(minutesAfter9, Dates.date("2008/09/08 09:00:00")); loader.add(SYMBOL, close, close, close, close, barTime); loader.add(SYMBOL2, close, close, close, close, barTime); simulator.nextBar(); }; Action <Symbol, int, string> doTick = (symbol, price, time) => { O.freezeNow("2008/09/08 " + time); tick(simulator, new Bar(0, price, 0, price, O.now()), symbol); }; bar(5, 0); O.freezeNow("2008/09/08 09:00:00"); simulator.goLive(); doTick(SYMBOL, 26, "09:00:00"); doTick(SYMBOL2, 28, "09:00:00"); doTick(SYMBOL, 25, "09:00:00"); doTick(SYMBOL2, 29, "09:00:00"); simulator.waitForBar(); var system = simulator.theSymbolSystem <EmptySystem>(SYMBOL); var system2 = simulator.theSymbolSystem <EmptySystem>(SYMBOL2); AreEqual(new Bar(26, 26, 25, 25, date("2008/09/08 09:00:00")), system.bar); AreEqual(new Bar(28, 29, 28, 29, date("2008/09/08 09:00:00")), system2.bar); O.freezeNow("2008/09/08 09:00:01"); doTick(SYMBOL, 42, "09:00:01"); doTick(SYMBOL, 57, "09:00:01"); doTick(SYMBOL, 15, "09:00:01"); system.placeOrder(SYMBOL.buy("somethin", Order.market(), 1, FillOrKill.FILL_KILL)); simulator.waitForBar(); // if it blows up in orderFilled here, it filled orders during live intraday bar (incorrect) IsTrue(O.isEmpty(system.allPositions())); AreEqual(new Bar(42, 57, 15, 15, date("2008/09/08 09:00:01")), system.bar); AreEqual(new Bar(28, 29, 28, 29, date("2008/09/08 09:00:00")), system2.bar); AreEqual(3, system.bars.count()); AreEqual(2, system2.bars.count()); } finally { simulator.clearTimer(); } }
public void testOnCloseIntraDay() { var siv5Minute = new Siv("TestSystem1", "5minute", "1.0"); var liveSystem = new LiveSystem(siv5Minute, FAST); var args = arguments(O.list(SYMBOL, SYMBOL2), liveSystem, RunMode.RIGHTEDGE, typeof(TestOnCloseSystem)); var loader = new FakeBarLoader(SYMBOL, SYMBOL2); var simulator = loader.simulator(args, OrderTable.prefix); var system = simulator.theSymbolSystem <TestOnCloseSystem>(SYMBOL); var system2 = simulator.theSymbolSystem <TestOnCloseSystem>(SYMBOL2); MarketSessionTable.SESSION.update(SYMBOL.name, Session.DAY, "16:00:00", 360); MarketSessionTable.SESSION.update(SYMBOL2.name, Session.DAY, "15:50:00", 360); Action <int, int> bar = (close, minutesAfter3) => { var barTime = Dates.minutesAhead(minutesAfter3, Dates.date("2008/08/08 15:00:00")); loader.add(SYMBOL, close, close, close, close, barTime); loader.add(SYMBOL2, close, close, close, close, barTime); simulator.nextBar(); }; Action <bool, bool> closeTriggered = (expected1, expected2) => { AreEqual(expected1, system.onCloseTriggered); AreEqual(expected2, system2.onCloseTriggered); system.onCloseTriggered = false; system2.onCloseTriggered = false; }; O.zeroTo(5, i => { bar(i, 15 + i * 5); closeTriggered(false, false); }); bar(6, 40); closeTriggered(false, false); // ? format but couldn't resist the parallellism. and terseness. bar(7, 45); closeTriggered(false, true); bar(8, 50); closeTriggered(false, false); bar(9, 55); closeTriggered(true, false); bar(10, 60); closeTriggered(false, false); }