QuantLua

Simulator programming


Introduction

The core of the simulation engine is the portfolio. All transactions take place within a portfolio. At the beginning of the simulation you are provided with a root portfolio which is visible in the Home tab. From there you are able to create your own subportfolios which can nest arbitrarily deep.

Most aspects of the stock simulator can be programmatically controlled. The main way of using programs within the simulator is by attaching a script to a portfolio

Attaching scripts

Suppose you have written a script Foo in the directory Components. Then to attach it to the home script do the following
  1. In the first line of the home portfolio click on "add" and select Script.
  2. A new item appears in the portfolio with the name "ScriptXXX". Click its button titled "attach". If this produces an error then you need to exit the Lua environment in the "Calculate" tab first, then try "attach" again.
  3. You navigate to the directory Components. When you are there, click on the "file" icon at the top right and select "Mark".
  4. Click on the script Foo. It is now attached to the portfolio. You may now exit the scripting environment.

Basic Simulator Function

The most important function is currpf(). This returns the current portfolio, either the one the visible if the simulator is not running, or portfolio where the script resides if the simulator is running.