• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Using dynamic arrays for investment schedule

niwaajjua

New Member
I need help creating dynamic arrays for the gain, the opening and closing balance in an investment schedule. I get a circular reference since all these columns are dependent on each other.
 

Attachments

  • investment schedule.xlsx
    18.2 KB · Views: 2

niwaajjua

It wasn't any request.
Did You tested Your file after ... You did something?
After I saved those values ....
Could You use something like this?
 

Attachments

  • investment schedule.xlsx
    18.7 KB · Views: 2
Here is a model that I have been using for over 20 years in Excel that lets you track individual stock performance. Use or Not. I think it does a great job for me.
 

Attachments

  • Investments.xlsx
    13.1 KB · Views: 1
You have already used the SCAN function to accumulate the Total Investment. What is different about the Closing Balance is that it requires access to two lots of series data, namely the 'In/Out' series and the 'Return' series. The key to such problems is to scan over a key series (I have used the Date), from which corresponding terms of the other series may be looked up (INDEX or XLOOKUP).
Code:
=SCAN(0,date,
    LAMBDA(c∕d, period,
        LET(
            rate,    XLOOKUP(period, date, Return),
            change,  XLOOKUP(period, date, InOut),
            balance, (change + c∕d) * (1 + rate),
            balance
        )
    )
)
Once the Closing Balance has been accumulated, the Opening Balances and Gains (or losses) are calculated from it using straightforward dynamic array formulas
Code:
openingBalance
= LET(
    c∕d, VSTACK(0, DROP(closingBalance, -1)),
    c∕d + InOut)
  )
 
gainLoss
= closingBalance - openingBalance

There is another way of passing multiple series as a single array and that is to use an array of functions; each function (a thunk) returns the series data for a given period in known order. To calculate the function (tuning it back to an array of values for a single period) requires an empty parameter string. I show that in green, but it most likely ranks as an 'advanced' technique.
Code:
= LET(
    dataϑ,  BYROW(periodData, LAMBDA(x, LAMBDA(x))),
    return, SCAN( 0, dataϑ,
        LAMBDA(c∕d, perioddataϑ,
            LET(
                rate,    INDEX(perioddataϑ(), 1),
                change,  INDEX(perioddataϑ(), 2),
                balance, (change + c∕d) * (1 + rate),
                balance
            )
        )
    ),
    return
  )
 

Attachments

  • investment schedule.xlsx
    28.1 KB · Views: 2
Back
Top