Navigation: Realtest Script Language > Syntax Element Details >







Strategy Elements


Specifies deposits and/or withdarawals to/from the current equity of a strategy


Formula expression returning an amount in dollars


This formula is evaluated once per day per strategy at the beginning of the day, before any trading signals are processed. The resulting amount is added to the "closed trade equity" of that strategy. Therefore, the formula should return a positive value for deposits or a negative value for withdrawals, and on most days will return 0.

For a multi-strategy system, only one strategy should include a CashInOut formula, since they're all using a shared equity pool anyhow. You might even want to define a separate strategy (perhaps called "Cash") just for this purpose.


1. Withdraw $10,000 every month at the start of the month:


2. Withdraw half of last year's net profit at the start of each year:


3. Deposit or withdraw specific amounts on specific dates (useful with import trades for tracking actual results):

Note that in this last example, the dates specified must be dates when the market was open, i.e., dates that correspond to a bar date in the test's bar size. The transaction is then processed before the open of that bar.

4. Another way to do the equivalent of (3), especially when the list is much longer, is to format your withdrawal and deposit information as a CSV file, add it to your Import as an EventListFile, and then reference it using the Event function.

This sounds harder than it is.

Here's how the CSV file might look:

EventListFile items must be associated with a specific symbol, so in this case we're using SPY. Any symbol in your data universe can be used, just keep it the same for every row.

Date is the deposit or withdrawal date, Value is the amount (negative for a withdrawal), and Type is an arbitrary type code to use in the Event function to look up the amount (also keep this the same for every row).

Assuming that you saved the above as "cash.csv", added "EventListFile: cash.csv" to your script's Import section, and then re-imported the data, your Cash Strategy can now simply be:

This technique is especially useful in TradeList strategies that use your actual trades to generate your own account statistics.





Copyright © 2020-2022 Systematic Solutions, LLC