Average return on investment over a year, given dates, investment, income and expense

I have columns with

) year, ascending

) month, ascending

) day, ascending

) investment, variable

) income, variable

) expense, variable

and I want to calculate the return on investment column, which I define as

cumulative investment averaged over a year back in time / ( cumulative income over a year back in time - cumulative expense over a year back in time)

How do I define such a column?

Please take a look on the financial functions help.

https://help.libreoffice.org/6.1/en-US/text/scalc/01/04060103.html?DbPAR=CALC#bm_id3143284