Пример #1
0
 public LiveWatcher(WatcherGui gui)
 {
     this.gui = gui;
     table    = new QDataTable {
         { "tag", typeof(string) },
         { "symbol", typeof(string) },
         { "tomahawk", typeof(double) },
         { "aim", typeof(double) },
         { "diff", typeof(double) },
         { "symbolHIDDEN", typeof(Symbol) }
     };
     table.filter(row => {
         var visible = true;
         if (filterZeroes)
         {
             visible = (double)row["aim"] != 0 || (double)row["tomahawk"] != 0;
         }
         if (!showHidden_)
         {
             visible &= !isExcludedByTag.get((string)row["tag"]);
         }
         if (!tagFilter.Equals("ALL"))
         {
             visible &= row["tag"].Equals(tagFilter);
         }
         return(visible);
     });
 }
Пример #2
0
        void addRunInfoTab(SystemRunInfo info, ItemsControl charts)
        {
            var parametersGrid = new QDataTableGrid();

            charts.Items.Add(new DockableContent {
                Title = title("RunInfo"), Content = parametersGrid
            });
            var parametersTable = new QDataTable {
                { "name", typeof(string) },
                { "value", typeof(string) }
            };
            Action <string, string> addRow = (name, value) => {
                var row = parametersTable.NewRow();
                row["name"]  = name;
                row["value"] = value;
                parametersTable.add(row);
            };

            Objects.each(info.parameters, name => addRow(name, info.parameters.get <string>(name)));
            addRow("", "");
            addRow("start date", Objects.ymdHuman(info.startDate, ""));
            addRow("end date", Objects.ymdHuman(info.endDate, ""));
            addRow("slippage calculator", info.slippageCalculatorName);
            addRow("run in native currency", info.runInNativeCurrency + "");
            parametersGrid.populateFromDataTable(parametersTable);
        }
Пример #3
0
 void addFilteredHistogram <T>(ItemsControl positionsPane, QDataTable table, string titleText, T tradePath) where T : System.Windows.Forms.Control, FilteredPositionsPlot
 {
     positionsPane.Items.Add(new DockableContent {
         Title = title(titleText), Content = new WindowsFormsHost {
             Child = tradePath
         }
     });
     table.filterChanged += rows => tradePath.updatePlot(Objects.convert(rows, row => (Position)row["positionHIDDEN"]));
 }
Пример #4
0
        public QDataTable makeDataTable()
        {
            var columns = Objects.list("open", "high", "low", "close");

            eachPane(pane => columns.AddRange(pane.names));
            columns.Add("equity");
            Bomb.unlessNull(dataTable_, () => "lazy early? wierd");
            dataTable_ = new QDataTable {
                { "time", typeof(DateTime) }
            };
            Objects.each(columns, c => dataTable_.Add(c, typeof(double)));
            Objects.eachIt(barSpud, addRow);
            return(dataTable_);
        }
Пример #5
0
        void addRow(string metric, QDataTable result)
        {
            var row = result.NewRow();

            row["Metric"] = metric;
            foreach (var column in result.columns())
            {
                var columnName = column.ColumnName;
                if (columnName.Equals("Metric"))
                {
                    continue;
                }
                row[column] = this[columnName.Replace("_", ".")][metric];
            }
            result.add(row);
        }
Пример #6
0
        void addTradesTab(Simulator simulator, ItemsControl charts, IEnumerable <Trade> trades)
        {
            var dataGrid = new QDataTableGrid();
            var table    = new QDataTable {
                { "symbol", typeof(string) },
                { "time", typeof(DateTime) },
                { "description", typeof(string) },
                { "direction", typeof(string) },
                { "size", typeof(int) },
                { "price", typeof(double) },
                { "details", typeof(string) },
                { "fxRate", typeof(double) }
            };
            var panel = new QDockPanel();

            charts.Items.Add(new DockableContent {
                Title = title("Trades"), Content = panel
            });
            var controlGrid = new QGrid();

            controlGrid.addColumns(2);
            controlGrid.add(withLabel("S_ymbol", new QComboBox("ALL", selected => table.filter("symbol", selected), markets())), 0);
            controlGrid.add(withLabel("_Direction", new QComboBox("ALL", selected => table.filter("direction", selected), Objects.list("buy", "sell"))), 1);
            panel.add(controlGrid, Dock.Top);
            panel.add(dataGrid, Dock.Bottom);
            Converter <Trade, DataRow> newTradeRow = trade => {
                var row = table.NewRow();
                row["symbol"]      = trade.order().symbol.name;
                row["time"]        = trade.time;
                row["description"] = trade.description;
                row["direction"]   = trade.direction.longShort("buy", "sell");
                row["size"]        = trade.size;
                row["price"]       = trade.price;
                row["details"]     = "        " + trade.order().details;
                row["fxRate"]      = trade.fxRate;
                return(row);
            };

            Objects.each(Objects.reverse(trades), trade => table.add(newTradeRow(trade)));
            dataGrid.populateFromDataTable(table);
            dataGrid.AutoGeneratedColumns += rightJustifyColumns;
            simulator.addNewTradeListener((position, trade) => runOnGuiThread(() => table.addAtStart(newTradeRow(trade))));
        }
