private void button2_Click(object sender, EventArgs e)
        {
            this.button2.Visible = false;
            this.button1.Visible = true;

            this.Simulation.Stop();

            this.Simulation.ProgressReported -= this.ProcessProgressReport;

            int ii = 0;

            while (this.Simulation.done == false)
            {
                Thread.Sleep(1000);

                ii++;

                if (ii == 20)
                {
                    DisplayLog("Simulation failed to stop within 20 seconds.");
                    return;
                }
            }

            SPY_History.SerializeClassToFile <SPY_Simulation>(this.dir, this.Simulation);
        }
        public SPY_Simulation(int NumberOfValues, int NumberOfVariables, int NumberOfTasks, int StartRangeAt, long DailyBuy, SPY_History SPYHistory)
        {
            // SET SIMULATION PARAMETERS

            this.CE = new Counting_Engine(NumberOfValues, NumberOfVariables);

            SPYHistory.Filter_Data(SPYHistory.Trading_Days.Count - YearsToTradingDays(43));  // SIMULATION CURRENTLY TRIMS THE DATA DOWN THE LAST 43 YEARS
                                                                                             // -> SOMEONE WHO STARTED INVESTING AT 22 AND IS RETIRING AT 65

            this.SPY = SPYHistory;

            this.numberoftasks = NumberOfTasks;

            this.numberofvalues = NumberOfValues;

            this.numberofvariables = NumberOfVariables;

            this.startRange = StartRangeAt;

            this.CalculateIncrementer();

            this.dailyBuy = DailyBuy * 100;

            this.dailyBuyPrecision = this.dailyBuy * 10000;

            this.sale = this.GrabSale();

            this.potCap = (this.dailyBuy * (YearsToTradingDays(1) / 4));  // POT CAP IS SET TO ONE FISCAL QUARTER'S WORTH OF BUYS

            this.countCap = Counting_Engine.ToPower(this.numberofvalues, this.numberofvariables);

            this.Results = new List <SPY_Simulation_Result>();

            this.progress = 0;
        }
        private void StartNewSim()
        {
            this.Simulation = new SPY_Simulation(11, 8, 6, 50, 10, SPY_History.DeserializeFromJSONFile(this.file));

            this.Simulation.ProgressReported += this.ProcessProgressReport;

            this.Simulation.Run();
        }
        static void Main(string[] args)
        {
            string dir = DirectoryFinder.GrabDir(args);

            string jsonFile = DirectoryValidator.DirectoryValidator.getfilename(dir, ".json");

            SPY_Simulation spy_sim = new SPY_Simulation(11, 8, 6, 50, 10, SPY_History.DeserializeFromJSONFile(jsonFile));

            Console.WriteLine("COMPLETE:");

            string dump = Console.ReadLine();

            File.WriteAllText((dir + "\\" + DateTime.UtcNow.ToString("MM_dd_yyyy_HH_mm_ss") + "_" + dump + ".json"), JsonConvert.SerializeObject(spy_sim));
        }