Quantitative Portfolio Rebalancing Function Calling Implementation
Create a TypeScript function-calling suite for executing automated equity and fixed-income rebalancing operations safely.
Deploy this template when developing programmatic trade validation and execution tools for robo-advisors or asset managers. It generates strict function declarations and order execution wrappers.
Role: Senior Quantitative Platform Developer specializing in algorithmic trade execution and tool routing.
Context
- Wealth Platform: {{wealth_platform_name}}
- Execution Broker: {{order_execution_broker}}
- Asset Classes: {{asset_classes_covered}}
- Compliance Rule Engine: {{compliance_rule_engine}}
- Execution Environment: {{runtime_environment}}
- Max Slippage Tolerance: {{max_slippage_tolerance}}
Task
Generate a robust TypeScript automation script containing explicit tool call definitions, parameter validation guards, and an execution engine that computes portfolio delta and safely routes trades to {{order_execution_broker}} under {{wealth_platform_name}} risk rules.
Method
- Declare JSON schema tool definitions for portfolio drift calculation across {{asset_classes_covered}}.
- Implement a trade simulation tool function verifying proposed orders against {{max_slippage_tolerance}}.
- Define a pre-trade compliance verification tool calling {{compliance_rule_engine}} endpoints.
- Write the order routing tool that packages authorized order payloads for {{order_execution_broker}}.
- Build a state machine to track tool execution stages from quotation to order confirmation.
- Add transaction rollback mechanisms if any single leg in the rebalance bundle fails.
- Provide an automated dry-run runner tailored for {{runtime_environment}}.
Constraints
- Output MUST be fully typed TypeScript without relying on
anytypes. - MUST NOT execute unconstrained market orders; all tools MUST enforce limit bounds.
- Financial arithmetic MUST use integer cents or big-number libraries to avoid float rounding errors.
- Tool definitions MUST contain clear descriptions to prevent agent hallucination.
Output format
1. Agent Tool Signatures
Exported TypeScript interfaces and tool definition objects.
2. Execution Handler Script
Complete execution runtime handling validation, compliance checks, and broker invocation.
3. Simulation Fixture
Mock portfolio drift event and console execution output.
Self-review
- Ensure {{max_slippage_tolerance}} is actively enforced within the trade simulation step.
- Verify all methods include structured error boundaries and type-safe returns.
- Validate that no order is routed without preceding approval from {{compliance_rule_engine}}.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.