示例#1
0
        /// <summary>
        /// Calculates all the buys and sells against the dataset.
        /// </summary>
        /// <param name="indicatorLibraryAdapter">Moves through each row of the indicatorLibraryAdapter to find the buy and sell points.</param>
        public void RunBacktest(TestData indicatorLibraryAdapter, Dictionary <DateTime, Dictionary <string, double> > ILA)
        {
            TradeCondition newbuyCondition = tradeSystem.BuyCondition;

            indicatorLibraryAdapter.Restart();
            DatePoint point = indicatorLibraryAdapter.GetStockPoint();

            do
            {
                if (newbuyCondition.Eval(ILA, point))
                {
                    occurance.Add(indicatorLibraryAdapter.GetStockPoint().PointDateTime);
                }
                point = indicatorLibraryAdapter.GetStockPoint();
            } while (indicatorLibraryAdapter.MoveNext());
        }
示例#2
0
        /// <summary>
        /// Creates a new instance of the chromosome with the same values.
        /// </summary>
        /// <returns>A new instance of the chromosome with the same values.</returns>
        internal TradeSystemChromosome Clone()
        {
            TradeCondition nBuy = new TradeCondition();

            nBuy = this.ChromosomeValue.BuyCondition.Clone();
            TradeSystemChromosome tc = new TradeSystemChromosome(
                new TradeSystem(
                    nBuy),
                this.indicatorHelper,
                this.size);

            tc.Capital        = this.Capital;
            tc.FitnessLosers  = this.FitnessLosers;
            tc.FitnessWinners = this.FitnessWinners;
            tc.Fitness        = this.Fitness;
            tc.UniqueID       = this.UniqueID;
            tc.TradeTable     = this.TradeTable;
            return(tc);
        }
示例#3
0
        private void LoadModel_Click(object sender, EventArgs e)
        {
            try
            {
                using (OpenFileDialog openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.InitialDirectory = ".";
                    openFileDialog.Filter           = "XML Files|*.xml";
                    openFileDialog.RestoreDirectory = true;
                    openFileDialog.Title            = "Load Buy Conditions";
                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        Stream newStream;

                        if ((newStream = openFileDialog.OpenFile()) != null)
                        {
                            System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(TradeCondition));
                            System.IO.StreamReader file = new System.IO.StreamReader(@openFileDialog.FileName);
                            condition = new TradeCondition();
                            condition = (TradeCondition)reader.Deserialize(file);
                            //BuyConditionControl.SetControlsToCondition(condition);
                        }
                        newStream.Close();
                    }
                }
            }


            catch
            {
                MessageBox.Show("Trade Conditions have not been saved yet");
            }

            this.LoadBox.Text      = "Data Upload Complete";
            this.LoadBox.BackColor = Color.Blue;
        }
示例#4
0
 private void RunGAButton_Click(object sender, EventArgs e)
 {
     this.progressBar2.Value = 0;
     this.bestResults.Clear();
     this.generationalBest.Clear();
     if (TDD != null)
     {
         this.Cursor         = Cursors.WaitCursor;
         this.StopGA.Enabled = true;
         //BackgroundWorker BGWkr = new BackgroundWorker();
         //DoWorkEventArgs eve = new DoWorkEventArgs(sender);
         //this.testData.Restart();
         TradeCondition        newBCond      = new TradeCondition();
         IndicatorHelper       list          = new IndicatorHelper(this.testData.IndicatorLocations.Keys.ToArray <string>());
         IGeneticMutating      mutant        = new TradeConditionMutation((double)this.MutationRate.Value, list);
         TradeSystem           newSys        = new TradeSystem(newBCond);
         TradeSystemChromosome newchromosome = new TradeSystemChromosome(newSys, list, (int)this.ChromosomeSize.Value);
         IGeneticBreeding      newBreed      = new RandomMultipleSplitBreeding();
         FitnessTest           fitTest       = new FitnessTest((int)ThresholdValue.Value, (string)timeRange.SelectedValue);
         IGeneticFitness       newFitness    = new BacktestFitness(this.testData, TDD, errorData, fitTest);
         this.geneticAlgorithm = new GeneticAlgorithm((int)this.Chromosomes.Value, (int)this.NoGenerations.Value, (int)this.ChromosomeSize.Value, newSys, list, newBreed, mutant, newFitness);
         this.backgroundWorkerRunGA.RunWorkerAsync(this.geneticAlgorithm);
     }
 }