Exemplo n.º 1
0
        /// <summary>
        /// Add alog results to the the graph
        /// </summary>
        /// <param name="algorithmResults"></param>
        private void graphResults(IAlogorithm algorithmResults)
        {
            //Create a unique name
            string symbolName = algorithmResults.Symbol;

            if (Chart.Series.IsUniqueName(symbolName) == false)
            {
                symbolName = symbolName + "_" + DateTime.Now.Second.ToString();
            }

            //Create a new series and add to the chart
            Series series = new Series()
            {
                Name      = symbolName,
                ChartType = SeriesChartType.Line
            };

            Chart.Series.Add(series);


            //Add equity over time results to the graph
            foreach (KeyValuePair <DateTime, decimal> equity in algorithmResults.Broker.EquityOverTime)
            {
                Chart.Series[symbolName].Points.AddXY(equity.Key, equity.Value);
            }

            //Add summary report to collection for the grid
            //Update the symbol name in the report - avoiding duplicates
            algorithmResults.SummaryReport.Symbol = symbolName;
            _algorithmSummaryReports.Add(algorithmResults.SummaryReport);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loops the stocks and run the default alogorithm
        /// </summary>
        private void runAlgorithm(Type defaultAlgoType, string symbols, bool buyAndHold)
        {
            if (string.IsNullOrEmpty(symbols))
            {
                return;
            }

            //Loops the stocks and run the alogo
            string[] symbolsCollection = symbols.Split(' ');

            foreach (var symbol in symbolsCollection)
            {
                Application.DoEvents();
                IAlogorithm algo = Activator.CreateInstance(defaultAlgoType) as IAlogorithm;
                algo.Initialize(symbol, buyAndHold);
                graphResults(algo);
            }

            #region Parallel method for processing
            //Parallel.ForEach(symbolsCollection, symbol =>
            //{
            //    IAlogorithm algo = Activator.CreateInstance(_defaultAlgoType) as IAlogorithm;
            //    algo.Initialize(symbol, buyAndHold);

            //    graphResults(algo);
            //    // Console.WriteLine("{0}, Thread Id= {1}", symbol, Thread.CurrentThread.ManagedThreadId);
            //});
            #endregion
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loops the stocks and run the default alogorithm
        /// </summary>
        private static void runAlgorithm(string symbols, bool buyAndHold)
        {
            if (string.IsNullOrEmpty(symbols))
            {
                return;
            }

            //Loops the stocks and run the alogo
            string[] symbolsCollection = symbols.Split(' ');

            //Parallel method for processing
            Parallel.ForEach(symbolsCollection, symbol =>
            {
                IAlogorithm algo = Activator.CreateInstance(_defaultAlgoType) as IAlogorithm;
                algo.Initialize(symbol, buyAndHold);

                //_graphForm.GraphResults(algo.Symbol, algo.Broker.EquityOverTime);

                // Console.WriteLine("{0}, Thread Id= {1}", symbol, Thread.CurrentThread.ManagedThreadId);
            });
        }