HESSIAN_MATRIX
Overview
Computes the Hessian matrix (second derivatives) of a scalar function with respect to its variables. This function enables business users to analyze curvature, perform advanced optimization, and understand the local behavior of functions directly in Excel. It leverages the CasADi package for symbolic and numeric differentiation, and is accessible via the Boardflare Python for Excel add-in.
The Hessian matrix of a scalar function with respect to variables is defined as:
or, in matrix form:
This function parses the symbolic expression, constructs symbolic variables, and uses CasADi to compute the Hessian matrix symbolically. The resulting Hessian is then evaluated at the provided point (the values for each variable) and returned as a 2D list. This allows for efficient and accurate computation of second-order derivatives, which are essential for optimization, sensitivity analysis, and understanding the curvature of functions.
Usage
To use the HESSIAN_MATRIX
function in Excel, enter it as a formula in a cell, specifying your function, variable values, and variable names:
=HESSIAN_MATRIX(expression, variables, [variable_names])
Arguments
Argument | Type | Required | Description | Example |
---|---|---|---|---|
expression | string | Yes | Symbolic expression for the scalar function. | "x**2 + 3*x*y + y**2" |
variables | 2D list float | Yes | Point at which to evaluate the Hessian (values for each variable). | [[1.0, 2.0]] |
variable_names | 2D list string | No | Names of the variables (if not inferred from the expression). | [["x", "y"]] |
Returns
Type | Description | Example |
---|---|---|
list[list[float]] | The Hessian matrix evaluated at the given point. | [[2.0, 3.0], [3.0, 2.0]] |
str | Error message if the calculation fails or input is invalid. | "Invalid input: expression must be a valid scalar function." |
Examples
Risk Analysis in Finance
Business context: A financial analyst wants to compute the Hessian of a risk function to understand how portfolio risk changes with respect to asset allocations.
Excel usage:
=HESSIAN_MATRIX("x**2 + 3*x*y + y**2", {1.0, 2.0}, {"x", "y"})
Expected outcome: Returns the Hessian matrix at the point (1.0, 2.0):
2.0 | 3.0 |
---|---|
3.0 | 2.0 |
Legend:
Engineering Design Sensitivity
Business context: An engineer analyzes the curvature of a cost function to assess sensitivity to design variables.
Live Notebook
Edit this function in a live notebook .