In the previous recipe, we tried out a trading idea. However, we have no benchmark that can tell us whether the result we got was any good. It is common in such cases to trade at random under the assumption that we should be able to beat a random process. We will simulate trading by taking some random days from a trading year. This should illustrate working with random numbers using NumPy.
If necessary, install matplotlib. Refer to the See also section of the corresponding recipe.
The following is the complete code from the
random_periodic.py file in this book's code bundle:
from __future__ import print_function from matplotlib.finance import quotes_historical_yahoo from datetime import date ...