Add date-range filtering to portfolio performance tool
The agent can now answer period-specific performance questions (YTD,
MTD, 1Y, etc.) instead of always returning all-time data. Uses
historical MarketData prices to compute start-of-period valuations
and calculates period gain adjusted for cash flows.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
'4. You are a READ-ONLY assistant. You cannot execute trades, modify portfolios, or make changes to accounts.',
'4. You are a READ-ONLY assistant. You cannot execute trades, modify portfolios, or make changes to accounts.',
'5. If asked to perform actions like buying, selling, or transferring assets, politely decline and explain you can only provide information.',
'5. If asked to perform actions like buying, selling, or transferring assets, politely decline and explain you can only provide information.',
'6. Include appropriate financial disclaimers when providing analytical or forward-looking commentary.',
'6. Include appropriate financial disclaimers when providing analytical or forward-looking commentary.',
'7. When the user asks about performance for a specific time period, pass the appropriate dateRange parameter: "ytd" for this year, "1y" for past year, "5y" for 5 years, "mtd" for this month, "wtd" for this week, "1d" for today. Use "max" for all-time or when no specific period is mentioned.',
'',
'',
'DISCLAIMER: This is an AI assistant providing informational responses based on portfolio data.',
'DISCLAIMER: This is an AI assistant providing informational responses based on portfolio data.',
'This is not financial advice. Always consult with a qualified financial advisor before making investment decisions.'
'This is not financial advice. Always consult with a qualified financial advisor before making investment decisions.'
@ -11,9 +12,17 @@ export function getPortfolioPerformanceTool(deps: {
}){
}){
returntool({
returntool({
description:
description:
"Get the user's portfolio performance including total return, net performance percentage, and current net worth",
"Get the user's portfolio performance including total return, net performance percentage, and current net worth. Supports date-range filtering: 1d (today), wtd (week-to-date), mtd (month-to-date), ytd (year-to-date), 1y (1 year), 5y (5 years), max (all-time).",
parameters: z.object({}),
parameters: z.object({
execute: async()=>{
dateRange: z
.enum(["1d","mtd","wtd","ytd","1y","5y","max"])
.optional()
.default("max")
.describe(
'Time period: "ytd" for year-to-date, "1y" for last year, "5y" for 5 years, "mtd" for month-to-date, "wtd" for week-to-date, "1d" for today, "max" for all-time'
)
}),
execute: async({dateRange})=>{
// Get all orders for this user with their symbol profiles
// Get all orders for this user with their symbol profiles