/// <summary> /// Callback method for Ticker edit box. /// Inputs the value of the ticker for which data is imported. /// </summary> /// <param name="control">Exposes method to ribbon</param> /// <param name="text">Value in the edit box</param> public void GetTickerValue(CustomUI.IRibbonControl control, string text) { if (!string.IsNullOrEmpty(text)) { this._ticker = text; } }
/// <summary> /// Callback method for Launch MA Test button. /// Launches the MA strategy backtest. /// </summary> /// <param name="control">Exposes method to ribbon</param> public void TestMovingAverage(CustomUI.IRibbonControl control) { #region TestMovingAverage sanity checks // --> On imported data var importer = DataImporter.DataImporter.Instance; List <DataTypes.Quote> data = importer.GetData(); if (data == null) { MessageBox.Show("Please import data before lauching test"); return; } // --> On strategy parameters if (this._maAmount == null) { MessageBox.Show("Please input amount to invest in strategy"); return; } if (this._maLongLevel == null) { MessageBox.Show("Please input Moving Average Long Level in strategy"); return; } if (this._maShortLevel == null) { MessageBox.Show("Please input Moving Average Short Level parameter"); return; } if (this._maTakeProfitInBps == null) { MessageBox.Show("Please input Moving Average Take Profit parameter"); return; } #endregion // Compute the backtest and get the results var strategy = new TradeStrategyLib.Models.MAStrategy((int)this._maShortLevel, (int)this._maLongLevel, (double)this._maAmount, (double)this._maTakeProfitInBps); var backtest = new StrategyBacktester(strategy, data); backtest.Compute(); List <double> pnlHistory = backtest.GetPnLHistory(); if (!pnlHistory.Any()) { MessageBox.Show("Moving average strategy did not generate any trades on this" + " time interval"); return; } List <DateTime> dates = backtest.GetDates(); double totalPnl = backtest.GetTotalPnl(); double? maxDD = backtest.GetMaximumDrawdown(); double vol = backtest.GetStrategyVol(); // Write the results DataWriter.WriteBacktestResults("Moving Average", totalPnl, maxDD, vol, pnlHistory, dates); // Ensure all COM objects are released GC.Collect(); GC.WaitForPendingFinalizers(); }
/// <summary> /// 点击按钮调用 /// </summary> /// <param name="control"></param> public void OnWnl_Click(ExcelDna.Integration.CustomUI.IRibbonControl control) { string exePath = "sxwnl.exe"; if (File.Exists(exePath)) { File.Delete(exePath); } //将资源内的exe文件临时存放在文件夹下 FileStream str = new FileStream(exePath, FileMode.OpenOrCreate); str.Write(Resource1.sxwnl, 0, Resource1.sxwnl.Length); str.Close(); // System.Windows.Forms.MessageBox.Show("点击了1"); System.Diagnostics.Process myProcess = new System.Diagnostics.Process(); try { myProcess.StartInfo.UseShellExecute = false; myProcess.StartInfo.FileName = exePath; myProcess.StartInfo.CreateNoWindow = true; myProcess.Start(); } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// Callback method for Launch All button. /// Creates Task objects for each strategy backtest and runs them /// asynchronously on a ThreadPool by calling the Run method. /// Method is safe as long as <see cref="XLSingleton"/> /// and <see cref="DataWriter"/> implemenations remain thread-safe. /// </summary> /// <param name="control">Exposes the method to the ribbon</param> public void OnLaunchAllPress(CustomUI.IRibbonControl control) { // Launch all tasks Task movingAverageWorker = Task.Run(() => TestMovingAverage(control)); Task parabolicSARWorker = Task.Run(() => TestParabolicSAR(control)); Task bollingerWorker = Task.Run(() => TestBollinger(control)); // Make sure tasks have been completed. If not, .GetResult() propagates // the original exception instead of the AggregatedExceptionResult usually // propragated by tasks var movingAverageAwaiter = movingAverageWorker.GetAwaiter(); movingAverageAwaiter.OnCompleted(() => { try { movingAverageAwaiter.GetResult(); } catch (Exception e) { MessageBox.Show("Moving Average calculation failed. Error message : " + e.Message); } }); var parabolicSARAwaiter = parabolicSARWorker.GetAwaiter(); parabolicSARAwaiter.OnCompleted(() => { try { parabolicSARAwaiter.GetResult(); } catch (Exception e) { MessageBox.Show("Parabolic SAR calculation failed. Error message : " + e.Message); } }); var bollingerAwaiter = bollingerWorker.GetAwaiter(); bollingerAwaiter.OnCompleted(() => { try { bollingerAwaiter.GetResult(); } catch (Exception e) { MessageBox.Show("Bollinger calculation failed. Error message : " + e.Message); ; } }); // Ensure all COM objects are released GC.Collect(); GC.WaitForPendingFinalizers(); }
public void OnImportDataPress(CustomUI.IRibbonControl control) { // Get instance of importer var importer = DataImporter.Instance; importer.ImportData(_ticker, _startDate, _endDate); //Model.TimeSeriesEntry[] data = importer.GetData(); var data = importer.GetData(); DataWriter.WriteStockData(_ticker, data); }
/// <summary> /// 动态控制选项卡显隐状态 /// </summary> /// <param name="control">ExcelDNA中的选项卡</param> /// <param name="pressed">boot型</param> public void OAcheckBoxShowTab(ExcelDna.Integration.CustomUI.IRibbonControl control, bool pressed) { switch (control.Id) { case "checkBoxShowTabHomeb": TabHomebool = pressed; break; case "checkBoxShowTabInsert": TabInsertbool = pressed; break; case "checkBoxShowTabPageLayoutExcel": TabPageLayoutExcelbool = pressed; break; case "checkBoxShowTabFormulas": TabFormulasbool = pressed; break; case "checkBoxShowTabData": TabDatabool = pressed; break; case "checkBoxShowTabReview": TabReviewbool = pressed; break; case "checkBoxShowTabView": TabViewbool = pressed; break; case "checkBoxShowTabDeveloper": TabDeveloperbool = pressed; break; case "checkBoxShowTabAddIns": TabAddInsbool = pressed; break; case "checkBoxShowTabIcons": TabIconsbool = pressed; break; case "checkBoxShowTabAgur": TabAgurbool = pressed; break; default: break; } this.ribbon.Invalidate(); }
/// <summary> /// Callback method for Start Date edit box. /// Inputs the value in the box and casts it to DateTime object. /// </summary> /// <param name="control">Exposes method to ribbon</param> /// <param name="text">Value in the edit box</param> public void GetStartDateValue(CustomUI.IRibbonControl control, string text) { try { if (!string.IsNullOrEmpty(text)) { this._startDate = DateTime.Parse(text, this._culture); } } catch (FormatException e) { MessageBox.Show(e.Message); } }
/// <summary> /// Callback method for Parabolic SAR Take Profit Level edit box. /// Inputs the value in the edit box and casts it to double. /// </summary> /// <param name="control">Exposes method to the ribbon</param> /// <param name="text">Value in the edit box</param> /// <exception cref="MessageBox">Shows message box on FormatException</exception> public void GetSARTakeProfitValue(CustomUI.IRibbonControl control, string text) { try { if (!string.IsNullOrEmpty(text)) { this._SARTakeProfitInBps = double.Parse(text); } } catch (FormatException e) { MessageBox.Show(e.Message); } }
/// <summary> /// Callback method for Maximum Accelerator Factor edit box. /// Inputs the value in the edit box and casts it to double. /// </summary> /// <param name="control">Exposes method to the ribbon</param> /// <param name="text">Value in the edit box</param> /// <exception cref="MessageBox">Shows message box on FormatException</exception> public void GetSARMaxAccFactorValue(CustomUI.IRibbonControl control, string text) { try { if (!string.IsNullOrEmpty(text)) { this._SARMaxAccFactorLevel = double.Parse(text); } } catch (FormatException e) { MessageBox.Show(e.Message); } }
/// <summary> /// Callback method for Bollinger Amount edit box. /// Inputs the value in the edit box and casts it to double. /// </summary> /// <param name="control">Exposes method to the ribbon</param> /// <param name="text">Value in the edit box</param> /// <exception cref="MessageBox">Shows message box on FormatException</exception> public void GetBolAmountValue(CustomUI.IRibbonControl control, string text) { try { if (!string.IsNullOrEmpty(text)) { this._bolAmount = double.Parse(text); } } catch (FormatException e) { MessageBox.Show(e.Message); } }
/// <summary> /// Callback method for MA Long Level edit box. /// Inputs the value in the edit box and casts it to double. /// </summary> /// <param name="control">Exposes method to the ribbon</param> /// <param name="text">Value in the edit box</param> /// <exception cref="MessageBox">Shows message box on FormatException</exception> public void GetMALongLevelValue(CustomUI.IRibbonControl control, string text) { try { if (!string.IsNullOrEmpty(text)) { this._maLongLevel = int.Parse(text); } } catch (FormatException e) { MessageBox.Show(e.Message); } }
/// <summary> /// Callback method for Import Data button. /// Gets the requested data for backtesting and writes it to a new worksheet. /// </summary> /// <param name="control">Exposes method to ribbon</param> public void OnImportDataPress(CustomUI.IRibbonControl control) { // Get instance of importer var importer = DataImporter.DataImporter.Instance; importer.ImportData(_ticker, _startDate, _endDate); // Get the data and write it var data = importer.GetData(); DataWriter.WriteStockData(_ticker, data); // Ensure all COM objects are released GC.Collect(); GC.WaitForPendingFinalizers(); }
/// <summary> /// 选项卡控制勾选标识 /// </summary> /// <param name="control"></param> /// <returns></returns> public bool checkBoxShowTabgetPressed(ExcelDna.Integration.CustomUI.IRibbonControl control) { switch (control.Id) { case "checkBoxShowTabHomeb": return(TabHomebool); case "checkBoxShowTabInsert": return(TabInsertbool); case "checkBoxShowTabPageLayoutExcel": return(TabPageLayoutExcelbool); case "checkBoxShowTabFormulas": return(TabFormulasbool); case "checkBoxShowTabData": return(TabDatabool); case "checkBoxShowTabReview": return(TabReviewbool); case "checkBoxShowTabView": return(TabViewbool); case "checkBoxShowTabDeveloper": return(TabDeveloperbool); case "checkBoxShowTabAddIns": return(TabAddInsbool); case "checkBoxShowTabIcons": return(TabIconsbool); case "checkBoxShowTabAgur": return(TabAgurbool); default: return(false); } }
/// <summary> /// 显示内置图标回调 /// </summary> /// <param name="control"></param> /// <param name="selectedId"></param> /// <param name="selectedIndex"></param> public void OAShowImageMso(ExcelDna.Integration.CustomUI.IRibbonControl control, string selectedId, int selectedIndex)//命名要与xml中一致 { Microsoft.Office.Interop.Excel.Range ActiveCell = (Microsoft.Office.Interop.Excel.Range)xlApp.ActiveCell; ActiveCell.Value = selectedId; }
public void OnShowUserInfo(ExcelDna.Integration.CustomUI.IRibbonControl control) { MessageBox.Show("Angemeldeter User: " + Environment.UserName); }
public void OnShowDataBrowser(ExcelDna.Integration.CustomUI.IRibbonControl control) { CTPManager.ShowCTP(); }
/// <summary> /// Callback method for Launch MA Test button. /// Launches the MA strategy backtest. /// </summary> /// <param name="control">Exposes method to ribbon</param> public void TestParabolicSAR(CustomUI.IRibbonControl control) { #region TestParabolicSAR sanity checks // --> On imported data var importer = DataImporter.DataImporter.Instance; List <DataTypes.Quote> data = importer.GetData(); if (data == null) { MessageBox.Show("Please import data before lauching test"); return; } // --> On strategy parameters if (this._SARAmount == null) { MessageBox.Show("Please input amount to invest in strategy"); return; } if (this._SARAccFactorLevel == null) { MessageBox.Show("Please input Accelerator Factor parameter"); return; } if (this._SARMaxAccFactorLevel == null) { MessageBox.Show("Please input Maximum Accelerator Factor parameter"); return; } if (this._SARTakeProfitInBps == null) { MessageBox.Show("Please input SAR Take Profit parameter"); return; } #endregion // Compute the backtest and get the results var Strategy = new TradeStrategyLib.Models.ParabolicSARStrategy((double)this._SARAccFactorLevel, (double)this._SARMaxAccFactorLevel, (double)this._SARAccFactorStep, (double)this._SARAmount, (double)this._SARTakeProfitInBps); var Backtest = new StrategyBacktester(Strategy, data); Backtest.Compute(); List <double> pnlHistory = Backtest.GetPnLHistory(); if (!pnlHistory.Any()) { MessageBox.Show("Parabolic SAR strategy did not generate any trades " + "in this time interval."); return; } List <DateTime> dates = Backtest.GetDates(); double totalPnl = Backtest.GetTotalPnl(); double? maxDD = Backtest.GetMaximumDrawdown(); double vol = Backtest.GetStrategyVol(); // Write the results DataWriter.WriteBacktestResults("Parabolic SAR", totalPnl, maxDD, vol, pnlHistory, dates); // Ensure COM objects are released GC.Collect(); GC.WaitForPendingFinalizers(); }