compare_strategies
Compare macro-factor quantitative trading strategies side-by-side to evaluate key metrics like return, drawdown, and Sharpe ratio for risk profile assessment.
Instructions
Compare multiple QuantToGo macro-factor strategies side-by-side. Returns a comparison table of key metrics (return, drawdown, Sharpe, recent performance). Useful for evaluating which quantitative signal source strategies fit your risk profile.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| productIds | Yes | Array of product IDs to compare, e.g. ['PROD-E3X', 'PROD-PCR'] |
Implementation Reference
- src/index.ts:229-270 (handler)Handler function that executes compare_strategies tool logic: fetches products via callAPI, filters by productIds, and returns comparison data with key metrics (return, drawdown, recent performance)
async ({ productIds }) => { const res = (await callAPI("getProducts")) as { code: number; data: Record<string, unknown>[]; }; if (res.code !== 0 || !Array.isArray(res.data)) { return { content: [{ type: "text" as const, text: "Failed to fetch strategies" }], }; } const selected = res.data.filter((p) => productIds.includes(p.productId as string) ); if (selected.length === 0) { return { content: [ { type: "text" as const, text: `None of the specified product IDs were found. Use list_strategies to see available IDs.`, }, ], }; } const comparison = selected.map((p) => ({ productId: p.productId, name: p.name, market: p.market || "—", totalReturn: p.totalReturn ?? p.totalReturn5Y ?? null, maxDrawdown: p.maxDrawdown ?? null, recent1dReturn: p.recent1dReturn ?? null, recent30dReturn: p.recent30dReturn ?? null, })); return { content: [ { type: "text" as const, text: JSON.stringify(comparison, null, 2) }, ], }; } - src/index.ts:218-271 (registration)Tool registration using server.tool() with name 'compare_strategies', description, zod schema for input validation, and async handler function
server.tool( "compare_strategies", "Compare multiple QuantToGo macro-factor strategies side-by-side. Returns a comparison table of key metrics (return, drawdown, Sharpe, recent performance). Useful for evaluating which quantitative signal source strategies fit your risk profile.", { productIds: z .array(z.string()) .min(2) .max(8) .describe("Array of product IDs to compare, e.g. ['PROD-E3X', 'PROD-PCR']"), }, async ({ productIds }) => { const res = (await callAPI("getProducts")) as { code: number; data: Record<string, unknown>[]; }; if (res.code !== 0 || !Array.isArray(res.data)) { return { content: [{ type: "text" as const, text: "Failed to fetch strategies" }], }; } const selected = res.data.filter((p) => productIds.includes(p.productId as string) ); if (selected.length === 0) { return { content: [ { type: "text" as const, text: `None of the specified product IDs were found. Use list_strategies to see available IDs.`, }, ], }; } const comparison = selected.map((p) => ({ productId: p.productId, name: p.name, market: p.market || "—", totalReturn: p.totalReturn ?? p.totalReturn5Y ?? null, maxDrawdown: p.maxDrawdown ?? null, recent1dReturn: p.recent1dReturn ?? null, recent30dReturn: p.recent30dReturn ?? null, })); return { content: [ { type: "text" as const, text: JSON.stringify(comparison, null, 2) }, ], }; } ); - src/index.ts:222-228 (schema)Zod schema definition for productIds parameter: array of strings with min 2 and max 8 elements, with descriptive text
{ productIds: z .array(z.string()) .min(2) .max(8) .describe("Array of product IDs to compare, e.g. ['PROD-E3X', 'PROD-PCR']"), }, - src/index.ts:11-19 (helper)callAPI helper function used by the handler to fetch data from QuantToGo API endpoints via HTTP POST requests
async function callAPI(fn: string, body: Record<string, unknown> = {}): Promise<unknown> { const resp = await fetch(`${API_BASE}/${fn}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); if (!resp.ok) throw new Error(`API ${fn} returned ${resp.status}`); return resp.json(); }