Ejemplo n.º 1
0
        /// <summary>
        /// Calculate the RSI for a currency
        /// </summary>
        /// <param name="currencyName">The currency name</param>
        /// <returns>The RSI</returns>
        private double GetCurrencyRSI(string currencyName, int rsiPeriod)
        {
            Int32  endDate   = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
            Int32  startDate = (Int32)(DateTime.UtcNow.AddDays(-rsiPeriod).Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
            string uri       = string.Format("{0}{1}&start={2}&end={3}&period=14400", uriCurrency, currencyName, startDate, endDate);

            string poloniexApiData = GetPoloniexApiData(new Uri(uri));

            if (poloniexApiData != "")
            {
                List <PoloQuoteTransfer> quotationList = JsonConvert.DeserializeObject <List <PoloQuoteTransfer> >(poloniexApiData);
                return(IndicatorHelper.CalculateRsi(rsiPeriod, quotationList.Select(p => p.Close).ToArray()));
            }

            return(0);
        }
Ejemplo n.º 2
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);
     }
 }