async function financialIntelligence(query: string, analysisType: "fundamental" | "technical" | "news") {
const sources = {
fundamental: ["valyu/valyu-stocks", "sec.gov", "investor.com"],
technical: ["valyu/valyu-stocks", "tradingview.com", "yahoo.com"],
news: ["bloomberg.com", "cnbc.com", "reuters.com", "marketwatch.com"]
};
const response = await valyu.search(query, {
searchType: analysisType === "fundamental" || analysisType === "technical" ? "all" : "web",
includedSources: sources[analysisType],
maxNumResults: 10,
responseLength: "medium",
category: "financial analysis"
});
if (response.success) {
console.log(`=== ${analysisType.toUpperCase()} Analysis ===`);
console.log(`Query: "${query}"`);
response.results.forEach((result, i) => {
console.log(`\n${i + 1}. ${result.title}`);
console.log(` Source: ${result.source}`);
console.log(` Relevance: ${result.relevance_score.toFixed(2)}`);
console.log(` URL: ${result.url}`);
// Show excerpt for financial data
if (result.content.length > 200) {
console.log(` Preview: ${result.content.substring(0, 200)}...`);
}
if (result.publication_date) {
console.log(` Date: ${result.publication_date}`);
}
});
return {
results: response.results,
analysisType,
query
};
}
return null;
}
// Usage examples - include timeframes in natural language
const teslaFundamentals = await financialIntelligence(
"Tesla financial performance Q3 2024 earnings revenue profit margins",
"fundamental"
);
const appleNews = await financialIntelligence(
"Apple latest news this week product announcements stock updates",
"news"
);
const bitcoinTechnical = await financialIntelligence(
"Bitcoin price analysis technical indicators support resistance levels recent trends",
"technical"
);