Patrick van Beek wrote: > Roger/Devon, thanks for your insight. I am getting the impression > that if I am going to code them in J I will have to re-build my models > from scratch . > > The example I gave did not really highlight the issue I am having very > well, since there are no variable interpendancies. > > Say as well as the Contribution variable you have a following two > variables, Fund and InvestmentReturn and two input vectors q(t) and > i(t), with the variables defined as follows: > > Fund: > If t = 0 Then > Fund(t) = 0 > Else > Fund(t) = Fund (t-1) + Mtly_Contributon - Contribution(t) * q(t) + > InvestmentReturn(t) > > InvestmentReturn: > InvestmentReturn(t)=(Fund(t)+Mtly_Contributon )* i(t) > > The code given by Roger's to repoduce the contribution variable using > infix is extremely elegant. > > Is there a similarly elegantly way to code the above Fund and > InvestmentReturn variables in J without resorting to control > structures? > > If there is lots of looping involved I assume there is a performance > hit using an interpreted language J rather than a comiled language > like C?
This does not look right, and I suspect you are mixing up beginning and end year values. Fund(t) is the fund at beginning year t, starting from t=0. InvestmentReturn(t) is investment income in year t, and will be an end-year value. As in your code, it will depend on Fund(t) and Contribution(t). Your calculation of Fund(t) includes InvestmentReturn(t), but should instead include InvestmentReturn(t-1) (for t>0). I believe the code in system/packages/finance will do these calculations for you. On other matters: as previously said, you would be unlikely to get good J code by automatically translating specifications in simple pseudo-code. On the other hand, with experience in J, you could do such translations very quickly. Moreover, the resulting "J specifications" would be likely be much shorter and more readable than the original. I would not be much concerned that J is iterated, as for just about any actuarial/financial work, it is quite fast enough. Accuracy is usually much more important, and for that, J is a great tool. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
