/// <summary>
        /// Executes a run of processing the stock data
        /// </summary>
        /// <param name="session">The session configuration</param>
        public static void Run(StockSession session)
        {
            // Create the stock processor
            StockProcessor processor = new StockProcessor(session);

            // Set the change percentages to monitor
            StockDataSink.ChangePercentages = new float[] { -0.025f, -0.05f, -0.10f };

            // Set the evaluator and resulting action
            processor.Evaluator = new PriceEvaluator()
            {
                Percentage      = 0.025f,
                MonitorIncrease = true,
                MonitorDecrease = false,
                ReferencePrices = new Dictionary <string, float>()
                {
                    { "GNTX", 18.0f }
                }
            };
            processor.Action     = new StockAction();
            processor.Action.Do += processor.Action.Notify;

            // Add targets for the stocks to monitor
            processor.Add(new StockProcessor.ProcessingTarget("GNTX"));

            // Run the data through the processor
            processor.Process(false, StockProcessor.MemoryScheme.MEM_KEEP_DERIVED);
        }
 /// <summary>
 /// Buys shares of the stock
 /// </summary>
 /// <param name="processor">The processor triggering the action</param>
 /// <param name="target">The processing target that triggered the action</param>
 /// <param name="time">The time at which the action was triggered</param>
 public void Buy(StockProcessor processor, StockProcessor.ProcessingTarget target, DateTime time)
 {
     Broker.Instance.SubmitOrder(new Broker.Order()
     {
         Symbol   = target.Symbol,
         BuySell  = Broker.Order.BuySellType.BUY,
         Type     = Broker.Order.OrderType.MARKET,
         Quantity = 1
     });
 }
 /// <summary>
 /// Buys shares of the stock
 /// </summary>
 /// <param name="processor">The processor triggering the action</param>
 /// <param name="target">The processing target that triggered the action</param>
 /// <param name="time">The time at which the action was triggered</param>
 public void Sell(StockProcessor processor, StockProcessor.ProcessingTarget target, DateTime time)
 {
     Broker.Instance.GetPositionInfo(target.Symbol, (position) =>
     {
         Broker.Instance.SubmitOrder(new Broker.Order()
         {
             Symbol   = target.Symbol,
             BuySell  = Broker.Order.BuySellType.SELL,
             Type     = Broker.Order.OrderType.MARKET,
             Quantity = position.Shares
         });
     });
 }
        /// <summary>
        /// Returns the stock processor instance, or creates one if there isn't one already
        /// </summary>
        /// <param name="session">The stock session to create the processor for</param>
        /// <returns>The stock processor instance</returns>
        public static StockProcessor GetInstance(StockSession session = null)
        {
            if (Instance == null)
            {
                if (session != null)
                {
                    Instance = new StockProcessor(session);
                }
                else
                {
                    throw new Exception("Must specify the session the first time the processor instance is accessed.");
                }
            }

            return(Instance);
        }
        /// <summary>
        /// Creates a stock data chart
        /// </summary>
        /// <param name="session">The session the chart is a part of</param>
        /// <returns>The chart, as a generic control</returns>
        public static Control CreateChart(StockSession session)
        {
            StockProcessor processor = new StockProcessor(session);

            return((Control)(new DataChartGui <StockDataSink>(processor.DerivedData, session.SinkFile, session)).GuiPanel);
        }
        /// <summary>
        /// Executes a run of processing the stock data
        /// </summary>
        /// <param name="session">The session configuration</param>
        public static void Run(StockSession session)
        {
            // Create the stock processor
            StockProcessor processor = new StockProcessor(session);

            // Get the sizes of the features and labels
            int dstIdx = 0;
            int numDataPoints = 0;
            int numFeatures, numLabels;

            float[,] tmpDst  = new float[1, 1024];
            int[,] tmpLabels = new int[1, 1];
            var tmpDataPoint = processor.DerivedData.First().Value[0];

            tmpDataPoint.Load(session);
            PopulateData(tmpDataPoint, tmpDst, tmpLabels, ref dstIdx, out numFeatures, out numLabels);

            // Determine the total number of data points
            List <string> symbols = new List <string>()
            {
                "GNTX"
            };

            foreach (var s in symbols)
            {
                List <StockDataSet <StockDataSink> > sources;
                if (!processor.DerivedData.TryGetValue(s, out sources))
                {
                    continue;
                }
                for (int i = 0; i < sources.Count; i++)
                {
                    sources[i].Load(session);
                    numDataPoints += sources[i].Count;
                }
            }

            // Allocate the feature and label arrays
            float[,] features = new float[numDataPoints, numFeatures];
            int[,] labels     = new int[numDataPoints, numLabels];

            // Load the data
            dstIdx = 0;
            foreach (var s in symbols)
            {
                List <StockDataSet <StockDataSink> > sources;
                if (!processor.DerivedData.TryGetValue(s, out sources))
                {
                    continue;
                }

                // Create a table of each data point in the specified range
                for (int i = 0; i < sources.Count; i++)
                {
                    sources[i].Load(session);
                    PopulateData(sources[i], features, labels, ref dstIdx, out numFeatures, out numLabels);
                }
            }

            // Create the Machine Learning instance
            MLInstance ml = new MLInstance();

            ml.BuildFullyConnectedGraph(new int[] { numFeatures, numFeatures, numLabels });
            ml.PrepareData(features, labels);
            ml.Train();
        }
 /// <summary>
 /// Buys shares of the stock
 /// </summary>
 /// <param name="processor">The processor triggering the action</param>
 /// <param name="target">The processing target that triggered the action</param>
 /// <param name="time">The time at which the action was triggered</param>
 public void Notify(StockProcessor processor, StockProcessor.ProcessingTarget target, DateTime time)
 {
     StockList.Instance.Add(StockList.NOTIFICATIONS, target.Symbol, new StockList.NotificationSummary(DataAccessor.Subscribe(target.Symbol, DataAccessor.SUBSCRIBE_ONE_SEC)));
 }