Skip to content

Add detailed refactoring plan for core classes and constants#2

Open
arkwave wants to merge 6 commits into
masterfrom
claude/update-backtesting-module-7aY7t
Open

Add detailed refactoring plan for core classes and constants#2
arkwave wants to merge 6 commits into
masterfrom
claude/update-backtesting-module-7aY7t

Conversation

@arkwave
Copy link
Copy Markdown
Owner

@arkwave arkwave commented Mar 1, 2026

No description provided.

Comprehensive plan covering:
- Centralize duplicated constants (multipliers dict in 9 files, etc.)
  into scripts/constants.py with ProductSpec NamedTuple and str Enums
- Fix bugs: LC missing comma, update_sec_lots wrong list, init_sec_by_month
  typo, desc case mismatch
- Full rename of Option attrs (K→strike, char→option_type, ki→knock_in,
  ko→knock_out, bvol→barrier_vol, direc→direction) across all callers
- Type hints on Future, Option, and Portfolio classes
- Simplify check_active (69→30 lines), moneyness (52→20 lines),
  compute_net_greeks (70→20 lines), decompose update_sec_by_month
- Extract duplicated Greeks computation into shared helper

https://claude.ai/code/session_01AMLHS99Saq5oyzykzQUGL8
- Create scripts/constants.py with ProductSpec NamedTuple, multipliers,
  contract_mths, month/sym maps, op_ticksize, and scalar constants
- Add str Enums: OptionType, BarrierStyle, BarrierDirection, SecurityType,
  PositionFlag for future use
- Replace inline constant definitions with imports in 8 consumer files:
  classes.py, calc.py, portfolio.py, simulation.py, hedge.py, util.py,
  prep_data.py, fetch_data.py
- Fix LC missing-comma bug ('V' 'Z' -> 'V', 'Z') in contract_mths
- Fix CT months inconsistency (fetch_data.py had extra 'V')
- Fix time.clock() -> time.perf_counter() (removed in Python 3.8)
- Remove unused timeit import from portfolio.py

https://claude.ai/code/session_01AMLHS99Saq5oyzykzQUGL8
- Add type hints to all Future methods
- Remove unused mutable default parameter instructions={}
- Remove verbose docstring (methods are self-documenting)

https://claude.ai/code/session_01AMLHS99Saq5oyzykzQUGL8
…thods

Rename Option attributes across entire codebase (14 files):
- K -> strike, char -> option_type, direc -> direction
- ki -> knock_in, ko -> knock_out
- bvol -> barrier_vol, bvol2 -> barrier_vol2
- Remove self.r (inline as 0)

Add type hints to all Option methods. Extract _sum_greeks_over_ttms()
helper and _is_itm() helper. Remove debug print statements.

Rename corresponding keyword arguments in calc.py functions:
_compute_value, _barrier_euro, _barrier_amer, _compute_greeks,
_euro_barrier_amer_greeks, _euro_barrier_euro_greeks.

Update all callers: simulation.py, hedge.py, util.py, portfolio.py,
signals.py, prep_data.py, and all test files.

https://claude.ai/code/session_01AMLHS99Saq5oyzykzQUGL8
Bug fixes:
- update_sec_lots: hedge_futures -> hedge_options for options lookup
- update_sec_lots: 'Option'/'Future' -> 'option'/'future' (match get_desc())
- init_sec_by_month: dict[prod] -> dic[prod] (was writing to builtin)
- init_sec_by_month: add missing 'flag' arg to update_greeks_by_month

Extract _get_position_lists() helper to DRY the flag-based dispatch
pattern repeated in 6 methods. Simplify compute_net_greeks() from
70 lines (3 separate loops) to 25 lines (single unified loop).
Replace magic number 2.8 with BREAKEVEN_FACTOR constant.

https://claude.ai/code/session_01AMLHS99Saq5oyzykzQUGL8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants