@railpath/finance-toolkit
Version:
Production-ready finance library for portfolio construction, risk analytics, quantitative metrics, and ML-based regime detection
95 lines (94 loc) • 2.61 kB
TypeScript
/**
* Linear System Solver Utilities
*
* Collection of utility functions for solving linear systems of equations,
* commonly used in mathematical optimization and portfolio analysis.
*/
/**
* Solve a linear system Ax = b using Gaussian elimination with partial pivoting
*
* @param A - Coefficient matrix (n×n)
* @param b - Right-hand side vector (n×1)
* @returns Solution vector x
*
* @example
* ```typescript
* const A = [[2, 1], [1, 3]];
* const b = [5, 8];
* const x = solveLinearSystem(A, b); // [1, 3]
* ```
*/
export declare function solveLinearSystem(A: number[][], b: number[]): number[];
/**
* Solve multiple linear systems with the same coefficient matrix
*
* @param A - Coefficient matrix (n×n)
* @param B - Matrix of right-hand sides (n×m)
* @returns Matrix of solutions (n×m)
*
* @example
* ```typescript
* const A = [[2, 1], [1, 3]];
* const B = [[5, 1], [8, 2]];
* const X = solveMultipleLinearSystems(A, B);
* ```
*/
export declare function solveMultipleLinearSystems(A: number[][], B: number[][]): number[][];
/**
* Calculate the determinant of a square matrix using LU decomposition
*
* @param A - Square matrix (n×n)
* @returns Determinant of the matrix
*
* @example
* ```typescript
* const A = [[2, 1], [1, 3]];
* const det = matrixDeterminant(A); // 5
* ```
*/
export declare function matrixDeterminant(A: number[][]): number;
/**
* Perform LU decomposition of a matrix
*
* @param A - Square matrix (n×n)
* @returns Object containing L, U matrices and permutation sign
*
* @example
* ```typescript
* const A = [[2, 1, 0], [1, 2, 1], [0, 1, 2]];
* const { L, U, sign } = luDecomposition(A);
* ```
*/
export declare function luDecomposition(A: number[][]): {
L: number[][];
U: number[][];
sign: number;
};
/**
* Check if a matrix is invertible (non-singular)
*
* @param A - Square matrix (n×n)
* @param tolerance - Tolerance for determinant check (default: 1e-12)
* @returns True if matrix is invertible
*
* @example
* ```typescript
* const A = [[2, 1], [1, 3]];
* const invertible = isMatrixInvertible(A); // true
* ```
*/
export declare function isMatrixInvertible(A: number[][], tolerance?: number): boolean;
/**
* Calculate the condition number of a matrix (ratio of largest to smallest singular value)
* Simplified implementation for 2x2 matrices
*
* @param A - Square matrix (n×n)
* @returns Condition number
*
* @example
* ```typescript
* const A = [[2, 1], [1, 3]];
* const cond = matrixConditionNumber(A);
* ```
*/
export declare function matrixConditionNumber(A: number[][]): number;