Backtester Variables
Posted by Mark on July 14, 2022 at 06:44 | Last modified: June 22, 2022 08:34Last 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:
- first_bar is Boolean to direct the outer loop. This could be omitted by manually removing the data file headers.
- spread_count is numeric* to count number of trades.
- profit_tgt and max_loss are numerics. These could be made customizable or set as ranges for optimization.
- missing_s_s_p_dict is a dictionary for cases where long strike is found but short strike is not.
- control_flag is string to direct program flow (‘find_long’, ‘find_short’, ‘update_long’, or ‘update_short’).
- wait_until_next_day is Boolean to direct program flow.
- trade_date and current_date are self-explanatory with format “number of days since Jan 1, 1970.”
- P_price, P_delta, and P_theta are self-explanatory with P meaning “position.”
- H_skew and H_skew_orig are self-explanatory with H meaning “horizontal.”
- L_iv_orig and S_iv_orig are long (L) and short (S) original (at trade inception) option IV.
- ROI_current is current (or trade just closed) trade ROI.
- trade_status is a string: ‘INCEPTION’, ‘IN_TRADE’, ‘WINNER’, or ‘LOSER’.
- L_dte_orig and S_dte_orig are days to expiration for long and short options at trade inception, respectively.
- L_strike and S_strike are strike prices (possibly redundant as these should be equal).
- L_exp and S_exp are expiration dates with format “number of days since Jan 1, 1970.”
- S_exp_mo and L_exp_mo are expiration months in 3-letter format.
- L_price_orig and S_price_orig are option prices at trade inception.
- L_delta_orig and S_delta_orig are delta values at trade inception.
- L_theta and S_theta are current theta values.
- spread_width is number of days between long- and short-option expiration dates.
- P_t_d_orig and P_t_d are original and current TD ratio, respectively.
- PnL is trade pnl.
- test_counter counts number of times program reads current line (debugging).
- trade_list is list of trade entry dates (string format).
- P_price_orig_all is list of trade inception spread prices (for graphing purposes).
- P_theta_orig_price (name needs clarification) is position theta normalized for spread price at trade inception.
- P_theta_orig_price_all is list of position theta values normalized for spread price at trade inception (graphing).
- P_theta_all is list of position theta values at trade inception (graphing).
- feed_dir is path for data files.
- strike_file is the results file.
- column_names is first row of the results file.
- btstats is dataframe containing the results [file data].
- mte is numeric input for minimum number of months until long option expiration.
- width is numeric input for number of expiration months between spread legs.
- file is an iterator for data files.
- barfile is an open data file.
- line is an iterator for barfile.
- add_btstats is a row of results to be added to dataframe.
- realized_pnl is self-explanatory numeric used to calculate cumulative pnl.
- trade_dates_in_datetime is list of string (rather than “days since Jan 1, 1970”) trade entry dates.
- marker_list is list of market symbols ( ‘ ‘ or ‘d’).
- xp, yp, and m are iterators to unpack dataframe elements for plotting.
- ticks_array_raw creates tick array for x-axis.
- ticks_to_use determines tick labels for x-axis.
>
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.
No comments posted.