/// <summary> /// Log a packet from the graph /// </summary> /// <param name="tag">A textual tag for the frame</param> /// <param name="color">The color to display the frame (if applicable)</param> /// <param name="frame">The frame to log, note this must be cloned to preserve its value</param> /// <param name="logAsBytes">Indicates whether the packet should be logged as a byte array</param> private void OnLogPacket(string tag, ColorValue color, DataFrame frame, bool logAsBytes) { EventHandler <LogPacketEventArgs> logPacketEvent = LogPacketEvent; if (logPacketEvent != null) { DataFrame logFrame = logAsBytes ? new ByteArrayDataFrame(frame.ToArray()) : frame.Clone(); logPacketEvent(this, new LogPacketEventArgs(tag, Uuid, logFrame, color, NetworkDescription)); } }
public void AddPositon(PositionFormulas position) { // adds the position to the position list. // adds the positon to the list of positions. this.positions.Add(position); // append the position.GetDailyValuation to the PortfolioTable initially. // then every table appended after that is added on. DataFrame positionValuation = position.GetDailyValuation(); if (this.PortfolioTable.Columns.Count == 0) { this.PortfolioTable = positionValuation.Clone(); } else { // If the portfolio already contains securities then add a new column int numberOfRows = this.PortfolioTable.Rows.Count(); string NewColName = $"{position.symbol}_MarketValue"; PrimitiveDataFrameColumn <decimal> newCol = new PrimitiveDataFrameColumn <decimal>(NewColName, numberOfRows); this.PortfolioTable.Columns.Add(newCol); int dateCol = 0; int secondaryRow = 0; int newColIndex = PortfolioTable.Columns.Count - 1; for (int row = 0; row < numberOfRows; row++) { if (secondaryRow == positionValuation.Rows.Count) { break; } if (this.PortfolioTable[row, dateCol].Equals(positionValuation[secondaryRow, dateCol])) { // if the dates between the tables match then assign the positions valuation at that date to the Portfolios Table this.PortfolioTable[row, newColIndex] = positionValuation[secondaryRow, 1]; secondaryRow++; } else { this.PortfolioTable[row, newColIndex] = Decimal.Zero; } } } }
/// <summary> /// Internal write function /// </summary> /// <param name="frame">The frame to write</param> /// <param name="nodes">The list of nodes to write to</param> private void WriteOutput(DataFrame frame, OutputNode[] nodes) { try { // Leave this like it is for legacy reasons. if (frame == null) { foreach (OutputNode node in nodes) { node.Node.Shutdown(this); } } else { _outputPacketCount++; _byteCount += frame.Length; if (LogOutput) { LogPacket(String.Format("{0} Output", Name), new ColorValue(255, 255, 255), frame, false); } if (nodes.Length == 1) { // If we only have one output then don't need to clone nodes[0].Node.Input(frame); } else { foreach (OutputNode node in nodes) { DataFrame newFrame = frame.Clone(); node.Node.Input(newFrame); } } } } catch (Exception ex) { // Back stop, do nothing but write to log LogException(ex); } }