### ECO: Custom Operations, Investments and Net Present Value

So I extended ECO III a little bit and can check if an investment should be made or declined

**without a single line of code**. My OCL extentions also give you the ability to calculate the optimal interest rate your bank has to offer to you, so that you can proceed with your investment (change: called the internal rate of return, thanks Olaf for the translation assistance). Everything is based on the theory of the "net present value" (Wikipedia Germany has a detailed article on that e.g.).

Christmas triggers funny things sometimes, for me it was going back 4 years and reliving the worst exam I ever had to take: Monetary Policy. That's all I am going to say about that. At least I can implement the stuff as an ECO Custom OCL Operation, eh? :-)

I used my other extentions of the OCL language as well. Basically, I am building a huge library with custom operations. Right now, there is no real structure, which categories I am going to cover in the library. I simply implemented what came to mind and made sense to me.

Back to the investment application.

Let me show you the simple model. This model could be one building block of a huge financial application. Yes, it's only for demo purposes and it might be enhanced a lot. But it shows the power you have, when building custom operations in ECO. Remember: not a single line of code for the Winforms application that lets the user plan his or her investments needs to be written!

- we have one class for investments
- another for payments for the investments
- the idea is to create one "Payment" for every period that is to be considered in the calculation
- the number of payments determines the total number of periods, we can consider this the asset depreciation range e.g.
- currencies are not modelled
- a "Payment" simply has an amount. Think of it as a yearly payment you get because of the initital investment to get started
- an investment has a name, an inital amount that has to be paid for the investment, an interest rate and "sellPrice" that stands for the money that will be earned for the investment being sold after the usage

I will continue by showing you the main form of the application. Remember these things: If the net present value is positive, go ahead. If negative, continue planning. The optimal interest rate can be calculated if you solve the equation for "Net Present Value equals 0".

What you see is one investment for a new computer. I bought a computer for 2000 bucks, which I sold after 4 years for 1000 bucks and my bank's interest rate is 8% over that period of time. Can I realize it? Yes, as the "net present value" is positive. Hmmm. What would be optimal? An interest rate of

`0,098051`, because the NPV is almost 0 at that interest rate. A note: I used a regula falsi approximation to solve the equation.

If you're not amazed by this... I sure am. Just think of the possibilities. I can easily build different scenarios with this application, compare them and consider all the consequences. Again: no code.

So, how does the OCL look? Not very complex. Here's a screenshot that shows how to calculate the optimal interest rate:

What do you think about custom operations now?

Furthermore, if anybody is interested in these extentions, let me know by commenting here. Suggestions are also welcome, of course.

## 4 Comments:

Way to go Holger! There are many a things that *OCL* lacks. ECO follows the OCL standard rather closely, thus ECO can in some way be said to lack several branches of mathemathics.

Luckily, and as you noticed, ECO is very forgiving and extensible in this area. I look forward to see OCL add-ons for trigonometry, matrix operations, statistics and who know where it ends (my vocabulary of cool-sounding mathematical words ended just there anyway :) ).

Merry xmas,

--Jesper

By Anonymous, at 12:11 PM

This looks very promising. i love the way you can stuff it all in the model and keep it together!

Are you going to sell these add-on's??

Rolf van der Toorn - Netherlands

By Anonymous, at 11:54 PM

Hi Rolf,

those custom OCL operations are just result of my very first experiments. I accumulated quite a few now, which make OCL more and more powerful and thus ECO even more handy to use.

I am in need of suggestions though what kind of operations are missing.

I might "release" the library at some point when I feel confident about it.

By Holger, at 4:08 PM

U need to Feed below values to ur object to calculate xIRR or xNPV

Principal

InitialAmt

CouponRate

PaymentCycle like Annually, SemiAnnually, Quarterly, Monthly, Daily, AtMaturity

PaymentMethod like 30/360 or Actual/Actual or Actual/360 or Actual/365

PaymentTime like End-of-Period or Start-of-Period

InitialDate

LastPayDate

MaturityDate

NPVDate

VariableRates

By Kiran Mahale, at 10:28 PM

Post a Comment

<< Home