On the other hand, if you are using recursive-dynamic optimization rather than forward-looking optimization (this terminology after Babiker et al 2009), then the algorithm is straightforward.
Assuming an object-oriented language (like python), maintain a state-of-charge (SoC) object attribute, degrade it if necessary across each timestep for “leakage”, and then calculate the efficiency prior to finalizing the contribution of the object (in this case, a battery bank) to the step-local optimization problem. The efficiency may be any explicit (and not necessarily linear) function of SoC.
By the way, is this an oemof model question? If so, you could indicate that in your post and also apply an
oemof tag for others to search on. HTH Robbie.
Babiker, Mustafa, Angelo Gurgel, Sergey Paltsev, and John Reilly (2009). “Forward-looking versus recursive-dynamic modeling in climate policy analysis: a comparison”. Economic Modelling. 26 (6): 1341–1354. ISSN 0264-9993. doi:10.1016/j.econmod.2009.06.009.