Using the QuantShare API, it is possible to perform many tasks programmatically. One of the things you can do is backtest and get results of a specific strategy. This can be accomplished using the Script Editor tool. To open the script editor, select "Tools -> Script Editor" then create a new script using "File -> New". To access and run backtests, you need to use the "Simulator" object. This object allows you to retrieve the list of trading systems, create trading systems, update them, backtest them and optimize them. In the script editor, type "Simulator." (without the double quotes), after typing the dot, a list of available methods will be displayed. Examples to help you get started To list all your trading systems, you can for example use: string[] ts = Simulator.GetTradingSystems(""); // Category is empty here to get all trading systems To create a new trading system based on an existing one (copy) then update the start date: QSTradingSystem ts = Simulator.CreateTradingSystem("", "MyStrategy"); ts.CopySettingsFromTradingSystem("", "ExistingStrategyName"); // Replace "ExistingStrategyName" with the name of an existing strategy you have ts.StartDate = new DateTime(2000, 10, 1); // Year, Month, Day ts.Save(); To backtest a specific strategy: SimulatorTask task = Simulator.Backtest("", "MyStrategy", true); // The last parameter indicates whether to show a report or not (Run the backtest silently) Note that this function returns a "SimulatorTask" variable. We can use this variable to check whether the simulation ended and to access the report programmatically. The following example will run the backtest silently then display a message with the simulation annual return: SimulatorTask task = Simulator.Backtest("", "MyStrategy", false); while(!task.IsCompleted){ App.Main.Sleep(100); } // Returns one report after a backtest (we access it using [0] next to Reports variable) and multiple reports after an optimization double annualReturn = task.Reports[0].AnnualReturn; MessageBox.Show("The strategy annual return is: " + annualReturn); Backtest on Schedule You can schedule backtests to run at specific times or after an event (such as a new file added or updated in a directory) using the "Task Manager" tool of QuantShare. First, you need to create a script to run the backtest. - After that, open the task manager using "Tools -> Task Manager". - In the new "Task Manager" control, click on "Click here to add a task". - Specify the task trigger settings then click on "Add" button at the bottom/left corner to add the script to be executed when the task is triggered. - Name your task then click on "Add" at the bottom/right corner. The task will be added in the task scheduler of the Windows operating system and when executed will execute the script. You can even have the script open automatically QuantShare if it is closed. To enable this, check the "Execute even if application is not loaded" field in the "Add Task" form.
|