Skip to content

Conversation

rrawatt
Copy link

@rrawatt rrawatt commented Mar 5, 2025

Refactored Optimization & Backtest modules

  • Updated header formatting and licensing comments.
  • Using setdefault in OptimizationParameter and simplifying Objective.
  • Revised Optimization base class: complete solve() implementation and clarifying turnover constraints.
  • Fixed MeanVariance bug by properly instantiating MeanEstimator.
  • Simplified PercentilePortfolios for clear portfolio segmentation and weight assignment.
  • Updated BacktestService and custom append function to use new "portfolio_ids" key.

rrawatt added 2 commits March 5, 2025 12:17
Refactor Optimization & Backtest modules

- Update header formatting and licensing comments.
- Use setdefault in OptimizationParameter and simplify Objective.
- Revise Optimization base class: complete solve() implementation and clarify turnover constraints.
- Fix MeanVariance bug by properly instantiating MeanEstimator.
- Simplify PercentilePortfolios for clear portfolio segmentation and weight assignment.
- Update BacktestService and custom append function to use new "portfolio_ids" key.
@rrawatt
Copy link
Author

rrawatt commented Mar 7, 2025

Fixed mutable default args in Portfolio.init
Set default values for weights and init_weights to None and assign empty dictionaries inside the constructor.

Using datetime conversion for comparisons
Converting date strings to pd.Timestamp in methods (e.g. turnover, get_previous_portfolio, and simulate) to ensure proper date comparisons.

Refactored cost subtraction in simulate
Using Series alignment via .subtract() and .loc indexing in Strategy.simulate for variable and fixed cost adjustments.

Minor improvements and error handling
Added checks for empty weights in float_weights and safe handling in initial_weights, plus various style improvements.

rrawatt added 3 commits March 11, 2025 17:55
Empty Filter Handling:
The df() method now checks if no filter names are provided and returns an empty DataFrame instead of attempting to concatenate an empty dictionary.

Safe MultiIndex Handling:
In df_binary(), a check was added to ensure the columns are a MultiIndex with more than one level before calling .droplevel(1).

Type and Value Checks:
The setter for selected enforces that the input is a pd.Index, and the add_filtered() method validates that filters (Series or DataFrame) are properly formatted with a binary column containing only 0s and 1s.

Consistent Filter Processing:
The code consistently processes filters by using their keys, ensuring only filters with 'binary' in their column names are considered during binary selection.
Expanded docstrings provide clarity on the purpose and usage of each function.
Type hints were added
Enhanced overall readability
docstrings have been added.
Fixed add_l1 Method to correctly accept values like 0.
modified to_GhAb Method to handle handles edge cases.
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.

1 participant