UNPKG

meridianalgo-js

Version:

Advanced algorithmic trading library for Node.js & TypeScript with 100+ technical indicators, pattern recognition, and risk management tools.

242 lines 8.44 kB
/** * Performance Metrics and Risk Management * * This module provides performance metrics and risk management utilities for * quantitative finance applications including Sharpe ratio, Sortino ratio, * maximum drawdown, and other risk-adjusted return metrics. * * @fileoverview Performance metrics and risk management utilities * @author MeridianAlgo * @version 1.0.0 */ /** * Sharpe Ratio * * The Sharpe ratio measures the risk-adjusted return of an investment. * It's calculated as (portfolio return - risk-free rate) / standard deviation of returns. * * @param returns - Array of returns * @param riskFreeRate - Risk-free rate (default: 0.02 for 2% annual) * @param annualized - Whether to annualize the ratio (default: true) * @returns Sharpe ratio value * * @example * ```typescript * const returns = [0.01, 0.02, -0.01, 0.03, 0.015]; * const sharpe = PerformanceMetrics.sharpeRatio(returns); * ``` */ export declare function sharpeRatio(returns: number[], riskFreeRate?: number, annualized?: boolean): number; /** * Sortino Ratio * * The Sortino ratio is similar to the Sharpe ratio but only considers downside deviation. * It's calculated as (portfolio return - risk-free rate) / downside deviation. * * @param returns - Array of returns * @param riskFreeRate - Risk-free rate (default: 0.02 for 2% annual) * @param annualized - Whether to annualize the ratio (default: true) * @returns Sortino ratio value */ export declare function sortinoRatio(returns: number[], riskFreeRate?: number, annualized?: boolean): number; /** * Maximum Drawdown * * Maximum drawdown is the largest peak-to-trough decline in the value of a portfolio. * It's expressed as a percentage and measures the worst loss from a peak. * * @param prices - Array of price data * @returns Object containing maximum drawdown and related metrics */ export declare function maxDrawdown(prices: number[]): { maxDrawdown: number; maxDrawdownPercent: number; drawdownStart: number; drawdownEnd: number; recoveryTime: number; }; /** * Calmar Ratio * * The Calmar ratio is the annualized return divided by the maximum drawdown. * It measures risk-adjusted returns relative to the worst loss. * * @param returns - Array of returns * @param maxDrawdownPercent - Maximum drawdown percentage * @returns Calmar ratio value */ export declare function calmarRatio(returns: number[], maxDrawdownPercent: number): number; /** * Information Ratio * * The Information ratio measures the excess return per unit of tracking error. * It's calculated as (portfolio return - benchmark return) / tracking error. * * @param portfolioReturns - Array of portfolio returns * @param benchmarkReturns - Array of benchmark returns * @returns Information ratio value */ export declare function informationRatio(portfolioReturns: number[], benchmarkReturns: number[]): number; /** * Value at Risk (VaR) * * VaR measures the potential loss in value of a portfolio over a defined period * for a given confidence interval. * * @param returns - Array of returns * @param confidence - Confidence level (default: 0.05 for 95% VaR) * @param method - Method for calculating VaR ('historical' or 'parametric') * @returns VaR value */ export declare function valueAtRisk(returns: number[], confidence?: number, method?: 'historical' | 'parametric'): number; /** * Conditional Value at Risk (CVaR) * * CVaR, also known as Expected Shortfall, is the expected loss given that * the loss exceeds the VaR threshold. * * @param returns - Array of returns * @param confidence - Confidence level (default: 0.05 for 95% CVaR) * @returns CVaR value */ export declare function conditionalValueAtRisk(returns: number[], confidence?: number): number; /** * Beta * * Beta measures the sensitivity of a portfolio's returns to market returns. * A beta of 1 means the portfolio moves with the market. * * @param portfolioReturns - Array of portfolio returns * @param marketReturns - Array of market returns * @returns Beta value */ export declare function beta(portfolioReturns: number[], marketReturns: number[]): number; /** * Alpha * * Alpha measures the excess return of a portfolio relative to the return * predicted by the Capital Asset Pricing Model (CAPM). * * @param portfolioReturns - Array of portfolio returns * @param marketReturns - Array of market returns * @param riskFreeRate - Risk-free rate (default: 0.02 for 2% annual) * @returns Alpha value */ export declare function alpha(portfolioReturns: number[], marketReturns: number[], riskFreeRate?: number): number; /** * Treynor Ratio * * The Treynor ratio measures risk-adjusted returns relative to systematic risk (beta). * It's calculated as (portfolio return - risk-free rate) / beta. * * @param returns - Array of returns * @param betaValue - Beta value of the portfolio * @param riskFreeRate - Risk-free rate (default: 0.02 for 2% annual) * @returns Treynor ratio value */ export declare function treynorRatio(returns: number[], betaValue: number, riskFreeRate?: number): number; /** * Jensen's Alpha * * Jensen's Alpha is the same as the regular alpha but is often used in the context * of evaluating fund managers' performance. * * @param portfolioReturns - Array of portfolio returns * @param marketReturns - Array of market returns * @param riskFreeRate - Risk-free rate (default: 0.02 for 2% annual) * @returns Jensen's Alpha value */ export declare function jensensAlpha(portfolioReturns: number[], marketReturns: number[], riskFreeRate?: number): number; /** * Tracking Error * * Tracking error measures the standard deviation of the difference between * portfolio returns and benchmark returns. * * @param portfolioReturns - Array of portfolio returns * @param benchmarkReturns - Array of benchmark returns * @returns Tracking error value */ export declare function trackingError(portfolioReturns: number[], benchmarkReturns: number[]): number; /** * Win Rate * * Calculates the percentage of positive returns in a series. * * @param returns - Array of returns * @returns Win rate as a percentage */ export declare function winRate(returns: number[]): number; /** * Average Win/Loss * * Calculates the average win and average loss from a series of returns. * * @param returns - Array of returns * @returns Object containing average win and average loss */ export declare function averageWinLoss(returns: number[]): { averageWin: number; averageLoss: number; }; /** * Profit Factor * * Profit factor is the ratio of gross profit to gross loss. * A value greater than 1 indicates profitability. * * @param returns - Array of returns * @returns Profit factor value */ export declare function profitFactor(returns: number[]): number; /** * Comprehensive performance analysis * * @param prices - Array of price data * @param benchmarkPrices - Array of benchmark price data (optional) * @param riskFreeRate - Risk-free rate (default: 0.02 for 2% annual) * @returns Object containing all performance metrics */ export declare function performanceAnalysis(prices: number[], benchmarkPrices?: number[], riskFreeRate?: number): { totalReturn: number; annualizedReturn: number; volatility: number; sharpeRatio: number; sortinoRatio: number; maxDrawdown: number; calmarRatio: number; winRate: number; profitFactor: number; averageWinLoss: { averageWin: number; averageLoss: number; }; var95: number; cvar95: number; beta?: number; alpha?: number; informationRatio?: number; trackingError?: number; }; /** * Collection of performance metrics and risk management utilities */ export declare const PerformanceMetrics: { sharpeRatio: typeof sharpeRatio; sortinoRatio: typeof sortinoRatio; maxDrawdown: typeof maxDrawdown; calmarRatio: typeof calmarRatio; informationRatio: typeof informationRatio; valueAtRisk: typeof valueAtRisk; conditionalValueAtRisk: typeof conditionalValueAtRisk; beta: typeof beta; alpha: typeof alpha; treynorRatio: typeof treynorRatio; jensensAlpha: typeof jensensAlpha; trackingError: typeof trackingError; winRate: typeof winRate; averageWinLoss: typeof averageWinLoss; profitFactor: typeof profitFactor; performanceAnalysis: typeof performanceAnalysis; }; //# sourceMappingURL=performance.d.ts.map