opencandle 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +150 -0
- package/dist/analysts/orchestrator.d.ts +9 -0
- package/dist/analysts/orchestrator.js +100 -0
- package/dist/analysts/orchestrator.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +122 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.js +76 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/infra/browser.d.ts +27 -0
- package/dist/infra/browser.js +102 -0
- package/dist/infra/browser.js.map +1 -0
- package/dist/infra/cache.d.ts +18 -0
- package/dist/infra/cache.js +42 -0
- package/dist/infra/cache.js.map +1 -0
- package/dist/infra/http-client.d.ts +13 -0
- package/dist/infra/http-client.js +54 -0
- package/dist/infra/http-client.js.map +1 -0
- package/dist/infra/index.d.ts +5 -0
- package/dist/infra/index.js +6 -0
- package/dist/infra/index.js.map +1 -0
- package/dist/infra/open-url.d.ts +1 -0
- package/dist/infra/open-url.js +29 -0
- package/dist/infra/open-url.js.map +1 -0
- package/dist/infra/opencandle-paths.d.ts +11 -0
- package/dist/infra/opencandle-paths.js +48 -0
- package/dist/infra/opencandle-paths.js.map +1 -0
- package/dist/infra/rate-limiter.d.ts +7 -0
- package/dist/infra/rate-limiter.js +38 -0
- package/dist/infra/rate-limiter.js.map +1 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/index.js +5 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/preference-extractor.d.ts +6 -0
- package/dist/memory/preference-extractor.js +88 -0
- package/dist/memory/preference-extractor.js.map +1 -0
- package/dist/memory/retrieval.d.ts +8 -0
- package/dist/memory/retrieval.js +61 -0
- package/dist/memory/retrieval.js.map +1 -0
- package/dist/memory/sqlite.d.ts +5 -0
- package/dist/memory/sqlite.js +95 -0
- package/dist/memory/sqlite.js.map +1 -0
- package/dist/memory/storage.d.ts +47 -0
- package/dist/memory/storage.js +124 -0
- package/dist/memory/storage.js.map +1 -0
- package/dist/onboarding/state.d.ts +8 -0
- package/dist/onboarding/state.js +31 -0
- package/dist/onboarding/state.js.map +1 -0
- package/dist/pi/opencandle-extension.d.ts +2 -0
- package/dist/pi/opencandle-extension.js +205 -0
- package/dist/pi/opencandle-extension.js.map +1 -0
- package/dist/pi/session.d.ts +10 -0
- package/dist/pi/session.js +28 -0
- package/dist/pi/session.js.map +1 -0
- package/dist/pi/setup.d.ts +10 -0
- package/dist/pi/setup.js +357 -0
- package/dist/pi/setup.js.map +1 -0
- package/dist/pi/tool-adapter.d.ts +5 -0
- package/dist/pi/tool-adapter.js +17 -0
- package/dist/pi/tool-adapter.js.map +1 -0
- package/dist/prompts/workflow-prompts.d.ts +9 -0
- package/dist/prompts/workflow-prompts.js +202 -0
- package/dist/prompts/workflow-prompts.js.map +1 -0
- package/dist/providers/alpha-vantage.d.ts +4 -0
- package/dist/providers/alpha-vantage.js +122 -0
- package/dist/providers/alpha-vantage.js.map +1 -0
- package/dist/providers/coingecko.d.ts +3 -0
- package/dist/providers/coingecko.js +53 -0
- package/dist/providers/coingecko.js.map +1 -0
- package/dist/providers/fear-greed.d.ts +2 -0
- package/dist/providers/fear-greed.js +26 -0
- package/dist/providers/fear-greed.js.map +1 -0
- package/dist/providers/fred.d.ts +2 -0
- package/dist/providers/fred.js +37 -0
- package/dist/providers/fred.js.map +1 -0
- package/dist/providers/index.d.ts +7 -0
- package/dist/providers/index.js +8 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/reddit.d.ts +9 -0
- package/dist/providers/reddit.js +69 -0
- package/dist/providers/reddit.js.map +1 -0
- package/dist/providers/sec-edgar.d.ts +9 -0
- package/dist/providers/sec-edgar.js +59 -0
- package/dist/providers/sec-edgar.js.map +1 -0
- package/dist/providers/yahoo-finance.d.ts +17 -0
- package/dist/providers/yahoo-finance.js +231 -0
- package/dist/providers/yahoo-finance.js.map +1 -0
- package/dist/routing/classify-intent.d.ts +2 -0
- package/dist/routing/classify-intent.js +147 -0
- package/dist/routing/classify-intent.js.map +1 -0
- package/dist/routing/defaults.d.ts +7 -0
- package/dist/routing/defaults.js +26 -0
- package/dist/routing/defaults.js.map +1 -0
- package/dist/routing/entity-extractor.d.ts +3 -0
- package/dist/routing/entity-extractor.js +130 -0
- package/dist/routing/entity-extractor.js.map +1 -0
- package/dist/routing/index.d.ts +5 -0
- package/dist/routing/index.js +5 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/routing/slot-resolver.d.ts +15 -0
- package/dist/routing/slot-resolver.js +120 -0
- package/dist/routing/slot-resolver.js.map +1 -0
- package/dist/routing/types.d.ts +51 -0
- package/dist/routing/types.js +2 -0
- package/dist/routing/types.js.map +1 -0
- package/dist/system-prompt.d.ts +1 -0
- package/dist/system-prompt.js +49 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/tool-kit.d.ts +19 -0
- package/dist/tool-kit.js +20 -0
- package/dist/tool-kit.js.map +1 -0
- package/dist/tools/fundamentals/company-overview.d.ts +7 -0
- package/dist/tools/fundamentals/company-overview.js +40 -0
- package/dist/tools/fundamentals/company-overview.js.map +1 -0
- package/dist/tools/fundamentals/comps.d.ts +22 -0
- package/dist/tools/fundamentals/comps.js +110 -0
- package/dist/tools/fundamentals/comps.js.map +1 -0
- package/dist/tools/fundamentals/dcf.d.ts +46 -0
- package/dist/tools/fundamentals/dcf.js +184 -0
- package/dist/tools/fundamentals/dcf.js.map +1 -0
- package/dist/tools/fundamentals/earnings.d.ts +7 -0
- package/dist/tools/fundamentals/earnings.js +33 -0
- package/dist/tools/fundamentals/earnings.js.map +1 -0
- package/dist/tools/fundamentals/financials.d.ts +7 -0
- package/dist/tools/fundamentals/financials.js +37 -0
- package/dist/tools/fundamentals/financials.js.map +1 -0
- package/dist/tools/fundamentals/sec-filings.d.ts +8 -0
- package/dist/tools/fundamentals/sec-filings.js +40 -0
- package/dist/tools/fundamentals/sec-filings.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +51 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/macro/fear-greed.d.ts +5 -0
- package/dist/tools/macro/fear-greed.js +26 -0
- package/dist/tools/macro/fear-greed.js.map +1 -0
- package/dist/tools/macro/fred-data.d.ts +8 -0
- package/dist/tools/macro/fred-data.js +34 -0
- package/dist/tools/macro/fred-data.js.map +1 -0
- package/dist/tools/market/crypto-history.d.ts +8 -0
- package/dist/tools/market/crypto-history.js +32 -0
- package/dist/tools/market/crypto-history.js.map +1 -0
- package/dist/tools/market/crypto-price.d.ts +7 -0
- package/dist/tools/market/crypto-price.js +42 -0
- package/dist/tools/market/crypto-price.js.map +1 -0
- package/dist/tools/market/search-ticker.d.ts +6 -0
- package/dist/tools/market/search-ticker.js +33 -0
- package/dist/tools/market/search-ticker.js.map +1 -0
- package/dist/tools/market/stock-history.d.ts +9 -0
- package/dist/tools/market/stock-history.js +35 -0
- package/dist/tools/market/stock-history.js.map +1 -0
- package/dist/tools/market/stock-quote.d.ts +7 -0
- package/dist/tools/market/stock-quote.js +32 -0
- package/dist/tools/market/stock-quote.js.map +1 -0
- package/dist/tools/options/greeks.d.ts +14 -0
- package/dist/tools/options/greeks.js +65 -0
- package/dist/tools/options/greeks.js.map +1 -0
- package/dist/tools/options/option-chain.d.ts +9 -0
- package/dist/tools/options/option-chain.js +61 -0
- package/dist/tools/options/option-chain.js.map +1 -0
- package/dist/tools/portfolio/correlation.d.ts +10 -0
- package/dist/tools/portfolio/correlation.js +122 -0
- package/dist/tools/portfolio/correlation.js.map +1 -0
- package/dist/tools/portfolio/predictions.d.ts +49 -0
- package/dist/tools/portfolio/predictions.js +171 -0
- package/dist/tools/portfolio/predictions.js.map +1 -0
- package/dist/tools/portfolio/risk-analysis.d.ts +12 -0
- package/dist/tools/portfolio/risk-analysis.js +113 -0
- package/dist/tools/portfolio/risk-analysis.js.map +1 -0
- package/dist/tools/portfolio/tracker.d.ts +10 -0
- package/dist/tools/portfolio/tracker.js +125 -0
- package/dist/tools/portfolio/tracker.js.map +1 -0
- package/dist/tools/portfolio/watchlist.d.ts +10 -0
- package/dist/tools/portfolio/watchlist.js +120 -0
- package/dist/tools/portfolio/watchlist.js.map +1 -0
- package/dist/tools/sentiment/news-sentiment.d.ts +7 -0
- package/dist/tools/sentiment/news-sentiment.js +57 -0
- package/dist/tools/sentiment/news-sentiment.js.map +1 -0
- package/dist/tools/sentiment/reddit-sentiment.d.ts +8 -0
- package/dist/tools/sentiment/reddit-sentiment.js +37 -0
- package/dist/tools/sentiment/reddit-sentiment.js.map +1 -0
- package/dist/tools/technical/backtest.d.ts +26 -0
- package/dist/tools/technical/backtest.js +190 -0
- package/dist/tools/technical/backtest.js.map +1 -0
- package/dist/tools/technical/indicators.d.ts +23 -0
- package/dist/tools/technical/indicators.js +212 -0
- package/dist/tools/technical/indicators.js.map +1 -0
- package/dist/types/fundamentals.d.ts +44 -0
- package/dist/types/fundamentals.js +2 -0
- package/dist/types/fundamentals.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/macro.d.ts +24 -0
- package/dist/types/macro.js +14 -0
- package/dist/types/macro.js.map +1 -0
- package/dist/types/market.d.ts +41 -0
- package/dist/types/market.js +2 -0
- package/dist/types/market.js.map +1 -0
- package/dist/types/options.d.ts +33 -0
- package/dist/types/options.js +2 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/portfolio.d.ts +44 -0
- package/dist/types/portfolio.js +2 -0
- package/dist/types/portfolio.js.map +1 -0
- package/dist/types/sentiment.d.ts +24 -0
- package/dist/types/sentiment.js +2 -0
- package/dist/types/sentiment.js.map +1 -0
- package/dist/workflows/compare-assets.d.ts +3 -0
- package/dist/workflows/compare-assets.js +14 -0
- package/dist/workflows/compare-assets.js.map +1 -0
- package/dist/workflows/index.d.ts +4 -0
- package/dist/workflows/index.js +4 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/options-screener.d.ts +3 -0
- package/dist/workflows/options-screener.js +22 -0
- package/dist/workflows/options-screener.js.map +1 -0
- package/dist/workflows/portfolio-builder.d.ts +3 -0
- package/dist/workflows/portfolio-builder.js +26 -0
- package/dist/workflows/portfolio-builder.js.map +1 -0
- package/dist/workflows/types.d.ts +4 -0
- package/dist/workflows/types.js +2 -0
- package/dist/workflows/types.js.map +1 -0
- package/package.json +97 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { httpGet } from "../../infra/http-client.js";
|
|
3
|
+
const params = Type.Object({
|
|
4
|
+
query: Type.String({
|
|
5
|
+
description: "Search query — company name, ticker symbol, or crypto name (e.g. 'apple', 'AAPL', 'ethereum', 'bitcoin')",
|
|
6
|
+
}),
|
|
7
|
+
});
|
|
8
|
+
export const searchTickerTool = {
|
|
9
|
+
name: "search_ticker",
|
|
10
|
+
label: "Search Ticker",
|
|
11
|
+
description: "Search for any ticker symbol — stocks, crypto, ETFs, indices, forex. Returns matching symbols with names and exchange info. Use this when you don't know the exact ticker for an asset.",
|
|
12
|
+
parameters: params,
|
|
13
|
+
async execute(toolCallId, args) {
|
|
14
|
+
const url = `https://query1.finance.yahoo.com/v1/finance/search?q=${encodeURIComponent(args.query)}"esCount=10&newsCount=0`;
|
|
15
|
+
const data = await httpGet(url, {
|
|
16
|
+
headers: { "User-Agent": "OpenCandle/1.0" },
|
|
17
|
+
});
|
|
18
|
+
const quotes = data.quotes ?? [];
|
|
19
|
+
if (quotes.length === 0) {
|
|
20
|
+
return {
|
|
21
|
+
content: [{ type: "text", text: `No results found for "${args.query}"` }],
|
|
22
|
+
details: quotes,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const lines = [
|
|
26
|
+
`**Search results for "${args.query}"** — ${quotes.length} matches`,
|
|
27
|
+
"",
|
|
28
|
+
...quotes.map((q) => ` ${q.symbol} — ${q.longname || q.shortname || "N/A"} (${q.quoteType}, ${q.exchange})`),
|
|
29
|
+
];
|
|
30
|
+
return { content: [{ type: "text", text: lines.join("\n") }], details: quotes };
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=search-ticker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-ticker.js","sourceRoot":"","sources":["../../../src/tools/market/search-ticker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACzB,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,WAAW,EAAE,0GAA0G;KACxH,CAAC;CACH,CAAC,CAAC;AAaH,MAAM,CAAC,MAAM,gBAAgB,GAA6B;IACxD,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,eAAe;IACtB,WAAW,EACT,yLAAyL;IAC3L,UAAU,EAAE,MAAM;IAClB,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI;QAC5B,MAAM,GAAG,GAAG,wDAAwD,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,6BAA6B,CAAC;QAChI,MAAM,IAAI,GAAG,MAAM,OAAO,CAAsB,GAAG,EAAE;YACnD,OAAO,EAAE,EAAE,YAAY,EAAE,gBAAgB,EAAE;SAC5C,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;QACjC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;gBACzE,OAAO,EAAE,MAAM;aAChB,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,GAAG;YACZ,yBAAyB,IAAI,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,UAAU;YACnE,EAAE;YACF,GAAG,MAAM,CAAC,GAAG,CACX,CAAC,CAAC,EAAE,EAAE,CACJ,KAAK,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,SAAS,IAAI,KAAK,KAAK,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,QAAQ,GAAG,CAC1F;SACF,CAAC;QAEF,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClF,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
import type { OHLCV } from "../../types/market.js";
|
|
3
|
+
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
|
+
symbol: import("@sinclair/typebox").TString;
|
|
5
|
+
range: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
6
|
+
interval: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const stockHistoryTool: AgentTool<typeof params, OHLCV[]>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { getHistory } from "../../providers/yahoo-finance.js";
|
|
3
|
+
const params = Type.Object({
|
|
4
|
+
symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT)" }),
|
|
5
|
+
range: Type.Optional(Type.String({
|
|
6
|
+
description: "Time range: 1d, 5d, 1mo, 3mo, 6mo, 1y, 2y, 5y, max. Default: 6mo",
|
|
7
|
+
})),
|
|
8
|
+
interval: Type.Optional(Type.String({
|
|
9
|
+
description: "Data interval: 1m, 5m, 15m, 1h, 1d, 1wk, 1mo. Default: 1d",
|
|
10
|
+
})),
|
|
11
|
+
});
|
|
12
|
+
export const stockHistoryTool = {
|
|
13
|
+
name: "get_stock_history",
|
|
14
|
+
label: "Stock History",
|
|
15
|
+
description: "Get historical OHLCV (open, high, low, close, volume) data for a stock",
|
|
16
|
+
parameters: params,
|
|
17
|
+
async execute(toolCallId, args) {
|
|
18
|
+
const symbol = args.symbol.toUpperCase();
|
|
19
|
+
const range = args.range ?? "6mo";
|
|
20
|
+
const interval = args.interval ?? "1d";
|
|
21
|
+
const bars = await getHistory(symbol, range, interval);
|
|
22
|
+
const summary = [
|
|
23
|
+
`${symbol} — ${bars.length} bars (${range}, ${interval})`,
|
|
24
|
+
`Period: ${bars[0]?.date} to ${bars[bars.length - 1]?.date}`,
|
|
25
|
+
];
|
|
26
|
+
// Include last 10 bars as sample
|
|
27
|
+
const recent = bars.slice(-10);
|
|
28
|
+
const table = recent
|
|
29
|
+
.map((b) => `${b.date} | O:${b.open.toFixed(2)} H:${b.high.toFixed(2)} L:${b.low.toFixed(2)} C:${b.close.toFixed(2)} V:${b.volume.toLocaleString()}`)
|
|
30
|
+
.join("\n");
|
|
31
|
+
const text = [...summary, "", "Recent bars:", table].join("\n");
|
|
32
|
+
return { content: [{ type: "text", text }], details: bars };
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=stock-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stock-history.js","sourceRoot":"","sources":["../../../src/tools/market/stock-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAG9D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACzB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WA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AAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,EAAE,CAC3I;aACA,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,EAAE,EAAE,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC9D,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
import type { StockQuote } from "../../types/market.js";
|
|
3
|
+
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
|
+
symbol: import("@sinclair/typebox").TString;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const stockQuoteTool: AgentTool<typeof params, StockQuote>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { getQuote } from "../../providers/yahoo-finance.js";
|
|
3
|
+
const params = Type.Object({
|
|
4
|
+
symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT, TSLA)" }),
|
|
5
|
+
});
|
|
6
|
+
export const stockQuoteTool = {
|
|
7
|
+
name: "get_stock_quote",
|
|
8
|
+
label: "Stock Quote",
|
|
9
|
+
description: "Get real-time stock price, volume, market cap, and 52-week range for a ticker symbol",
|
|
10
|
+
parameters: params,
|
|
11
|
+
async execute(toolCallId, args) {
|
|
12
|
+
const quote = await getQuote(args.symbol.toUpperCase());
|
|
13
|
+
const sign = quote.changePercent >= 0 ? "+" : "";
|
|
14
|
+
const text = [
|
|
15
|
+
`${quote.symbol}: $${quote.price.toFixed(2)} (${sign}${quote.changePercent.toFixed(2)}%)`,
|
|
16
|
+
`Open: $${quote.open.toFixed(2)} | High: $${quote.high.toFixed(2)} | Low: $${quote.low.toFixed(2)}`,
|
|
17
|
+
`Volume: ${quote.volume.toLocaleString()} | Market Cap: $${formatLargeNumber(quote.marketCap)}`,
|
|
18
|
+
`52W Range: $${quote.week52Low.toFixed(2)} - $${quote.week52High.toFixed(2)}`,
|
|
19
|
+
].join("\n");
|
|
20
|
+
return { content: [{ type: "text", text }], details: quote };
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
function formatLargeNumber(n) {
|
|
24
|
+
if (n >= 1e12)
|
|
25
|
+
return `${(n / 1e12).toFixed(2)}T`;
|
|
26
|
+
if (n >= 1e9)
|
|
27
|
+
return `${(n / 1e9).toFixed(2)}B`;
|
|
28
|
+
if (n >= 1e6)
|
|
29
|
+
return `${(n / 1e6).toFixed(2)}M`;
|
|
30
|
+
return n.toLocaleString();
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=stock-quote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stock-quote.js","sourceRoot":"","sources":["../../../src/tools/market/stock-quote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAG5D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACzB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,6CAA6C,EAAE,CAAC;CACpF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAyC;IAClE,IAAI,EAAE,iBAAiB;IACvB,KAAK,EAAE,aAAa;IACpB,WAAW,EACT,sFAAsF;IACxF,UAAU,EAAE,MAAM;IAClB,KAAK,CAAC,OAAO,CA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AC,CAAC,CAAC,GAAG,CAAC;IAChD,IAAI,CAAC,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IAChD,OAAO,CAAC,CAAC,cAAc,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Greeks } from "../../types/options.js";
|
|
2
|
+
interface GreeksInput {
|
|
3
|
+
type: "call" | "put";
|
|
4
|
+
spot: number;
|
|
5
|
+
strike: number;
|
|
6
|
+
timeYears: number;
|
|
7
|
+
iv: number;
|
|
8
|
+
riskFreeRate: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Compute option Greeks using the Black-Scholes model.
|
|
12
|
+
*/
|
|
13
|
+
export declare function computeGreeks(input: GreeksInput): Greeks;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute option Greeks using the Black-Scholes model.
|
|
3
|
+
*/
|
|
4
|
+
export function computeGreeks(input) {
|
|
5
|
+
const { type, spot, strike, timeYears, iv, riskFreeRate: r } = input;
|
|
6
|
+
// At expiration: return intrinsic values
|
|
7
|
+
if (timeYears <= 0) {
|
|
8
|
+
const isCall = type === "call";
|
|
9
|
+
const itm = isCall ? spot >= strike : spot <= strike;
|
|
10
|
+
return {
|
|
11
|
+
delta: itm ? (isCall ? 1 : -1) : 0,
|
|
12
|
+
gamma: 0,
|
|
13
|
+
theta: 0,
|
|
14
|
+
vega: 0,
|
|
15
|
+
rho: 0,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const sqrtT = Math.sqrt(timeYears);
|
|
19
|
+
const d1 = (Math.log(spot / strike) + (r + (iv * iv) / 2) * timeYears) / (iv * sqrtT);
|
|
20
|
+
const d2 = d1 - iv * sqrtT;
|
|
21
|
+
const nd1 = cdf(d1);
|
|
22
|
+
const nd2 = cdf(d2);
|
|
23
|
+
const npd1 = pdf(d1);
|
|
24
|
+
const expRT = Math.exp(-r * timeYears);
|
|
25
|
+
if (type === "call") {
|
|
26
|
+
return {
|
|
27
|
+
delta: nd1,
|
|
28
|
+
gamma: npd1 / (spot * iv * sqrtT),
|
|
29
|
+
theta: (-(spot * npd1 * iv) / (2 * sqrtT) - r * strike * expRT * nd2) / 365,
|
|
30
|
+
vega: (spot * npd1 * sqrtT) / 100, // per 1% change in IV
|
|
31
|
+
rho: (strike * timeYears * expRT * nd2) / 100, // per 1% change in rate
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const nMinusD1 = cdf(-d1);
|
|
36
|
+
const nMinusD2 = cdf(-d2);
|
|
37
|
+
return {
|
|
38
|
+
delta: nd1 - 1,
|
|
39
|
+
gamma: npd1 / (spot * iv * sqrtT),
|
|
40
|
+
theta: (-(spot * npd1 * iv) / (2 * sqrtT) + r * strike * expRT * nMinusD2) / 365,
|
|
41
|
+
vega: (spot * npd1 * sqrtT) / 100,
|
|
42
|
+
rho: -(strike * timeYears * expRT * nMinusD2) / 100,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Standard normal cumulative distribution function */
|
|
47
|
+
function cdf(x) {
|
|
48
|
+
// Abramowitz and Stegun approximation 26.2.17
|
|
49
|
+
const a1 = 0.254829592;
|
|
50
|
+
const a2 = -0.284496736;
|
|
51
|
+
const a3 = 1.421413741;
|
|
52
|
+
const a4 = -1.453152027;
|
|
53
|
+
const a5 = 1.061405429;
|
|
54
|
+
const p = 0.3275911;
|
|
55
|
+
const sign = x < 0 ? -1 : 1;
|
|
56
|
+
const absX = Math.abs(x);
|
|
57
|
+
const t = 1 / (1 + p * absX);
|
|
58
|
+
const y = 1 - ((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t * Math.exp(-absX * absX / 2);
|
|
59
|
+
return 0.5 * (1 + sign * y);
|
|
60
|
+
}
|
|
61
|
+
/** Standard normal probability density function */
|
|
62
|
+
function pdf(x) {
|
|
63
|
+
return Math.exp(-0.5 * x * x) / Math.sqrt(2 * Math.PI);
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=greeks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"greeks.js","sourceRoot":"","sources":["../../../src/tools/options/greeks.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAkB;IAC9C,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IAErE,yCAAyC;IACzC,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QACnB,MAAM,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC;QAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC;QACrD,OAAO;YACL,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAClC,KAAK,EAAE,CAAC;YACR,KAAK,EAAE,CAAC;YACR,IAAI,EAAE,CAAC;YACP,GAAG,EAAE,CAAC;SACP,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC;IACtF,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;IAE3B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AAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
import type { OptionsChain } from "../../types/options.js";
|
|
3
|
+
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
|
+
symbol: import("@sinclair/typebox").TString;
|
|
5
|
+
expiration: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
6
|
+
type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"call">, import("@sinclair/typebox").TLiteral<"put">, import("@sinclair/typebox").TLiteral<"CALL">, import("@sinclair/typebox").TLiteral<"PUT">]>>;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const optionChainTool: AgentTool<typeof params, OptionsChain>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { getOptionsChain } from "../../providers/yahoo-finance.js";
|
|
3
|
+
const params = Type.Object({
|
|
4
|
+
symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, TSLA, SPY, MSFT)" }),
|
|
5
|
+
expiration: Type.Optional(Type.String({
|
|
6
|
+
description: "Expiration date as YYYY-MM-DD. If omitted, uses the nearest expiration.",
|
|
7
|
+
})),
|
|
8
|
+
type: Type.Optional(Type.Union([Type.Literal("call"), Type.Literal("put"), Type.Literal("CALL"), Type.Literal("PUT")], {
|
|
9
|
+
description: "Filter by option type. Omit for both calls and puts.",
|
|
10
|
+
})),
|
|
11
|
+
});
|
|
12
|
+
export const optionChainTool = {
|
|
13
|
+
name: "get_option_chain",
|
|
14
|
+
label: "Options Chain",
|
|
15
|
+
description: "Get the full options chain for a stock with strikes, bids, asks, volume, open interest, implied volatility, and computed Greeks (Delta, Gamma, Theta, Vega, Rho via Black-Scholes). No API key required.",
|
|
16
|
+
parameters: params,
|
|
17
|
+
async execute(toolCallId, args) {
|
|
18
|
+
const symbol = args.symbol.toUpperCase();
|
|
19
|
+
const normalizedType = args.type?.toLowerCase();
|
|
20
|
+
const expirationTs = args.expiration
|
|
21
|
+
? Math.floor(new Date(args.expiration).getTime() / 1000)
|
|
22
|
+
: undefined;
|
|
23
|
+
const chain = await getOptionsChain(symbol, expirationTs);
|
|
24
|
+
const lines = [
|
|
25
|
+
`**${chain.symbol} Options Chain** — Expiry: ${chain.expirationDate}`,
|
|
26
|
+
`Underlying: $${chain.underlyingPrice.toFixed(2)}`,
|
|
27
|
+
`Available expirations: ${chain.expirationDates.slice(0, 6).join(", ")}${chain.expirationDates.length > 6 ? ` (+${chain.expirationDates.length - 6} more)` : ""}`,
|
|
28
|
+
"",
|
|
29
|
+
];
|
|
30
|
+
const showCalls = !normalizedType || normalizedType === "call";
|
|
31
|
+
const showPuts = !normalizedType || normalizedType === "put";
|
|
32
|
+
if (showCalls && chain.calls.length > 0) {
|
|
33
|
+
lines.push(`**CALLS** (${chain.calls.length} contracts, volume: ${chain.totalCallVolume.toLocaleString()})`);
|
|
34
|
+
lines.push("Strike | Bid/Ask | Last | Vol | OI | IV | Delta | Theta");
|
|
35
|
+
const topCalls = sortByVolume(chain.calls).slice(0, 10);
|
|
36
|
+
for (const c of topCalls) {
|
|
37
|
+
lines.push(formatContract(c));
|
|
38
|
+
}
|
|
39
|
+
lines.push("");
|
|
40
|
+
}
|
|
41
|
+
if (showPuts && chain.puts.length > 0) {
|
|
42
|
+
lines.push(`**PUTS** (${chain.puts.length} contracts, volume: ${chain.totalPutVolume.toLocaleString()})`);
|
|
43
|
+
lines.push("Strike | Bid/Ask | Last | Vol | OI | IV | Delta | Theta");
|
|
44
|
+
const topPuts = sortByVolume(chain.puts).slice(0, 10);
|
|
45
|
+
for (const c of topPuts) {
|
|
46
|
+
lines.push(formatContract(c));
|
|
47
|
+
}
|
|
48
|
+
lines.push("");
|
|
49
|
+
}
|
|
50
|
+
lines.push(`Put/Call Ratio: ${chain.putCallRatio.toFixed(2)}`);
|
|
51
|
+
return { content: [{ type: "text", text: lines.join("\n") }], details: chain };
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
function sortByVolume(contracts) {
|
|
55
|
+
return [...contracts].sort((a, b) => b.volume - a.volume);
|
|
56
|
+
}
|
|
57
|
+
function formatContract(c) {
|
|
58
|
+
const itm = c.inTheMoney ? "*" : " ";
|
|
59
|
+
return `${itm}$${c.strike.toFixed(2)} | $${c.bid.toFixed(2)}/$${c.ask.toFixed(2)} | $${c.lastPrice.toFixed(2)} | ${c.volume} | ${c.openInterest} | ${(c.impliedVolatility * 100).toFixed(1)}% | ${c.greeks.delta.toFixed(3)} | ${c.greeks.theta.toFixed(3)}`;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=option-chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option-chain.js","sourceRoot":"","sources":["../../../src/tools/options/option-chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAGnE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACzB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,kDAAkD,EAAE,CAAC;IACxF,UAAU,EAAE,IAAI,CAAC,QAAQ,CACvB,IAAI,CAAC,MAAM,CAAC;QACV,WAAW,EACT,yEAAyE;KAC5E,CAAC,CACH;IACD,IAAI,EAAE,IAAI,CAAC,QAAQ,CACjB,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE;QACjG,WAAW,EAAE,sDAAsD;KACp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E,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACjF,CAAC;CACF,CAAC;AAEF,SAAS,YAAY,CAAC,SAA2B;IAC/C,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,cAAc,CAAC,CAAiB;IACvC,MAAM,GAAG,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IACrC,OAAO,GAAG,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,YAAY,MAAM,CAAC,CAAC,CAAC,iBAAiB,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/P,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
import type { OHLCV } from "../../types/market.js";
|
|
3
|
+
export declare function computeCorrelation(returnsA: number[], returnsB: number[]): number;
|
|
4
|
+
export declare function alignReturnsByDate(historiesBySymbol: Map<string, OHLCV[]>, minOverlap?: number): Map<string, number[]>;
|
|
5
|
+
declare const params: import("@sinclair/typebox").TObject<{
|
|
6
|
+
symbols: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
|
|
7
|
+
period: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const correlationTool: AgentTool<typeof params>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { getHistory } from "../../providers/yahoo-finance.js";
|
|
3
|
+
import { computeDailyReturns } from "./risk-analysis.js";
|
|
4
|
+
export function computeCorrelation(returnsA, returnsB) {
|
|
5
|
+
const n = Math.min(returnsA.length, returnsB.length);
|
|
6
|
+
if (n === 0)
|
|
7
|
+
return 0;
|
|
8
|
+
let sumA = 0, sumB = 0;
|
|
9
|
+
for (let i = 0; i < n; i++) {
|
|
10
|
+
sumA += returnsA[i];
|
|
11
|
+
sumB += returnsB[i];
|
|
12
|
+
}
|
|
13
|
+
const meanA = sumA / n;
|
|
14
|
+
const meanB = sumB / n;
|
|
15
|
+
let cov = 0, varA = 0, varB = 0;
|
|
16
|
+
for (let i = 0; i < n; i++) {
|
|
17
|
+
const dA = returnsA[i] - meanA;
|
|
18
|
+
const dB = returnsB[i] - meanB;
|
|
19
|
+
cov += dA * dB;
|
|
20
|
+
varA += dA * dA;
|
|
21
|
+
varB += dB * dB;
|
|
22
|
+
}
|
|
23
|
+
if (varA === 0 || varB === 0)
|
|
24
|
+
return 0;
|
|
25
|
+
return cov / Math.sqrt(varA * varB);
|
|
26
|
+
}
|
|
27
|
+
const DEFAULT_MIN_OVERLAP = 20;
|
|
28
|
+
export function alignReturnsByDate(historiesBySymbol, minOverlap = DEFAULT_MIN_OVERLAP) {
|
|
29
|
+
// Build date → close price maps for each symbol
|
|
30
|
+
const priceByDate = new Map();
|
|
31
|
+
for (const [symbol, bars] of historiesBySymbol) {
|
|
32
|
+
const dateMap = new Map();
|
|
33
|
+
for (const bar of bars) {
|
|
34
|
+
dateMap.set(bar.date, bar.close);
|
|
35
|
+
}
|
|
36
|
+
priceByDate.set(symbol, dateMap);
|
|
37
|
+
}
|
|
38
|
+
// Find common dates across all symbols
|
|
39
|
+
const symbols = [...historiesBySymbol.keys()];
|
|
40
|
+
const firstDates = priceByDate.get(symbols[0]);
|
|
41
|
+
const commonDates = [...firstDates.keys()].filter((date) => symbols.every((s) => priceByDate.get(s).has(date))).sort();
|
|
42
|
+
if (commonDates.length < minOverlap) {
|
|
43
|
+
throw new Error(`Insufficient date overlap for correlation: ${commonDates.length} common dates (need ${minOverlap}+). Symbols may trade on different exchanges or have sparse history.`);
|
|
44
|
+
}
|
|
45
|
+
// Extract aligned close prices, then compute returns
|
|
46
|
+
const result = new Map();
|
|
47
|
+
for (const symbol of symbols) {
|
|
48
|
+
const dateMap = priceByDate.get(symbol);
|
|
49
|
+
const alignedCloses = commonDates.map((d) => dateMap.get(d));
|
|
50
|
+
result.set(symbol, computeDailyReturns(alignedCloses));
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
const params = Type.Object({
|
|
55
|
+
symbols: Type.Array(Type.String(), {
|
|
56
|
+
description: "Array of 2+ ticker symbols to compute correlation matrix (e.g. ['AAPL','MSFT','GOOGL'])",
|
|
57
|
+
minItems: 2,
|
|
58
|
+
}),
|
|
59
|
+
period: Type.Optional(Type.String({ description: "Historical period: 6mo, 1y, 2y. Default: 1y" })),
|
|
60
|
+
});
|
|
61
|
+
export const correlationTool = {
|
|
62
|
+
name: "analyze_correlation",
|
|
63
|
+
label: "Correlation Matrix",
|
|
64
|
+
description: "Compute pairwise return correlations between 2+ stocks. Identifies highly correlated positions (|r| > 0.7) as concentration risk. Useful for portfolio diversification analysis.",
|
|
65
|
+
parameters: params,
|
|
66
|
+
async execute(toolCallId, args) {
|
|
67
|
+
const symbols = args.symbols.map((s) => s.toUpperCase());
|
|
68
|
+
const period = args.period ?? "1y";
|
|
69
|
+
if (symbols.length < 2) {
|
|
70
|
+
throw new Error("Need at least 2 symbols for correlation analysis.");
|
|
71
|
+
}
|
|
72
|
+
// Fetch history for all symbols in parallel
|
|
73
|
+
const histories = await Promise.all(symbols.map((s) => getHistory(s, period, "1d")));
|
|
74
|
+
const historiesBySymbol = new Map();
|
|
75
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
76
|
+
historiesBySymbol.set(symbols[i], histories[i]);
|
|
77
|
+
}
|
|
78
|
+
const returnsBySymbol = alignReturnsByDate(historiesBySymbol);
|
|
79
|
+
// Build correlation matrix
|
|
80
|
+
const matrix = {};
|
|
81
|
+
const warnings = [];
|
|
82
|
+
for (const a of symbols) {
|
|
83
|
+
matrix[a] = {};
|
|
84
|
+
for (const b of symbols) {
|
|
85
|
+
if (a === b) {
|
|
86
|
+
matrix[a][b] = 1.0;
|
|
87
|
+
}
|
|
88
|
+
else if (matrix[b]?.[a] != null) {
|
|
89
|
+
matrix[a][b] = matrix[b][a];
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const r = computeCorrelation(returnsBySymbol.get(a), returnsBySymbol.get(b));
|
|
93
|
+
matrix[a][b] = r;
|
|
94
|
+
if (Math.abs(r) > 0.7 && a < b) {
|
|
95
|
+
warnings.push(`${a}/${b}: r=${r.toFixed(2)} — high correlation, concentration risk`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Format output
|
|
101
|
+
const header = `**Correlation Matrix** (${period} daily returns)`;
|
|
102
|
+
const colHeader = `${"".padEnd(8)} ${symbols.map((s) => s.padStart(8)).join("")}`;
|
|
103
|
+
const rows = symbols.map((a) => {
|
|
104
|
+
const cells = symbols.map((b) => matrix[a][b].toFixed(2).padStart(8));
|
|
105
|
+
return `${a.padEnd(8)} ${cells.join("")}`;
|
|
106
|
+
});
|
|
107
|
+
const lines = [header, "", colHeader, ...rows];
|
|
108
|
+
if (warnings.length > 0) {
|
|
109
|
+
lines.push("", "**Concentration Warnings:**");
|
|
110
|
+
for (const w of warnings)
|
|
111
|
+
lines.push(` - ${w}`);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
lines.push("", "No high-correlation pairs detected. Portfolio appears diversified.");
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
content: [{ type: "text", text: lines.join("\n") }],
|
|
118
|
+
details: { matrix, warnings },
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=correlation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correlation.js","sourceRoot":"","sources":["../../../src/tools/portfolio/correlation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD,MAAM,UAAU,kBAAkB,CAAC,QAAkB,EAAE,QAAkB;IACvE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAEtB,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC;IACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC;IACvB,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC;IAEvB,IAAI,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC;IAChC,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CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YACtE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QAC5C,CAAC,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;QAC/C,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,6BAA6B,CAAC,CAAC;YAC9C,KAAK,MAAM,CAAC,IAAI,QAAQ;gBAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACnD,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,oEAAoE,CAAC,CAAC;QACvF,CAAC;QAED,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;SAC9B,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
export interface Prediction {
|
|
3
|
+
symbol: string;
|
|
4
|
+
direction: "bullish" | "bearish" | "neutral";
|
|
5
|
+
conviction: number;
|
|
6
|
+
entryPrice: number;
|
|
7
|
+
targetPrice?: number;
|
|
8
|
+
date: string;
|
|
9
|
+
expiresAt: string;
|
|
10
|
+
timeframeDays: number;
|
|
11
|
+
}
|
|
12
|
+
export interface PredictionCheckResult {
|
|
13
|
+
total: number;
|
|
14
|
+
open: number;
|
|
15
|
+
correct: number;
|
|
16
|
+
wrong: number;
|
|
17
|
+
hitRate: number;
|
|
18
|
+
weightedHitRate: number;
|
|
19
|
+
details: Array<{
|
|
20
|
+
symbol: string;
|
|
21
|
+
direction: string;
|
|
22
|
+
conviction: number;
|
|
23
|
+
entryPrice: number;
|
|
24
|
+
currentPrice: number;
|
|
25
|
+
pnlPercent: number;
|
|
26
|
+
correct: boolean;
|
|
27
|
+
status: "open" | "resolved";
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
export declare function recordPrediction(params: {
|
|
31
|
+
symbol: string;
|
|
32
|
+
direction: "bullish" | "bearish" | "neutral";
|
|
33
|
+
conviction: number;
|
|
34
|
+
entryPrice: number;
|
|
35
|
+
targetPrice?: number;
|
|
36
|
+
timeframeDays: number;
|
|
37
|
+
}): Prediction;
|
|
38
|
+
export declare function checkPredictions(predictions: Prediction[], currentPrices: Map<string, number>, now?: Date): PredictionCheckResult;
|
|
39
|
+
declare const params: import("@sinclair/typebox").TObject<{
|
|
40
|
+
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"record">, import("@sinclair/typebox").TLiteral<"check">]>;
|
|
41
|
+
symbol: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
42
|
+
direction: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"bullish">, import("@sinclair/typebox").TLiteral<"bearish">, import("@sinclair/typebox").TLiteral<"neutral">]>>;
|
|
43
|
+
conviction: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
44
|
+
entry_price: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
45
|
+
target_price: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
46
|
+
timeframe_days: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
47
|
+
}>;
|
|
48
|
+
export declare const predictionsTool: AgentTool<typeof params>;
|
|
49
|
+
export {};
|