  We consider the problem of dynamic buying and selling of shares from a
collection of $N$ stocks with random price fluctuations. To limit investment
risk, we place an upper bound on the total number of shares kept at any time.
Assuming that prices evolve according to an ergodic process with a mild
decaying memory property, and assuming constraints on the total number of
shares that can be bought and sold at any time, we develop a trading policy
that comes arbitrarily close to achieving the profit of an ideal policy that
has perfect knowledge of future events. Proximity to the optimal profit comes
with a corresponding tradeoff in the maximum required stock level and in the
timescales associated with convergence. We then consider arbitrary (possibly
non-ergodic) price processes, and show that the same algorithm comes close to
the profit of a frame based policy that can look a fixed number of slots into
the future. Our analysis uses techniques of Lyapunov Optimization that we
originally developed for stochastic network optimization problems.
