Emulating Solver with LAMBDA
Demystifying LAMBDA

Emulating Solver with LAMBDA

Introduction

Excel’s Solver is a powerful optimization tool, but some companies impose restrictions on its use. A friend of mine faced this challenge when his client asked him to recreate a financial model he had previously built using Solver, but without Solver, VBA, or enabling iterative calculations. Seeking an alternative, he wondered if Excel’s LAMBDA function could provide a solution.

Recursive LAMBDA functions can solve optimization problems like this dynamically. In this article, we’ll explore APRxNPVλ, a LAMBDA function that leverages recursion to determine the APR that yields the smallest NPV.

Problem Statement

Here is a example of the worksheet needing our attention.

In the above example, we have been tasked to find the effective APR (Annual Percentage Rate) on Bank Interest (Actual/360) which we can do by finding the rate at which the Net Present Value (NPV) of a given set of cash flows and discount factors is 0, or as close as we can get. Traditional methods, such as Solver, can find the APR by iteratively adjusting it to minimize our NPV calculation until any additional adjustments make no changes between iterations. The APRxNPVλ function replicates this process using recursion within Excel’s LAMBDA framework.


How APRxNPVλ Works

1. Initialization

  • The function starts by setting an initial APR of 0%.
  • It calculates the initial NPV using a helper function, NPVλ (how NPVλ works is not important to this discussion).
  • A large starting difference (100%) is set to ensure iteration begins.
  • We then 'call' the recursive function we defined in LET step: APRxNPV (No λ symbol).

2. Recursive Refinement

  • In each iteration: The APR is adjusted based on whether the NPV is positive or negative. If NPV is negative we have gone too low and we increase APR by half the previous difference. If NPV is positive we have gone to high and we decrease APR.
  • This continues until the APR stops changing, meaning the optimal solution has been found.


Breakdown of the LAMBDA Components

Here is the LAMBDA.

APRxNPVλ()

  • Like all LAMBDAs, we start by declaring arguments. These arguments are needed by NPVλ().
  • We then define the Recursive LAMBDA (APRxNPV) inside our host function. The host function (APRxNPVλ with a λ symbol) is not recursive (does not call itself). The interior recursive function calls itself until convergence is achieved.
  • NewAPR is the LET step that, based on NPV being positive or negative, adds or subtracts half the difference in APRs between iterations. We can see how this impacts NPV in the table at the bottom of this article.
  • Exit Condition: When Excel cannot detect any difference in APRs between iterations, the routine exits.


Why Use This Approach?

? No Need for Solver – Works in environments where Solver or add-ins are prohibited.

? Fully Dynamic – Updates automatically when input data changes.

? Embedded in a Single Cell – Eliminates external VBA or add-ins.


Conclusion

LAMBDA can emulate Excel's Solver feature when circumstances prohibit Solver's use.


Table of each iteration's results.

Here is what is produced with each iteration of APRxNPV. It clearly shows how the routine resolves to the smallest NPV until adjustments to APR make no difference.


carlos barboza

compliance reporting @ Natixis | spilledgraphics.com

1 天前

replacing SOLVER calculations with dynamic spilled results from LAMBDAs would be fantastic. ?? thanks for sharing this Craig. on image below, a practical use case for emulating SOLVER calculations; a Holt-Winters model to explain forecasting. a masterpiece by Kellogg Professor Sudhakar "Sid" Deshmukh

  • 该图片无替代文字
Ny Tsiory Rakotonanahary

Co-Fondateur at KAJY Partners, AFM, FMVA, MCGAO, MCCA, BIDA

1 天前

This is some hard topic you're tackling with LAMBDA. it would be really incredible if you could look at what can be done to replicate data table behavior. The lambda can be called WHATIF: WHATIF(target_cell, input_cell, input_new_value) I'm not sure if that's even possible. But if there is anyone who could make it work, you're most probably one of them! (A big fan of your works btw)

要查看或添加评论,请登录

Craig Hatmaker的更多文章

  • Rollingλ(): 5g Function for Rolling Calculations

    Rollingλ(): 5g Function for Rolling Calculations

    Introduction Excel's LAMBDA functions have opened up incredible possibilities. 5g functions are LAMBDA functions…

    10 条评论
  • TRIMRANGE() and Trim Refs

    TRIMRANGE() and Trim Refs

    I cringed when I first saw TRIMRANGE(). "Oh great," I thought, "another reason for people to avoid learning tables.

    6 条评论
  • Intro to LAMBDA - Lesson 16 - Simple Corkscrew

    Intro to LAMBDA - Lesson 16 - Simple Corkscrew

    I could use your help. I am preparing a virtual work session for FMI on "Intro to LAMBDA.

    13 条评论
  • Programming with LAMBDA - Prime Numbers

    Programming with LAMBDA - Prime Numbers

    LAMBDA makes Excel "Turing Complete." Virtually all programming languages are Turing complete.

    2 条评论
  • Timing LAMBDAs with LAMBDA

    Timing LAMBDAs with LAMBDA

    I recently created a 5g function. It worked great but two friends suggested faster ways to accomplish the same thing.

    2 条评论
  • Create a 5g Function: RunTotRowsλ()

    Create a 5g Function: RunTotRowsλ()

    NOTE! This article was written with assistance from Google's Gemini AI. Introduction In the world of Excel, complex…

    7 条评论
  • Live 5g Instruction

    Live 5g Instruction

    The only live 5g training session starts July 30th. Register here: https://maven.

    4 条评论
  • From Formulas to LAMBDAs

    From Formulas to LAMBDAs

    I have just completed creating a small class on converting a group of formulas into a single LAMBDA function. It is…

    1 条评论
  • Stairway to ... LAMBDA?

    Stairway to ... LAMBDA?

    I use Excel for everything. I need some stairs from my yard to the forest floor below.

    19 条评论
  • Corkscrew LAMBDA Template

    Corkscrew LAMBDA Template

    Create complex corkscrew calculations easily with this template. What is the difference between complex Corkscrews and…

    3 条评论