Пример #7
0
        public DataTable table()
        {
            var result = new QDataTable();

            result.addTypedColumn("Metric", typeof(string));
            O.each(O.sort(Keys, (a, b) => {
                if (a.Equals(b))
                {
                    return(0);
                }
                if (a.Equals("ALL"))
                {
                    return(-1);
                }
                return(b.Equals("ALL") ? 1 : a.CompareTo(b));
            }), symbol => result.addTypedColumn(symbol.Replace(".", "_"), typeof(double)));
            var example = O.first(Values);

            O.each(O.sort(example.Keys), metric => addRow(metric, result));
            return(result);
        }
Пример #8
0
        void addPositionsTab(Researcher researcher, ItemsControl charts)
        {
            var simulator     = researcher.simulator;
            var positionsPane = new DockablePane();
            var dataGrid      = new QDataTableGrid();
            var table         = new QDataTable("symbol", "entryTime", "exitTime", "direction")
            {
                { "initialSize", typeof(int) },
                { "pnl", typeof(double) },
                { "barsHeld", typeof(int) },
                { "numTrades", typeof(int) },
                { "positionHIDDEN", typeof(Position) }
            };
            var panel = new QDockPanel();

            positionsPane.Items.Add(new DockableContent {
                Title = title("Position List"), Content = panel
            });
            charts.Items.Add(new DockableContent {
                Title = title("Positions"), Content = positionsPane
            });
            var controlGrid = new QGrid();

            controlGrid.addColumns(3);
            controlGrid.add(withLabel("S_ymbol", new QComboBox("ALL", selected => table.filter("symbol", selected), markets())), 0);
            controlGrid.add(withLabel("_Direction", new QComboBox("ALL", selected => table.filter("direction", selected), Objects.list("long", "short"))), 1);
            controlGrid.add(withLabel("_P&L", new QComboBox("ALL", selected => table.filter <double>("pnl", value => pnlMatchesSelection(selected, value)), Objects.list("winning", "losing"))), 2);
            panel.add(controlGrid, Dock.Top);
            panel.add(dataGrid, Dock.Bottom);

            Action <DataRow, Position> updateRow = (row, position) => {
                row["symbol"]         = position.symbol.name;
                row["entryTime"]      = Objects.ymdHuman(position.entry().time);
                row["exitTime"]       = position.isClosed() ? Objects.ymdHuman(position.exitTrade().time) : "Open";
                row["direction"]      = position.entry().direction.ToString();
                row["initialSize"]    = position.entry().size;
                row["pnl"]            = position.isClosed() ? position.pnl(true, simulator.runInNativeCurrency()) : simulator.pnlForPosition(position);
                row["barsHeld"]       = position.barsHeld();
                row["numTrades"]      = position.trades().Count;
                row["positionHIDDEN"] = position;
            };
            Converter <Position, DataRow> newRow = position => {
                var row = table.NewRow();
                updateRow(row, position);
                return(row);
            };

            Objects.each(Objects.reverse(researcher.positions), position => table.add(newRow(position)));
            dataGrid.populateFromDataTable(table);
            dataGrid.AutoGeneratedColumns += rightJustifyColumns;
            simulator.addNewTradeListener((position, trade) => runOnGuiThread(() => {
                if (position.isEntry(trade))
                {
                    table.addAtStart(newRow(position));
                }
                else
                {
                    updateRow(table.firstRow("positionHIDDEN", position), position);
                }
            }));
            addFilteredHistogram(positionsPane, table, "Average P&L (Bar To End)", new TradePathHistogramControl(researcher, true, true));
            addFilteredHistogram(positionsPane, table, "Cumulative P&L (Bar To End)", new TradePathHistogramControl(researcher, false, true));
            addFilteredHistogram(positionsPane, table, "Average P&L (Start To Bar)", new TradePathHistogramControl(researcher, true, false));
            addFilteredHistogram(positionsPane, table, "Cumulative P&L (Start To Bar)", new TradePathHistogramControl(researcher, false, false));
            addFilteredHistogram(positionsPane, table, "Pnl Distribution", new PositionHistogramControl(researcher, position => position.pnl(true, researcher.simulator.runInNativeCurrency())));
            addFilteredHistogram(positionsPane, table, "Entry Size Distribution", new PositionHistogramControl(researcher, position => Objects.first(position.trades()).size));
            addFilteredHistogram(positionsPane, table, "Bars Held Distribution", new PositionHistogramControl(researcher, position => position.barsHeld()));
        }