Math problem. How to code `Xn+1 = Xn + Xn * S`

This would certainly benefit from a better explanation of your goal(s) with this.

Though the code you did post can (for the most part) be written with higher level primitives.

min_mid_price = Decimal.div("0.001", "2") |> Decimal.mult("0.123") |> then(&Decimal.sub("0.123", &1))
levels_total = 2 * 2 + 1
mid = div(levels_total, 2)

Decimal.new("1") 
|> Stream.iterate(&Decimal.sub(&1, Decimal.mult(&1, "0.001"))) 
|> Stream.take(100_000)
|> Stream.chunk_every(levels_total, 1)
|> Enum.find(fn list -> 
  list |> Enum.at(mid) |> Decimal.lt?(min_mid_price)
end)