Esempio n. 1
0
        public void PaintX2(int j)
        {
            ChartValues <double> valueChart = new ChartValues <double>();
            ChartValues <double> test       = new ChartValues <double>();

            for (int i = 0; i < 20; i++)
            {
                valueChart.Add(Math.Sin(i * i * j));
                test.Add(Math.Cos(i));
            }

            ValueAsset = new SeriesCollection
            {
                new LineSeries
                {
                    Title     = "Serie 1",
                    Values    = valueChart,
                    ScalesYAt = 0
                }
            };


            if (GeneralSetting.MovingAverageList.Count != 0) // If there is some Moving average ...
            {
                for (int i = 0; i < GeneralSetting.MovingAverageList.Count; i++)
                {
                    int period = GeneralSetting.MovingAverageList[i].Period;
                    if (period < valueChart.Count)
                    {
                        ChartValues <double> valueChartMovingAverageTemp = new ChartValues <double>();
                        // because for the beginning sma is equal to value chart until we can compute the average
                        for (int k = 0; k < period; k++)
                        {
                            valueChartMovingAverageTemp.Add(valueChart[k]);
                        }
                        // compute average for the rest of data
                        for (int k = period; k < valueChart.Count; k++)
                        {
                            valueChartMovingAverageTemp.Add(valueChart.Skip(k).Take(period).Sum() / period);
                        }

                        // adding sma
                        ValueAsset.Add(new LineSeries
                        {
                            Title  = "SMA" + period,
                            Values = valueChartMovingAverageTemp,
                            Fill   = System.Windows.Media.Brushes.Transparent
                        });
                    }
                }
            }

            if (GeneralSetting.isBollingerBands)
            {
                ChartValues <double> bollingerAverage = new ChartValues <double>();
                int period = GeneralSetting.BollingerBand.Period;
                for (int k = 0; k < period; k++)
                {
                    bollingerAverage.Add(valueChart[k]);
                }
                // compute average for the rest of data
                for (int k = period; k < valueChart.Count; k++)
                {
                    bollingerAverage.Add(valueChart.Skip(k).Take(period).Sum() / period);
                }


                ChartValues <double> bollingerTop = new ChartValues <double>();
                for (int i = 1; i < bollingerAverage.Count; i++)
                {
                    double result = bollingerAverage[i] + StandardDeviation(bollingerAverage.Take(i).ToList(), bollingerAverage.Take(i).Count());
                    bollingerTop.Add(result);
                }

                ChartValues <double> bollingerDown = new ChartValues <double>();
                for (int i = 1; i < bollingerAverage.Count; i++)
                {
                    double result = bollingerAverage[i] - StandardDeviation(bollingerAverage.Take(i).ToList(), bollingerAverage.Take(i).Count());
                    bollingerDown.Add(result);
                }


                ValueAsset.Add(new LineSeries
                {
                    Title  = "BollingerAverage",
                    Values = bollingerAverage,
                    Stroke = Brushes.Green,
                    Fill   = System.Windows.Media.Brushes.Transparent
                });

                ValueAsset.Add(new LineSeries
                {
                    Title  = "BollingerTop",
                    Values = bollingerTop,
                    Stroke = Brushes.Green,
                    Fill   = System.Windows.Media.Brushes.Transparent
                });

                ValueAsset.Add(new LineSeries
                {
                    Title  = "BollingerDown",
                    Values = bollingerDown,
                    Stroke = Brushes.Green,
                    Fill   = System.Windows.Media.Brushes.Transparent
                });
            }
        }
        public void PopulateChartPrice(string ticker)
        {
            // Get historical data
            List <Object> result = bbH.GetPriceVolumeValue(ticker, null, "20180101", "20180220");
            List <double> price  = (List <double>)result[1];

            ChartValues <double> valueChart = new ChartValues <double>();

            for (int i = 0; i < price.Count; i++)
            {
                valueChart.Add(price[i]);
            }

            // Compute Volatility
            ChartValues <double> valueVolatility = new ChartValues <double>();
            double V0 = price[0];

            for (int i = 0; i < price.Count; i++)
            {
                double Vt = price[i];
                valueVolatility.Add(((Vt / V0) - 1) * 100); // peut etre *100 à voir selon le résultat
            }

            NameAsset = ticker;

            // Compute Performance
            ChartValues <double> valuePerformance = new ChartValues <double>();

            for (int i = 0; i < price.Count; i++)
            {
                double resultPerf = PopulationStandardDeviation(valueVolatility.Take(i).ToList());
                valuePerformance.Add(resultPerf);
            }


            AssetValue = new SeriesCollection
            {
                new LineSeries
                {
                    Title  = "Asset Value",
                    Values = valueChart
                }
            };

            AssetValuePerformance = new SeriesCollection
            {
                new LineSeries
                {
                    Title  = "Performance",
                    Values = valuePerformance
                }
            };

            AssetValueVolatility = new SeriesCollection
            {
                new LineSeries
                {
                    Title  = "Volatility",
                    Values = valueVolatility
                }
            };


            // Here for AssetReaserch
            AssetResarch.ValuePerformance = valuePerformance.ToList();
            AssetResarch.Value            = valueChart.ToList();
            AssetResarch.ValueVolatility  = valueVolatility.ToList();
        }