コード例 #1
0
 public bool DisplayLine()
 {
     if (ChartValues.Any() && OptimizerDone)
     {
         return(true);
     }
     return(false);
 }
コード例 #2
0
        private void AddNewPrices(ChartValues <OrderBookPriceLevel> cv, List <OrderBookPriceLevel> pl)
        {
            var newPoints = pl.Where(p => !cv.Any(v => v.Price == p.Price)).ToList();

            var newPointsCount = newPoints.Count;

            if (newPointsCount.Equals(0))
            {
                return;
            }

            var chartValueCount = cv.Count;

            int currentNewPoint = 0;

            for (int i = 0; i < chartValueCount; i++)
            {
                if (newPoints[currentNewPoint].Price < cv[i].Price)
                {
                    cv.Insert(i, newPoints[currentNewPoint]);

                    // Increments
                    currentNewPoint++;  // position in new points list
                    chartValueCount++;  // number of items in the cv list after the insert
                }

                if (currentNewPoint > (newPointsCount - 1))
                {
                    // No more new points to add so break out
                    break;
                }

                if (i == chartValueCount - 1)
                {
                    // We have reached the end of the chart values
                    if (currentNewPoint < newPointsCount)
                    {
                        // Add the remaining new points
                        var appendNewPoints = newPoints.Skip(currentNewPoint).ToList();
                        cv.AddRange(appendNewPoints);
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Identify and missing data points and add a new ZERO datapoint using the appropriate datetime
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        private ChartValues <DateTimePoint> GetListAllDates(ChartValues <DateTimePoint> list)
        {
            DateTime tmpInterval = RoundDown(DateTime.UtcNow.ToLocalTime().Subtract(TimeSpan.FromDays(datePointTimeWindow - datePointTimeIntervalDays)), TimeSpan.FromDays(datePointTimeIntervalDays));
            var      upperBound  = DateTime.UtcNow.ToLocalTime();

            while (tmpInterval <= upperBound)
            {
                if (list.Any(x => RoundDown(x.DateTime, TimeSpan.FromDays(datePointTimeIntervalDays)) == tmpInterval) == false)
                {
                    DateTimePoint dateTimePoint = new DateTimePoint
                    {
                        Value    = 0,
                        DateTime = tmpInterval
                    };
                    list.Add(dateTimePoint);
                }
                tmpInterval = tmpInterval.Add(TimeSpan.FromDays(datePointTimeIntervalDays));
            }
            ;

            return(list);
        }
コード例 #4
0
        public double Objective(double[] x)
        {
            //Debug.WriteLine("Obj");
            //x.ToList().ForEach(i => Debug.WriteLine(i.ToString()));

            DateTime start_iteration = DateTime.Now;

            bool finished = false;

            Grasshopper.Kernel.GH_SolutionMode refresh = Grasshopper.Kernel.GH_SolutionMode.Silent;

            if (this.RadicalVM.Mode == RefreshMode.Live)
            {
                refresh = Grasshopper.Kernel.GH_SolutionMode.Default;
            }

            System.Action run = delegate()
            {
                //Turn off all components not needed for gradient calculation and stepping
                Grasshopper.Instances.ActiveCanvas.Document.SetEnabledFlags(Disable, false);

                //set other inactive objects expired flags to false
                foreach (IGH_ActiveObject a in this.SetExpiredFalse)
                {
                    a.ExpireSolution(false);
                }

                for (int i = 0; i < nVars; i++)
                {
                    IVariable var = Design.ActiveVariables[i]; // ONLY INCL. VARS
                    var.UpdateValue(x[i]);
                }
                // Once all points have been updated, we can update the geometries
                foreach (IDesignGeometry geo in this.Design.Geometries)
                {
                    geo.Update();
                }

                if (this.Design.Geometries.Any())
                {
                    Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true, refresh);
                }
                else
                {
                    Grasshopper.Instances.ActiveCanvas.Document.NewSolution(false, refresh);
                }

                // this.SolutionInProcess = true;
                finished = true;
            };
            Rhino.RhinoApp.MainApplicationWindow.Invoke(run);

            // inelegant, temporary
            while (!finished)
            {
                Thread.Sleep(1);
            }

            double objective = Design.Objectives[0];

            //When a new global objective minimum is reached all variable values at that point are recorded
            //if constraints are computed after the objective then this might be why our return to optimal solution guy does not work ...
            if (objective < this.RadicalVM.SmallestObjectiveValue && AllConstraintsSatisfied())
            {
                this.RadicalVM.SmallestObjectiveValue = objective;
                foreach (VarVM v in this.RadicalVM.NumVars)
                {
                    v.UpdateBestSolutionValue();
                }
                foreach (List <VarVM> lvm in this.RadicalVM.GeoVars)
                {
                    foreach (VarVM v in lvm)
                    {
                        v.UpdateBestSolutionValue();
                    }
                }
            }

            //store evolution of number variables
            for (int i = 0; i < this.RadicalVM.NumVarEvolution.Count; i++)
            {
                this.RadicalVM.NumVarEvolution[i].Add(Design.ActiveVariables[i].CurrentValue);
            }

            //If RefreshMode == Silent then values are stored in a local list so that the graph is not updated
            if (this.RadicalVM.Mode == RefreshMode.Silent)
            {
                this.StoredMainValues.Add(objective);

                for (int i = 0; i < this.RadicalVM.ConstraintsEvolution.Count; i++)
                {
                    double score = Design.Constraints[i].CurrentValue;
                    this.StoredConstraintValues[i].Add(score);
                }
            }
            else
            {
                this.RadicalVM.UpdateCurrentScoreDisplay();

                //If refresh mode is switched from Silent to Live
                if (StoredMainValues.Any())
                {
                    AppendStoredValues();
                    this.RadicalVM.AutomateStepSize(true);
                }

                //Checks to see if # of iterations is = number of original steps in graph, if it is it will make it auto
                this.RadicalVM.AutomateStepSize(false);

                //Adds main objective values to list and draws
                this.RadicalVM.ObjectiveEvolution.Add(objective);

                for (int i = 0; i < this.RadicalVM.ConstraintsEvolution.Count; i++)
                {
                    double score = Design.Constraints[i].CurrentValue;
                    this.RadicalVM.ConstraintsEvolution[i].Add(score);
                }

                foreach (GraphVM gvm in this.RadicalVM.ActiveGraphs)
                {
                    gvm.ForceGraphUpdate();
                }
            }

            try
            {
                this.RadicalWindow.source.Token.ThrowIfCancellationRequested();
            }
            catch
            {
                bool          final_refresh_done = false;
                System.Action lastrun            = delegate()
                {
                    //turn disabled guys back on
                    Grasshopper.Instances.ActiveCanvas.Document.SetEnabledFlags(Disable, true);
                    Grasshopper.Instances.ActiveCanvas.Document.NewSolution(false);
                    final_refresh_done = true;
                };
                Rhino.RhinoApp.MainApplicationWindow.Invoke(lastrun);

                while (!final_refresh_done)
                {
                }

                if (this.RadicalVM.Mode == RefreshMode.Silent)
                {
                    EndSilentMode();
                }

                throw new OperationCanceledException();
            }

            DateTime end_iteration = DateTime.Now;

            if ((this.StoredMainValues.Count + this.RadicalVM.ObjectiveEvolution.Count) % 10 == 0)
            {
                this.RadicalVM.TimeEvolution.Add(end_iteration - start_iteration);
            }
            else
            {
                this.RadicalVM.TimeEvolution.Add(new TimeSpan(0, 0, -10));
            }

            return(objective);
        }
コード例 #5
0
ファイル: OrderBook.cs プロジェクト: lulzzz/tradeview
        public void UpdateChartValues(ChartValues <OrderBookPriceLevel> cv, List <OrderBookPriceLevel> pl, bool isAsk)
        {
            Func <OrderBookPriceLevel, OrderBookPriceLevel, OrderBookPriceLevel> f = ((p, n) =>
            {
                p.Quantity = n.Quantity;
                return(p);
            });

            var removePoints = cv.Where(v => !pl.Any(p => p.Price == v.Price)).ToList();

            foreach (var point in removePoints)
            {
                cv.Remove(point);
            }

            (from v in cv
             join p in pl
             on v.Price equals p.Price
             select f(v, p)).ToList();

            var addPoints   = pl.Where(p => !cv.Any(v => v.Price == p.Price)).ToList();
            var appendRange = new List <OrderBookPriceLevel>();

            foreach (var point in addPoints)
            {
                for (int i = 0; i < cv.Count; i++)
                {
                    if (isAsk)
                    {
                        if (point.Price < cv[i].Price)
                        {
                            cv.Insert(i, point);
                            break;
                        }
                    }
                    else
                    {
                        if (point.Price > cv[i].Price)
                        {
                            cv.Insert(i, point);
                            break;
                        }
                    }

                    if (i == cv.Count - 1)
                    {
                        appendRange.Add(point);
                    }
                }
            }

            if (appendRange.Any())
            {
                if (isAsk)
                {
                    cv.AddRange(appendRange.OrderBy(p => p.Price));
                }
                else
                {
                    cv.AddRange(appendRange.OrderByDescending(p => p.Price));
                }
            }
        }