Option FanaticOptions, stock, futures, and system trading, backtesting, money management, and much more!

Backtester Logic (Part 9)

Having completed analysis of the first two, I now continue with the update_long and update_short branches.

The conditional skeleton for these two branches of program flow looks like this:*

As discussed in the third paragraph of Part 2, rather than follow trade entry criteria these branches just need to locate previous selections. L134 (for update_long) and L150 (for update_short) look to match strike price and expiration. Short and sweet.

Here are considerations with regard to historical date:

  1. After find_short, historical date should be advanced to update the spread.
  2. After update_long, historical date should not be advanced since two legs need to be updated on the same date.
  3. After update_short, historical date should be advanced assuming the trade remains open.

(1) Near the end of find_short, the wait_until_next_day flag is set to True, but current_date has not yet been assigned. I have already discussed this oversight (near end of Part 3 and beginning of Part 4).

(2) update_long does nothing with the wait_until_next_day flag, and…

(3) In L145, update_short checks to make sure historical date has not advanced before progressing to update. If historical date has advanced, then an exception is raised. This should not happen if the data file is complete unless the short option has expired. Whether it be short option expiration or a predetermined DTE, I still need to build in time-stop logic to handle this.

When any branch of program flow finds a match, encoding from the data file assigns to variables shown in the key.

find_short and update_short include several lines devoted to variable reset. Variable reset prevents previous (stale) values to be used in current calculations. Variable reset will only be done as part of find_short if a short option is not found, which itself in an error. To do this effectively, I will make a list to ensure every variable involved in assignment is subsequently reset.

I will also decide whether a user-defined function to reset variables (as mentioned in Part 2 footnote) is indicated.

Is that the light at the end of the tunnel I might be starting to see?

Here are some other topics I still want to discuss:

I will continue next time.

*—As discussed in the Part 6 footnote, I’ve used Atom’s folding feature for display purposes, which
     means the higher level (indented) lines are hidden from view.

No comments posted.

Leave a Reply

Your email address will not be published. Required fields are marked *