Example #1
0
        static void generateCurves(LiveSystem system, IEnumerable <JMarket> markets, QDirectory directory, DateTime start, DateTime end, DataSource metricSource)
        {
            var symbols    = convert(markets, market => new Symbol(market.name(), market.bigPointValue()));
            var parameters = new Parameters {
                { "systemId", system.id() },
                { "RunMode", (double)RunMode.LIVE }
            };
            var startLoading = DateTime.Now;

            Bomb.when(system.details().runInNativeCurrency(), () => "portfolio optimization requires systems to run in dollars, not native currency");
            var bars            = new SystemDbBarLoader(system.details().interval(), symbols, start, end);
            var simulator       = new Simulator(new SystemArguments(symbols, parameters), bars, "QUEDGE");
            var startProcessing = DateTime.Now;
            var perSecond       = simulator.processBars();

            saveMetric(system, "marketBarsPerSecond", metricSource, perSecond);
            var startMetricCalc = DateTime.Now;

            simulator.metrics();
            saveMetric(system, "metricCalculationSeconds", metricSource, secondsSince(startMetricCalc));
            saveMetric(system, "totalRunSeconds", metricSource, secondsSince(startProcessing));
            simulator.writeCurveFiles(directory);
            saveMetric(system, "totaSeconds", metricSource, secondsSince(startLoading));
            Db.commit();
        }
Example #2
0
        public static Simulator run(int systemId, IEnumerable <Symbol> symbols, IEnumerable <QPortfolio> portfolios, int runNumber, BarLoader data, bool dumpParamsOnly, bool shutdown)
        {
            var parameters = new Parameters {
                { "systemId", systemId },
                { "RunMode", (double)RunMode.STO },
                { "RunNumber", runNumber }
            };

            try {
                parameters.runNumber();
                LogC.err("" + parameters);
                if (dumpParamsOnly)
                {
                    return(null);
                }
                var simulator = new Simulator(new SystemArguments(symbols, portfolios, parameters), data, "QUEDGE");
                simulator.processBars();
                if (shutdown)
                {
                    simulator.shutdown();
                }
                else
                {
                    var metrics = simulator.metrics();
                    LogC.verbose(() => "skipping shutdown based on noShutdown parameter.");
                    LogC.verbose(() => toShortString(metrics["ALL"]));
                }
                return(simulator);
            } catch (Exception e) {
                throw Bomb.toss("\nFailed in run " + runNumber + "\nUsing:\n" + parameters + "\n", e);
            }
        }
Example #3
0
        public void testCanRunSystem()
        {
            var className  = "Q.Systems.NDayBreak";
            var parameters = new Parameters(className)
            {
                { "ATRLen", 10 },
                { "ATRlong", 100 },
                { "BreakDays", 30 },
                { "FirstDayATR", 1 },
                { "FixEquity", 1 },
                { "InitEquity", 6000000 },
                { "LeadBars", 50 },
                { "MaxPyramid", 1 },
                { "Risk", 0.02 },
                { "nATR", 2 },
                { "upATR", 2 },
                { "systemId", 39 }
            };
            var markets   = O.list(new Symbol(new Market("RE.TEST.TY.1C")));
            var arguments = new SystemArguments(markets, parameters);
            var simulator = new Simulator(arguments, "NOSENDMESSAGES");

            simulator.processBars(300);
            AlmostEqual(293099.30, simulator.pnl(), 0.01);
        }
Example #4
0
        public static void Main(string[] args)
        {
            var arguments = Arguments.arguments(args, jStrings("system", "prefix"));
            var system    = arguments.get("system");
            var prefix    = arguments.get("prefix", PREFIX_DEFAULT);

            LogC.setOut("Tomahawk", Systematic.logsDir().file("Tomahawk." + system + ".log").path(), true);
            LogC.useJavaLog = true;
            LogC.info("running system " + system + ", process " + processId());
            var liveSystems = accept(list <LiveSystem>(MsivLiveHistory.LIVE.liveSystems()), ls => ls.siv().system().Equals(system));

            each(liveSystems, liveSystem => {
                Bomb.when(liveSystem.details().runInNativeCurrency(), () => "not allowed to run live systems in native currency");
                var markets    = list <Market>(liveSystem.markets());
                var symbols    = convert(markets, market => new Symbol(market.name(), market.bigPointValue()));
                var systemId   = liveSystem.id();
                var parameters = new Parameters {
                    { "systemId", systemId },
                    { "RunMode", (double)RunMode.LIVE }
                };
                Bomb.when(isEmpty(symbols), () => "No markets for " + systemId);
                var systemArguments = new SystemArguments(symbols, parameters);

                var start = date(systemArguments.interval().isDaily() ? BloombergSecurity.BBG_START_HISTORICAL : BloombergSecurity.BBG_START_INTRADAY);
                if (parameters.has("DaysBack"))
                {
                    start = now().AddDays(-parameters.get <int>("DaysBack"));
                }
                var loader    = new SystemDbBarLoader(liveSystem.details().interval(), symbols, start);
                var simulator = new Simulator(systemArguments, loader, prefix);
                simulator.processBars();
                simulator.goLive();
            });
            sleep(Int32.MaxValue);
        }
Example #5
0
        public void testNBarFade()
        {
            O.freezeNow("2009/03/10");
            var symbol = new Symbol("RE.TEST.TY.1C", 1000);
            var args   = new SystemArguments(symbol, new Parameters {
                { "systemId", 133486 },
                { "RunMode", (double)RunMode.RIGHTEDGE },
                { "LeadBars", 50 },
                { "ATRLen", 5 },
                { "nDays", 6 },
                { "nATRentry", 1.5 },
                { "exitATRmultiple", 1 },
                { "stopAfStep", 0.02 },
                { "stopAfMax", 0.2 },
                { "entryBarWindow", 2 },
                { "closeBetter", 1 },
                { "riskDollars", 100000000 }
            });
            var loader    = new SystemDbBarLoader(Interval.DAILY, O.list(symbol), date("2003/01/01"));
            var simulator = new Simulator(args, loader, OrderTable.prefix);

            simulator.processBars();
        }