// // Abstract: // Update managerVM's attributs. // // Parameters: // theDate: // DateTime where the modeling should be ran. // // estWindow: // String containing the period where the model should be ran. // // frequency: // String containing the step where portefolio is reshuffled. public void PleaseUpdateManager(DateTime theDate, string estmWindow, string frequency, IDataFeedProvider simulator, FinancialComputation opt) { StartDate = theDate; SampleNumber = Int32.Parse(estmWindow); Step = Int32.Parse(frequency); marketSimulator = simulator; option = opt; option.MarketDataDates.Clear(); var window = 20; var res = option.GenChartData(window, StartDate, Step, marketSimulator); ValPayOff = option.PayOff; ValPortfolio = res.PortfolioValue.Last().Value; Labels = GetDateSet(option.MarketDataDates); optp.Clear(); pfp.Clear(); trackingError.Clear(); for (int i = 0; i < res.OptionPrice.Count; i++) { optp.Insert(i, res.OptionPrice[i]); pfp.Insert(i, res.PortfolioValue[i].Value); trackingError.Insert(i, res.OptionPrice[i] - res.PortfolioValue[i].Value); } }
private void SetValues(object sender, EventArgs e) { var values = new ChartValues <DateTimePoint>(); Int_TIME_SERIES_INTRADAY time_series_intraday = _connection.GetQueryObject_TIME_SERIES_INTRADAY(); try { IAvapiResponse_TIME_SERIES_INTRADAY time_series_intradayResponse = time_series_intraday.Query( _args.Symbol, Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_1min, Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_outputsize.compact); var data = time_series_intradayResponse.Data; if (data.Error) { //MessageBox.Show("Failed to fetch data", "Error"); } else { Console.WriteLine("Information: " + data.MetaData.Information); Console.WriteLine("Symbol: " + data.MetaData.Symbol); Console.WriteLine("LastRefreshed: " + data.MetaData.LastRefreshed); Console.WriteLine("Interval: " + data.MetaData.Interval); Console.WriteLine("OutputSize: " + data.MetaData.OutputSize); Console.WriteLine("TimeZone: " + data.MetaData.TimeZone); Console.WriteLine("========================"); Console.WriteLine("========================"); int count = 12; foreach (var timeseries in data.TimeSeries) { if (count <= 0) { break; } Console.WriteLine("open: " + timeseries.open); Console.WriteLine("high: " + timeseries.high); Console.WriteLine("low: " + timeseries.low); Console.WriteLine("close: " + timeseries.close); Console.WriteLine("volume: " + timeseries.volume); Console.WriteLine("DateTime: " + timeseries.DateTime); Console.WriteLine("========================"); values.Insert(0, new DateTimePoint { Value = double.Parse(timeseries.close), DateTime = DateTime.ParseExact(timeseries.DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) }); } LastHourSeries[0].Values = values; } } catch (NullReferenceException) { MessageBox.Show("Failed to send request", "Error"); } }
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); } } } }
private void AnimatedPlot(object sender, EventArgs e) { double y = cpuPerformance.NextValue(); cpuUsageText.Text = string.Format("CPU使用率:{0:0}%", y); if (y > 85) { cpuUsageText.Foreground = red; } else if (y > 70) { cpuUsageText.Foreground = yellow; } else { cpuUsageText.Foreground = green; } double R = Math.Round((double)((ulong)TotalRam - ci.AvailablePhysicalMemory / 1024 / 1024)); double Rp = (R * 100) / TotalRam; ramUsageText.Text = string.Format("内存使用率:{0:0}%\n" + R + "/" + TotalRam + "MB", Rp); if (Rp > 85) { ramUsageText.Foreground = red; } else if (Rp > 70) { ramUsageText.Foreground = yellow; } else { ramUsageText.Foreground = green; } Cpu1.Insert(0, new ObservableValue(Math.Round(y))); Ram1.Insert(0, new ObservableValue(R)); if (Cpu1.Count == 62) { Cpu1.RemoveAt(61); Ram1.RemoveAt(61); } }
private void ShowButtonClicked(object sender, RoutedEventArgs e) { // Clear the chart if it has values already if (Chart.Series != null) { Chart.Series.Clear(); } // Exception control // If date fields are empty if (StartDatePicker.SelectedDate == null || EndDatePicker.SelectedDate == null) { MessageBox.Show("Lütfen tarihleri seçiniz"); return; } // If selected dates aren't possible if (StartDatePicker.SelectedDate >= EndDatePicker.SelectedDate) { MessageBox.Show("Başlangıç tarihi bitiş tarihinden önce olmalı"); return; } DateTime Start = (DateTime)StartDatePicker.SelectedDate; DateTime End = (DateTime)EndDatePicker.SelectedDate; string dateFormat; if (End.Year != Start.Year) { dateFormat = "dd/MM/yyyy"; } else { dateFormat = "dd/MM"; } Chart.Series = new SeriesCollection { }; // Calculate total days between selected dates int TotalDays = (int)(End - Start).TotalDays + 1; // Get selected Products var selectedItems = ProductList.SelectedItems; if (selectedItems.Count == 0) { MessageBox.Show("Lütfen ürün seçiniz"); return; } ChartValues <string> DateLabels = new ChartValues <string>(); // Loop through selected items and draw a line for every item foreach (Product product in selectedItems) { // Create arrays for x and y values of the graph DateTime[] dates = new DateTime[TotalDays]; ChartValues <double> AmountOfProductsSold = new ChartValues <double>(); var context = new MarketDBContext(); // Loop for total days for (int i = 0; i < TotalDays; i++) { DateTime indexDate = Start.AddDays(i); DateTime queryEndDate = indexDate.AddDays(1); dates[i] = indexDate; // List of sales that are between start and end date List <Sale> saleList = context.Sales.Where(s => s.Date >= indexDate && s.Date < queryEndDate).ToList(); if (saleList.Count() > 0) { double amountSum = 0; // Loop through each sale we found foreach (Sale saleItem in saleList) { // Get each product that is related to the sale we are currently looping // Then check if we have the selected product in those related products List <ProductSale> psList = context.ProductSales.Where(s => s.SaleID == saleItem.ID) .Where(ps => ps.ProductID == product.ID).ToList(); if (psList.Count > 0) { amountSum += psList.First().Amount; } } // Insert the sum to the corresponding chartValue AmountOfProductsSold.Insert(i, amountSum); } else { AmountOfProductsSold.Insert(i, 0); } } foreach (DateTime date in dates) { DateLabels.Add(date.ToString(dateFormat)); } // Input data to the chart Chart.Series.Add(new LineSeries { LineSmoothness = 0, Title = product.Name, Values = AmountOfProductsSold }); } // Set date strings to labels on the X axis Chart.AxisX.First().Labels = DateLabels; }
private ChartValues <DateTimePoint> GetData() { var values = new ChartValues <DateTimePoint>(); //_backgroindWork = Task.Factory.StartNew(() => // { // Int_TIME_SERIES_INTRADAY time_series_intraday = // _connection.GetQueryObject_TIME_SERIES_INTRADAY(); // IAvapiResponse_TIME_SERIES_INTRADAY time_series_intradayResponse = // time_series_intraday.Query( // _args.Symbol, // Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_1min, // Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_outputsize.compact); // var data = time_series_intradayResponse.Data; // if (data.Error) // { // MessageBox.Show("Failed to fetch data", "Error"); // } // else // { // Console.WriteLine("Information: " + data.MetaData.Information); // Console.WriteLine("Symbol: " + data.MetaData.Symbol); // Console.WriteLine("LastRefreshed: " + data.MetaData.LastRefreshed); // Console.WriteLine("Interval: " + data.MetaData.Interval); // Console.WriteLine("OutputSize: " + data.MetaData.OutputSize); // Console.WriteLine("TimeZone: " + data.MetaData.TimeZone); // Console.WriteLine("========================"); // Console.WriteLine("========================"); // foreach (var timeseries in data.TimeSeries) // { // //Console.WriteLine("open: " + timeseries.open); // //Console.WriteLine("high: " + timeseries.high); // //Console.WriteLine("low: " + timeseries.low); // //Console.WriteLine("close: " + timeseries.close); // //Console.WriteLine("volume: " + timeseries.volume); // //Console.WriteLine("DateTime: " + timeseries.DateTime); // //Console.WriteLine("========================"); // values.Insert(0, new DateModel // { // Value = double.Parse(timeseries.close), // DateTime = DateTime.ParseExact(timeseries.DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) // }); // } // } // } // ,TaskCreationOptions.LongRunning //); //Dispatcher.BeginInvoke(new Action(()=> // { // Int_TIME_SERIES_INTRADAY time_series_intraday = // _connection.GetQueryObject_TIME_SERIES_INTRADAY(); // IAvapiResponse_TIME_SERIES_INTRADAY time_series_intradayResponse = // time_series_intraday.Query( // _args.Symbol, // Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_1min, // Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_outputsize.compact); // var data = time_series_intradayResponse.Data; // if (data.Error) // { // MessageBox.Show("Failed to fetch data", "Error"); // } // else // { // Console.WriteLine("Information: " + data.MetaData.Information); // Console.WriteLine("Symbol: " + data.MetaData.Symbol); // Console.WriteLine("LastRefreshed: " + data.MetaData.LastRefreshed); // Console.WriteLine("Interval: " + data.MetaData.Interval); // Console.WriteLine("OutputSize: " + data.MetaData.OutputSize); // Console.WriteLine("TimeZone: " + data.MetaData.TimeZone); // Console.WriteLine("========================"); // Console.WriteLine("========================"); // foreach (var timeseries in data.TimeSeries) // { // //Console.WriteLine("open: " + timeseries.open); // //Console.WriteLine("high: " + timeseries.high); // //Console.WriteLine("low: " + timeseries.low); // //Console.WriteLine("close: " + timeseries.close); // //Console.WriteLine("volume: " + timeseries.volume); // //Console.WriteLine("DateTime: " + timeseries.DateTime); // //Console.WriteLine("========================"); // values.Insert(0, new DateModel // { // Value = double.Parse(timeseries.close), // DateTime = DateTime.ParseExact(timeseries.DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) // }); // } // } // } //),DispatcherPriority.Background); Int_TIME_SERIES_INTRADAY time_series_intraday = _connection.GetQueryObject_TIME_SERIES_INTRADAY(); try { IAvapiResponse_TIME_SERIES_INTRADAY time_series_intradayResponse = time_series_intraday.Query( _args.Symbol, Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_1min, Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_outputsize.compact); var data = time_series_intradayResponse.Data; if (data.Error) { MessageBox.Show("Failed to fetch data", "Error"); } else { Console.WriteLine("Information: " + data.MetaData.Information); Console.WriteLine("Symbol: " + data.MetaData.Symbol); Console.WriteLine("LastRefreshed: " + data.MetaData.LastRefreshed); Console.WriteLine("Interval: " + data.MetaData.Interval); Console.WriteLine("OutputSize: " + data.MetaData.OutputSize); Console.WriteLine("TimeZone: " + data.MetaData.TimeZone); Console.WriteLine("========================"); Console.WriteLine("========================"); int count = 12; foreach (var timeseries in data.TimeSeries) { if (count <= 0) { break; } Console.WriteLine("open: " + timeseries.open); Console.WriteLine("high: " + timeseries.high); Console.WriteLine("low: " + timeseries.low); Console.WriteLine("close: " + timeseries.close); Console.WriteLine("volume: " + timeseries.volume); Console.WriteLine("DateTime: " + timeseries.DateTime); Console.WriteLine("========================"); values.Insert(0, new DateTimePoint { Value = double.Parse(timeseries.close), DateTime = DateTime.ParseExact(timeseries.DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) }); } } } catch (NullReferenceException) { MessageBox.Show("Failed to send request", "Error"); } return(values); }
private void DrawGraph() { ValuesTmp.Clear(); LabelsTmp.Clear(); string path = Base.path + "\\Data\\" + album_cb.SelectedValue; DateTime date; if (Directory.Exists(path)) { foreach (string photo in Directory.GetFiles(path).Select(Path.GetFileName).ToArray()) { using (StreamReader sr = new StreamReader(path + "\\" + photo)) { string label = sr.ReadLine(); sr.ReadLine(); if (date_cbi.IsSelected == false) { sr.ReadLine(); LabelsTmp.Add(label); if (percentages_cbi.IsSelected == true) { ValuesTmp.Add(new ObservableValue(((Double.Parse(sr.ReadLine())) / (Double.Parse(sr.ReadLine()))) * 100)); chartAxisY.Title = "Percent"; } else if (pixels_cbi.IsSelected == true) { ValuesTmp.Add(new ObservableValue(Int32.Parse(sr.ReadLine()))); chartAxisY.Title = "Pixels"; } } else { date = DateTime.Parse(sr.ReadLine()); if (LabelsTmp.Count == 0) { LabelsTmp.Add(date.ToShortDateString()); if (percentages_cbi.IsSelected == true) { ValuesTmp.Add(new ObservableValue(((Double.Parse(sr.ReadLine())) / (Double.Parse(sr.ReadLine()))) * 100)); chartAxisY.Title = "Percent"; } else if (pixels_cbi.IsSelected == true) { ValuesTmp.Add(new ObservableValue(Int32.Parse(sr.ReadLine()))); chartAxisY.Title = "Pixels"; } continue; } for (int i = 0; i < LabelsTmp.Count; i++) { if (date <= DateTime.Parse(LabelsTmp[i])) { LabelsTmp.Insert(i, date.ToShortDateString()); if (percentages_cbi.IsSelected == true) { ValuesTmp.Insert(i, (new ObservableValue(((Double.Parse(sr.ReadLine())) / (Double.Parse(sr.ReadLine()))) * 100))); chartAxisY.Title = "Percent"; } else if (pixels_cbi.IsSelected == true) { ValuesTmp.Insert(i, new ObservableValue(Int32.Parse(sr.ReadLine()))); chartAxisY.Title = "Pixels"; } break; } else { LabelsTmp.Add(date.ToShortDateString()); if (percentages_cbi.IsSelected == true) { ValuesTmp.Add(new ObservableValue(((Double.Parse(sr.ReadLine())) / (Double.Parse(sr.ReadLine()))) * 100)); chartAxisY.Title = "Percent"; } else if (pixels_cbi.IsSelected == true) { ValuesTmp.Add(new ObservableValue(Int32.Parse(sr.ReadLine()))); chartAxisY.Title = "Pixels"; } break; } } } } } chartAxisX.Labels = LabelsTmp.ToArray(); if (ValuesTmp.Count > 1) { adcisGlobal_l.Content = "ADCIS global: " + Math.Round((ValuesTmp[ValuesTmp.Count - 1].Value / ValuesTmp[0].Value) * 100, 2) + "%"; adcisLast_l.Content = "ADCIS last: " + Math.Round((ValuesTmp[ValuesTmp.Count - 1].Value / ValuesTmp[ValuesTmp.Count - 2].Value) * 100, 2) + "%"; } } else { MessageBox.Show("No areas selected!"); } }
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)); } } }