Add detailed refactoring plan for core classes and constants#2
Open
arkwave wants to merge 6 commits into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.