modular_trader.framework.risk_management#

Submodules#

Classes#

BaseRiskManagement

Base class for risk management.

FixedStopLossRiskManagement

Fixed stop loss.

NullRiskManagement

No-op risk management strategy.

Package Contents#

class modular_trader.framework.risk_management.BaseRiskManagement#

Bases: abc.ABC

Inheritance diagram of modular_trader.framework.risk_management.BaseRiskManagement

Base class for risk management.

This class defines the interface for all risk management strategies.

The __call__ method is called by the framework to apply the risk management strategy to the given allocations.

The run method is called by __call__ and should be implemented by subclasses to perform the actual risk management logic.

__call__(context: modular_trader.context.Context, allocations: modular_trader.allocation.AllocationCollection)#
Parameters:
abstract run(context: modular_trader.context.Context, allocations: modular_trader.allocation.AllocationCollection) modular_trader.allocation.AllocationCollection#
Parameters:
Return type:

modular_trader.allocation.AllocationCollection

class modular_trader.framework.risk_management.FixedStopLossRiskManagement#

Bases: modular_trader.framework.risk_management.base.BaseRiskManagement

Inheritance diagram of modular_trader.framework.risk_management.FixedStopLossRiskManagement

Fixed stop loss.

Liquidate positions if unrealized loss percent >= percent_loss.

run(context: modular_trader.context.Context, allocations: modular_trader.allocation.AllocationCollection) modular_trader.allocation.AllocationCollection#

Liquidate positions if unrealized loss percent >= percent_loss.

Args:

context: The context to get the current positions from. allocations: The allocations to modify.

Returns:

The modified allocations.

Parameters:
Return type:

modular_trader.allocation.AllocationCollection

percent_loss: float = None#
class modular_trader.framework.risk_management.NullRiskManagement#

Bases: modular_trader.framework.risk_management.base.BaseRiskManagement

Inheritance diagram of modular_trader.framework.risk_management.NullRiskManagement

No-op risk management strategy.

Leaves allocations unchanged.

run(context: modular_trader.context.Context, allocations: modular_trader.allocation.AllocationCollection) modular_trader.allocation.AllocationCollection#
Parameters:
Return type:

modular_trader.allocation.AllocationCollection