Computing optimal rebalance frequency for log-optimal portfolios in linear time