Corkscrew LAMBDA Template
Demystifying LAMBDA

Corkscrew LAMBDA Template

Create complex corkscrew calculations easily with this template.

What is the difference between complex Corkscrews and Simple Corkscrews?

A simple corkscrew has flows (a series of values such as Revenue or Expenses) that are independent of the opening balance. In simple corkscrews the flows are added or subtracted from an opening balance then summed to create a cumulative closing balance. That can be done with a simple SCAN() LAMBDA.

A complex corkscrew calculates flows based on the opening balance or some other flow which are then totaled to create an ending balance, which, because this is a corkscrew, is a cumulative balance, or running total. To perform this type of calculation requires a method like the one discussed here.

Can you show me an example?

An amortization schedule is a simple example of a complex corkscrew. We need the opening balance to calculate the interest amount. To do this with a dynamic array, we need to calculate each column one at a time and stack the results together horizontally. The animation below emphasizes the stacking of columns in this approach.

Stacking animation

We can do this with recursive LAMBDAs but using REDUCE() is simpler and easier to understand. Here is the template completed for a simple loan amortization schedule.

Corkscrew template completed for a simple amortization schedule

The parts of the template are:

  1. Calculate anything that is independent of the opening balance or other flows.
  2. Use REDUCE( initial value, array, lambda) to perform the period calculations. We do not need an initial value. The array is a column counter, which, in this example is a number for each month in the loan's Term.
  3. Extract single values from array arguments. In this example our opening balance will be the principal amount when processing the first column (n=1). For all other columns, the opening balance is the last period's closing balance which is in the last row and last column: TAKE( Accumulator, -1, -1).
  4. Perform period calculations.
  5. Vertically stack the values into a column.
  6. If this is the first column, the LAMBDA's result is the stacked column, otherwise, we horizontally stack the column against the prior columns.

The results of our LAMBDA() are placed in the Accumulator. Thus, the first time the LAMBDA() is called by REDUCE(), the LAMBDA() returns a single column. That goes in the Accumulator. The second time REDUCE() calls the LAMBDA(), the Accumulator has one column in it until the LAMBDA() finishes, at which time, the Accumulator will have two columns. This process continues until we have processed the last month in the Loan's term.

Summary

I use the 5g version of this template to quickly create many of my 5g functions. It is shown below. The 5g version contains inline help, version control, and lots of comments. If you intend for anyone other than yourself to use your LAMBDA, for their sakes, please consider following 5g standards. Want to know more about this template? See 5gModeling.Com

5g



蔡佳昊, CFA

帝国理工金融会计硕士(学术校长特别提名荣誉)

4 个月

Thanks for this, can you help me understand by why implementation doesn't split over one period?

  • 该图片无替代文字
回复
Paul Smith, CFA, CFM

Financial Modelling | Power BI | FMWC Multi-Award Winner |

9 个月

Won't pretend I understand all of that on a first take but can already see how powerful the potential of this is.

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

Craig Hatmaker的更多文章

  • Emulating Solver with LAMBDA

    Emulating Solver with LAMBDA

    Introduction Excel’s Solver is a powerful optimization tool, but some companies impose restrictions on its use. A…

    4 条评论
  • 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 条评论

社区洞察

其他会员也浏览了