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

Coffee with Professional Commodity Trader (Part 4)

The sunburn has finally healed after nearly two hours outdoors enjoying a Caramel Frappuccino and conversation with our professional commodity trader NK. Today I will wrap up the miscellaneous notes and talk briefly about future directions.

Because incorporating and sticking with new trading strategies has proven to be a herculean task for me, in order to make this discussion useful I should aim to start with something small. To this end, tasks I will ultimately need to complete include:

While I have brainstormed everything I can think of at the present moment, I repeat that my goal is really to do one [or two] per week [or month]. “Start small” and “look for continuous improvement” are mantras by which I try to live.

And because I will probably need the accountability of this blog to stay on track, I will probably be keeping you posted!

Coffee with Professional Commodity Trader (Part 3)

I recently spent nearly two hours taking in a lot of sun and a conversation with NK, a professional commodity trader. Today I continue presentation of miscellaneous notes from the meeting.

I will conclude next time.

Coffee with Professional Commodity Trader (Part 2)

Today I continue with miscellaneous notes from two hours of sun exposure and a delish grande Carmel Frappuccino while conversing with professional commodity trader NK:

I will continue next time.

Coffee with Professional Commodity Trader (Part 1)

I recently met up with a professional commodities trader (NK) to talk about trading in general. We sat outside Starbucks and I enjoyed a Caramel Frappuccino in the sun for nearly two hours. Once I got through the whipped cream, I found the sun had melted the drink to liquid. 1-2 days later, I also regretted not having sat in the shade.

In any case, here are some miscellaneous notes about our conversation:

I will continue next time.

Backtester Variables

Last time I discussed modules including those used by an early version of my backtester. Today I introduce the variables.

For any seasoned Python programmer, this post is probably unnecessary. Not only can you understand the variables just by looking at the program, the names themselves make logical sense. This post is really for me.

Without further ado:

I will have further variables as I continue with program development and I can always follow-up or update as needed.

*—Exercise: write a code overlay that will print out all variable names and respective data types in a program.

Backtester Modules

In Part 1, I reviewed the history and background of this backtester’s dream. I now continue with exploration of the backtesting program in a didactic fashion because as a Python beginner, I am still trying to learn.

Modular programming involves cobbling together individual modules like building blocks to form a larger application. I can understand a few advantages to modularizing code:

The backtester is currently 290 lines long, which is hardly large enough for a programming team. It is large enough to make use of the following modules, though: os, glob, numpy, datetime, pandas, and matplotlib.pyplot.

I learned about numpy, datetime, pandas, and matplotlib in my DataCamp courses. I trust many beginners are also familiar so I won’t spend dedicated time discussing them.

The os and glob modules are involved in file management. The backtester makes use of option .csv files. According to Python documentation, the os module provides “a portable way of using operating system dependent functionality.” This will direct the program to a specific folder where the data files are located.

The glob module “finds all the pathnames matching a specified pattern according to the rules used by the Unix shell, although results are returned in arbitrary order.” I don’t know what the Unix shell rules are. I also don’t want results returned in arbitrary order. Regardless of what the documentation says, the following simple code works:

I created a folder “test” on my desktop and placed three Excel .csv files inside: 2017.csv, 2018.csv, and 2019.csv. Note how the filenames print in chronological order. For backtesting purposes, that is exactly what I need to happen.

Functions are a form of modular programming. When defined early in the program, functions may be called by name at multiple points later. I did not create any user-defined functions because I was having trouble conceptualizing how. The backtester does perform repetitive tasks, but loops seems sufficient do the work thus far.

If functions are faster, then it may worth making the change to implement them. As I go through the program more closely and further organize my thoughts,* I will be in a better position to make this assessment.

*—Don’t get me started on variable scope right now.

Time Spread Backtesting 2022 Q1 (Part 5)

I’m in the process of manually backtesting time spreads through 2022 Q1 by entering a new trade every Monday (or Tuesday).

I left off describing the controversy of managing time spreads. Simply with regard to adjustment timing, I have mentioned:

With SPX at 4474, trade #7 begins on 2/7/22 at the 4475 strike for $8,041: TD 46, IV 20.5%, horizontal skew -0.1%, NPV 367, and theta 47. This trade reaches PT on 24 DIT with one adjustment for a gain of 10.4%. Max DD is -12%.

With SPX at 4403, trade #8 begins on 2/14/22 at the 4425 strike for $5,528: TD 25, IV 23.5%, horizontal skew 0.1%, NPV 246, and theta 27. This trade reaches PT on 29 DIT with one adjustment for a gain of 12.4%. Max DD is -10.3%.

