I am trying to do something that is simple and I think recursive loops should help, but so far they don’t. I can do this in Excel, but it is tedious and I’m hoping KNIME is the answer.
Basically I have a portfolio of 10 stocks with an initial investment of some number, say 100,000. Then at the end of the week it is sold. The amount of cash at the end of the week is reinvested in 10 other stocks, using the ending value of the previous week. This process continues for many weeks.
It is the ending value that I want to carry over to the next week, so that it is the starting value for the portfolio the next week. I could do the work on the portfolio by week using the Group Loop, but of course the value of the first week doesn’t feed back to the second week when it starts in the Group Loop.
I put a Recursive Loop within the Group Loop, but I must have done something wrong because the result is no different – the value of the portfolio does not get used by the next batch of rows in the Group Loop.
It seems this is like doing compound interest calculations, but I couldn’t find any examples using KNIME. I looked at all of the posts in the Forum about recursive loops, but couldn’t find something similar that would help.
Does anyone have any understandable examples of this kind of thing in KNIME? Thank you.
1 Like
Hi. I do similar calculations based on mutual funds. I do prefer java snippet for calculating these kind of compound returns. I think it can be done with recursive loops. I will be glad to help you. Do you have any structural data to start with?
1 Like
Hi,
Still, I went ahead and created a recursive loop example based on my own fund return data. Each week, the logic selects the top-performing fund from the previous week and invests in it for the current week. This process continues recursively: every week, it picks the top performer from the last week. The attached recursive loop ensures this flow.
That said, this is admittedly a more complex approach. Personally, I find it easier to handle such tasks using Java snippets.
In the collected_data
output of the recursive loop, you can observe:
- Which fund was selected each week based on past performance,
- What its return was for that week,
- How the accumulated return evolved,
- And how the position transitioned to the following week.
If you run the recursive loop using “Step Loop Execution”, you’ll get a clearer understanding of how the logic unfolds step by step.
Please feel free to reach out if you have any questions.
Best regards,
Alpay
SampleMFData.xlsx (408.8 KB)
Recursive Loop Sample.knwf (57.3 KB)
3 Likes
Thank you very much for your quick reply! What I’m trying to do is similar. I was hoping not to have to use Java, but I will try the workflow you sent.
1 Like
Hi, no problem. Just to clarify; I used recursive loop here as you were exploring. I meant I generally use java snippet in my workflows but not in this case it is solely based on recursive loop which carries compunded amount to next loop. If you have any questions let me know.
Best
Alpay
2 Likes