private void WriteDataToCsv(StreamWriter sw, PortfolioPerformance portfolioPerformance) { string listSeparator = Thread.CurrentThread.CurrentCulture.TextInfo.ListSeparator; sw.WriteLine(string.Format("DateTime{0}Equity{0}Drowdawn", (object)listSeparator)); for (int index = 0; index < portfolioPerformance.EquitySeries.Count; ++index) { string str = string.Format("{1}{0}{2}{0}{3}", (object)listSeparator, (object)portfolioPerformance.EquitySeries.GetDateTime(index), (object)portfolioPerformance.EquitySeries[index], (object)portfolioPerformance.DrawdownSeries[index]); sw.WriteLine(str); } }
private void Reset() { this.portfolio = Framework.Current.PortfolioManager.Portfolios[this.name]; if (this.portfolio == null) { return; } PortfolioPerformance performance = this.portfolio.Performance; this.chart.Reset(); this.chart.SetMainSeries((ISeries)performance.EquitySeries, false, Color.White); this.chart.AddPad(); this.chart.DrawSeries(performance.DrawdownSeries, 2, Color.White, SimpleDSStyle.Line, SearchOption.ExactFirst, SmoothingMode.HighSpeed); this.chart.UpdateStyle = ChartUpdateStyle.WholeRange; performance.Updated += new EventHandler(this.performance_Updated); }
private void Reset() { Gtk.Application.Invoke((sender, args) => { this.portfolio = Framework.Current.PortfolioManager.Portfolios.GetByIndex(0); if (this.portfolio == null) { return; } PortfolioPerformance performance = this.portfolio.Performance; this.chart3.Reset(); this.chart3.SetMainSeries(performance.EquitySeries, false, Color.White); this.chart3.AddPad(); this.chart3.DrawSeries(performance.DrawdownSeries, 2, Color.White, SimpleDSStyle.Line, SearchOption.ExactFirst, SmoothingMode.HighSpeed); this.chart3.UpdateStyle = ChartUpdateStyle.WholeRange; performance.Updated += new EventHandler((o, e) => { this.chart3.OnItemAdedd(this.portfolio.Performance.EquitySeries.LastDateTime); }); }); }
private void CopyDataToWorksheet(Worksheet sheet, PortfolioPerformance portfolioPerformance) { int num = 2; Range range1 = sheet.GetRange(1, 1); range1.Bold = true; range1.Value = (object)"DateTime"; Range range2 = sheet.GetRange(1, 2); range2.Bold = true; range2.Value = (object)"Equity"; Range range3 = sheet.GetRange(1, 3); range3.Bold = true; range3.Value = (object)"Drowdawn"; for (int index = 0; index < portfolioPerformance.EquitySeries.Count; ++index) { sheet.GetRange(num + index, 1).Value = (object)portfolioPerformance.EquitySeries.GetDateTime(index).ToString(); sheet.GetRange(num + index, 2).Value = (object)portfolioPerformance.EquitySeries[index]; sheet.GetRange(num + index, 3).Value = (object)portfolioPerformance.DrawdownSeries[index]; } }
private void ExportCsv(TabControl tabControl) { CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; try { this.Cursor = Cursors.WaitCursor; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture.DateTimeFormat = currentCulture.DateTimeFormat; SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.DefaultExt = "*.csv"; saveFileDialog.Filter = "CSV Files|*.csv|All Files|*.*"; saveFileDialog.Title = "Save Worksheet"; if (saveFileDialog.ShowDialog((IWin32Window)this) != DialogResult.OK) { return; } StreamWriter sw = new StreamWriter(saveFileDialog.FileName); for (int index = 0; index < tabControl.TabCount; ++index) { TabPage tabPage = tabControl.TabPages[index]; switch (tabPage.Text) { case "Composition": IEnumerator enumerator = tabPage.Controls[0].Controls.GetEnumerator(); try { while (enumerator.MoveNext()) { Control control = (Control)enumerator.Current; sw.WriteLine("Tab[" + tabPage.Text + "]"); this.WriteDataToCsv(sw, new ListView[1] { control.Controls[0] as ListView }); } break; } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } case "Performance": PortfolioPerformance performance = ((PerformanceWindow)tabPage.Controls[0]).Portfolio.Performance; sw.WriteLine("Tab[" + tabPage.Text + "]"); this.WriteDataToCsv(sw, performance); break; case "Correlation Matrix": case "Children Statistics": case "Statistics": Control control1 = tabPage.Controls[0]; sw.WriteLine("Tab[" + tabPage.Text + "]"); this.WriteDataToCsv(sw, new ListView[1] { control1.Controls[0] as ListView }); break; } } sw.Close(); } catch (Exception ex) { int num = (int)MessageBox.Show((IWin32Window)this, string.Format("An error occured while exporting results. {0}{0}{1}", (object)Environment.NewLine, (object)ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } finally { Thread.CurrentThread.CurrentCulture = currentCulture; this.Cursor = Cursors.Default; } }
private void ExportXls(TabControl tabControl) { CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; try { this.Cursor = Cursors.WaitCursor; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture.DateTimeFormat = currentCulture.DateTimeFormat; Excel excel = new Excel(); excel.Workbooks.Add(); Workbook workbook = excel.Workbooks[1]; WorksheetList worksheets = workbook.Worksheets; for (int index = 0; index < tabControl.TabCount; ++index) { TabPage tabPage = tabControl.TabPages[index]; switch (tabPage.Text) { case "Composition": IEnumerator enumerator = tabPage.Controls[0].Controls.GetEnumerator(); try { while (enumerator.MoveNext()) { Control control = (Control)enumerator.Current; worksheets.AddLast(); Worksheet sheet = worksheets[worksheets.Count - 1]; sheet.Name = control.Text; this.CopyDataToWorksheet(sheet, new ListView[1] { control.Controls[0] as ListView }); } break; } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } case "Performance": PortfolioPerformance performance = ((PerformanceWindow)tabPage.Controls[0]).Portfolio.Performance; worksheets.AddLast(); Worksheet sheet1 = worksheets[worksheets.Count - 1]; sheet1.Name = "Performance"; this.CopyDataToWorksheet(sheet1, performance); break; case "Correlation Matrix": case "Children Statistics": case "Statistics": Control control1 = tabPage.Controls[0]; worksheets.AddLast(); Worksheet sheet2 = worksheets[worksheets.Count - 1]; sheet2.Name = tabPage.Text; this.CopyDataToWorksheet(sheet2, new ListView[1] { control1.Controls[0] as ListView }); break; } } workbook.Worksheets[1].Activate(); excel.Visible = true; } catch (Exception ex) { int num = (int)MessageBox.Show((IWin32Window)this, string.Format("An error occured while exporting results. Possible, MS Office is not installed.{0}{0}{1}", (object)Environment.NewLine, (object)ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } finally { Thread.CurrentThread.CurrentCulture = currentCulture; this.Cursor = Cursors.Default; } }