I have an existing python algorithm that I created awhile ago, outside of quantopian, and I have already backtested it with historical data from Yahoo's API and I know it should be profitable. I'm trying to wrap my head around how quantopian structures things so I can adapt my algorithm to work on the platform. The basic pattern is this:
On each trading day:
Step 1 -- Assuming there are N tradable stocks on a given day, I need a matrix of size Nx30. This matrix holds the past 30 days worth of close prices for each stock.
output = secret_sauce(price_matrix)
This function returns N subsets of stocks like: [['AAPL', 'GOOG', 'AMZN'], ['GOOG', 'TWTR', 'AMZN'], ... ]
I really need to have that Nx30 matrix all at once in order to use my algorithm.
Step 2 -- Then for each possible subset from above, I take the group that has the highest total return from the past 5 days.
Step 3 -- Rebalance the portfolio to be equally weighted amongst the chosen group.
Any help would be appreciated. How would I use this general structure in quantopian?
Thanks!