With SPX at 4292, trade #9 begins on 2/22/22 at the 4300 strike for $5,698: TD 37, IV 26.5%, horizontal skew 0.2%, NPV 246, and theta 32. This trade reaches PT on 15 DIT with no adjustments for a gain of 15.0%. Max DD is -3.7%.

With SPX at 4366, trade #10 begins on 2/28/22 at the 4375 strike for $5,998: TD 37, IV 26.1%, horizontal skew 0.2%, NPV 261, and theta 35. This trade reaches PT on 15 DIT with no adjustments for a gain of 10.7%. Max DD is -3.5%.

With SPX at 4201, trade #11 begins on 3/7/22 at the 4225 strike for $6,598: TD 37, IV 34.1%, horizontal skew 0.5%, NPV 262, and theta 48.

With SPX up 1.04 SD over 11 days, the first adjustment point is hit with trade down 9%:

time spread backtesting 2022 Q1 trade 11 (1) (7-1-22)

Trade down 13% after 22 DIT, but despite another scary look (see Part 4, first graph) this is not the second adjustment point:

time spread backtesting 2022 Q1 trade 11 (2) (7-1-22)

PT is hit two weeks later with a gain of 11.3%. Max DD is the 13% shown above. Unlike trade #6, doing a pre-emptive adjustment this time is followed by max loss two weeks later (-20.1%).

I don’t necessarily think the base strategy is good or better just because trade management matters for trade #11. More than anything else, I feel lucky and I realize that at market pivots, I will feel equally unlucky going through other trades that proceed to lose.

While I await a larger sample size to make any determination about optimal strategy guidelines, I suspect this sort of ambiguity is what is what makes time spreads difficult to trade.

I will continue next time.

Time Spread Backtesting 2022 Q1 (Part 4)

Today I continue manual backtesting of 2022 Q1 time spreads by entering a new trade every Mon (or Tues in case of holiday).

With SPX at 4403, trade #5 begins on 1/24/22 at the 4425 strike for $7,598: TD 29, IV 25.7%, horizontal skew 0.2%, NPV 334, and theta 43.

Profit target is hit 32 days later with trade up 15.82% and TD 20. Nothing to see here.

With SPX at 4515, trade #6 begins on 1/31/22 at the 4525 strike for $7,578: TD 32, IV 20.8%, horizontal skew -0.1%, NPV 356, and theta 41.

According to the base strategy, this is not an adjustment point with SPX down 0.79 SD over 18 days:

time spread backtesting 2022 Q1 trade 6 (1) (7-1-22)

Trade is only down 3% and TD (not mentioned in base strategy guidelines) = 4. Graphically, expiration breakeven looks close such that another substantial SPX move lower could mean big trouble.

This is exactly what happens the very next trading day with a 1.03 SD selloff. The pre-emptive adjustment just mentioned would have the trade down less than 9% and just under 14% the day after: an even worse selloff at 1.42 SD. The trade would then go on to reach PT with a gain of 14.1% after 30 DIT.

Sticking with the base strategy would put me at an adjustment point the next trading day (22 DIT):

time spread backtesting 2022 Q1 trade 6 (2) (7-1-22)

Trade is now down 12% after a 1.03 SD selloff in SPX, which is not as bad as I might have expected. What is somewhat frustrating about adjusting for the first time down 12% is the next adjustment point lingering a mere 2% away.

The lesson here may be to mind the numbers (TD 4 is much better than 1-2) rather than a graph that may not be properly scaled for best interpretation. A holiday separates the two graphs above, too; the extra day of time decay can help PnL.

The very next day (23 DIT), that 1.42 SD selloff puts the trade down 16%:

time spread backtesting 2022 Q1 trade 6 (3) (7-1-22)

The base strategy does not address days between adjustments, which means I should adjust on back-to-back days as needed. My gut wants to minimize adjustments because of slippage loss,* and skipping this second adjustment gets me to PT with a gain of 13% after 32 DIT. The risk of skipping the second adjustment is that a big move catapults me well beyond -16% to max loss before a second adjustment can be made.

Adhering to trade guidelines and making adjustments on back-to-back days results in a 10% profit after 37 DIT. For this particular trade, the specifics of management really do not matter.

You can get a sense of why I find time spreads so challenging, though. “The devil’s in the details,” and there are lots of details in which to get lost.

I will continue next time.

* — I need to trade more time spreads to get a feel for how significant this is.