Millburn interview question

Coding implementation in R