calculate_tema
Calculate the Triple Exponential Moving Average (TEMA) for financial market analysis using price data to identify trends and reduce lag in technical indicators.
Instructions
Calculate Triple Exponential Moving Average (TEMA).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kwargs | Yes |
Implementation Reference
- src/mcp_talib/core/server.py:322-334 (handler)The primary MCP tool handler for the 'calculate_tema' tool. It retrieves the TEMA indicator from the registry, creates MarketData from close prices, passes the timeperiod option, and returns the computation result.@mcp.tool() async def calculate_tema(close: List[float], timeperiod: int = 30) -> Dict[str, Any]: try: indicator = registry.get_indicator("tema") if not indicator: raise ValueError("TEMA indicator not found") market_data = MarketData(close=close) result = await indicator.calculate(market_data, {"timeperiod": timeperiod}) if result.success: return {"success": True, "values": result.values, "metadata": result.metadata} return {"success": False, "error": result.error_message} except Exception as e: return {"success": False, "error": str(e)}
- TOOL_SPECS definition providing schema, description, parameters, defaults, and market data mapping for the 'tema' indicator used in dynamic tool generation."tema": { "description": "Triple Exponential Moving Average (TEMA)", "params": {"close": List[float], "timeperiod": int}, "defaults": {"timeperiod": 30}, "market_data_args": {"close": "close"},
- src/mcp_talib/indicators/__init__.py:41-41 (registration)Registration of the TEMAIndicator in the global indicator registry, enabling lookup via registry.get_indicator('tema').registry.register("tema", TEMAIndicator)
- The TEMAIndicator class that implements the core computation using TA-Lib's TEMA function. This is called by the tool handler.class TEMAIndicator(BaseIndicator): def __init__(self): super().__init__(name="tema", description="Triple Exponential Moving Average (TEMA)") @property def input_schema(self) -> Dict[str, Any]: return {"type": "object", "properties": {"close_prices": {"type": "array", "items": {"type": "number"}}, "timeperiod": {"type": "integer", "default": 30}}, "required": ["close_prices"]} async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult: if options is None: options = {} timeperiod = options.get("timeperiod", 30) close = np.asarray(market_data.close, dtype=float) try: out = ta.TEMA(close, timeperiod=timeperiod) return IndicatorResult(indicator_name=self.name, success=True, values={"tema": out.tolist()}, metadata={"timeperiod": timeperiod, "input_points": len(close), "output_points": len(out)}) except Exception as e: return IndicatorResult(indicator_name=self.name, success=False, values={}, error_message=str(e))