BuyHoldConverter

Description

When utilizing a model from our framework, daily orders can occur even without position rebalancing. This process aligns the account’s positions with the daily ratios from the DataFrame generated by the framework.

For models like active stock selection, trading may need to align with the rebalancing cycle, holding existing positions until the next rebalancing. This tool allows for such adjustments.

This class includes two functions that convert a DataFrame generated by the framework into a buy-and-hold version.

Functions

basic_converter

This function treats changes in the position DataFrame as rebalancing dates, executing trades on these dates and holding positions thereafter. The rebalancing cycle varies based on the model.

Parameters

  • df (pandas.DataFrame): The position DataFrame to be converted.

  • universe (str): The investment universe for the position, e.g., 'kr_stock'.

Example

from finter.modeling import BuyHoldConverter

converted_position = BuyHoldConverter().basic_converter(position, 'kr_stock')

fixed_converter

This function executes trades on the first day of a specified rebalancing period, holding positions for the remainder of the period. The rebalancing period is fixed, ignoring intra-period DataFrame changes.

Parameters

  • df (pandas.DataFrame): The position DataFrame to be converted.

  • universe (str): The investment universe for the position, e.g., 'kr_stock'.

  • rebalancing_period (str or int): The rebalancing period, such as 'weekly', 'monthly', 'quarterly', or a specific integer.

Example

from finter.modeling import BuyHoldConverter

converted_position = BuyHoldConverter().fixed_converter(position, 'kr_stock', 'monthly')

Important: The first rebalancing day in the DataFrame must precede the position start date to avoid validation issues.

Last updated