Creating a scores table with recarray
The
recarray
class is a subclass of ndarray
. They can hold records like in a database, with different data types. For instance, we can store records about employees, containing numerical data such as salary, and strings such as the employee name.
Modern economic theory tells us that an investing
boils down to optimizing risk and reward. Risk is represented by the standard
deviation of log returns (for more information on Arithmetic and logarithmic return visit http://en.wikipedia.org/wiki/Rate_of_return#Arithmetic_and_logarithmic_return). Reward on the other hand, is represented by the average of log returns. We can come up with a relative score, where a high score means low risk and high reward. We will calculate the scores for several stocks and store them together with the stock symbol using a table format in a NumPy recarray
function.
How to do it...
We will start by creating the record array.
Create the record array.
Create a record array with for...