YieldManager#
API documentation for tradeexecutor.strategy.pandas_trader.yield_manager.YieldManager Python class in Trading Strategy framework.
- class YieldManager[source]#
Bases:
object
Generate yield on cash.
Park cash to profitable positions outside direactional trading
Extract cash when needed
Example:
# Move cash in and out yield managed to cover spot positions if parameters.use_managed_yield: yield_manager = YieldManager( position_manager=position_manager, rules=create_yield_rules(parameters, strategy_universe), ) yield_input = YieldDecisionInput( execution_mode=input.execution_context.mode, cycle=input.cycle, timestamp=timestamp, total_equity=state.portfolio.get_total_equity(), directional_trades=trades, size_risk_model=size_risk_model, pending_redemptions=position_manager.get_pending_redemptions(), ) yield_result = yield_manager.calculate_yield_management(yield_input) trades += yield_result.trades
- __init__(position_manager, rules)[source]#
- Parameters:
position_manager (PositionManager) – PositionManager instance setup within decide_trades()
rules (YieldRuleset) –
Methods
__init__
(position_manager, rules)- param position_manager:
How much cash we need ton this cycle.
calculate_yield_management
(input)Calculate trades for the yield management.
calculate_yield_positions
(execution_mode, ...)Calculate cash positions we are allowed to take.
Get map of our non-directional positions.
generate_rebalance_trades
(cycle, timestamp, ...)Create trades to adjust yield positions.
Attributes
cash_pair
portfolio
- __init__(position_manager, rules)[source]#
- Parameters:
position_manager (PositionManager) – PositionManager instance setup within decide_trades()
rules (YieldRuleset) –
- gather_current_yield_positions()[source]#
Get map of our non-directional positions.
Note that this is called in planning phase, so there may be pending positions
- Returns:
List of positions that are used to generate yield.
- Return type:
dict[tradeexecutor.state.identifier.TradingPairIdentifier, tradeexecutor.state.generic_position.GenericPosition | None]
- generate_rebalance_trades(cycle, timestamp, current_yield_positions, desired_yield_positions)[source]#
Create trades to adjust yield positions.
- Parameters:
cycle (int) – Strategy cycle number for diagnostics
current_yield_positions (dict[tradeexecutor.state.identifier.TradingPairIdentifier, tradeexecutor.state.generic_position.GenericPosition | None]) – Where is our cash currently held
desired_yield_positions (dict[tradeexecutor.state.identifier.TradingPairIdentifier, tradeexecutor.strategy.pandas_trader.yield_manager.YieldDecision]) – What are the desired positiosn at the end of this cycle
timestamp (datetime) –
- Return type:
- calculate_yield_positions(execution_mode, timestamp, cycle, cash_available_for_yield, current_positions, size_risk_model=None, usd_assert_epsilon=0.01)[source]#
Calculate cash positions we are allowed to take.
Simple first in, first out, fill earier rules to their max weight
- Parameters:
execution_mode (ExecutionMode) –
timestamp (datetime) –
cycle (int) –
cash_available_for_yield (float) –
current_positions (dict[tradeexecutor.state.identifier.TradingPairIdentifier, tradeexecutor.state.generic_position.GenericPosition | None]) –
size_risk_model (tradeexecutor.strategy.tvl_size_risk.BaseTVLSizeRiskModel | None) –
- Return type:
dict[tradeexecutor.state.identifier.TradingPairIdentifier, tradeexecutor.strategy.pandas_trader.yield_manager.YieldDecision]
- calculate_cash_needed_to_cover_directional_trades(input, available_cash, already_deposited)[source]#
How much cash we need ton this cycle.
We have a strategy that uses Aave for USDC credit yield, or similar yield farming service
We need to know how much new cash we need to release
Note
Only call this after you have set up all the other trades in this cycle.
See also
manage_credit_flow()
- Returns:
Positive: This much of cash must be released from credit supplied. Negative: This much of cash be deposited to Aave at the end of the cycle.
- Parameters:
input (YieldDecisionInput) –
available_cash (float) –
already_deposited (float) –
- calculate_yield_management(input)[source]#
Calculate trades for the yield management.
- Parameters:
input (YieldDecisionInput) –
- Return type: