You are the only person responsible for designing your trading strategy, whatever you intend it to do. You can analyze all the data, make some sense out of it. Then, build a trading algorithm to extract from the data the information you want to make trading decisions.

When you write a stock trading program, it has two purposes. The first one is to show your methods were at least feasible and profitable over some past long term trading interval trading a sufficiently large number of stocks. It is relatively easy to show, a portfolio simulation will give the answers.

From the previous notes, the most important could be summarized in just a few equations. Whatever we do has to comply with these equations.

The portfolio payoff matrix equation: $$A(t) = A_0\, + \displaystyle{\sum_{i=1}^n} (H\,.^*\Delta{P}) $$

and its sibling which says exactly the same thing: $\,A(t) = A_0\, + n \cdot \bar x \quad $ with for objective: $\,\bar x > 0$.

Everything is included in these expressions, every trade over the life of a portfolio is accounted for, to the penny.

The main impact of: $\,n \cdot \bar x\,$, just as for the payoff matrix, is to reduce the output of a portfolio to the number of trades taken multiplied by the average profit per trade. That there be 1 or a million trades.

For any trading system with $\bar x > 0$, meaning with an average positive net profit per trade, there remains one goal: to make $\,n\,$ as large as one possibly can for any value of $\,\bar x$.

You deal with equations. And, the only state an equation can be in is: the equal sign stands or it does not. There are no other choices. There are no maybes, no in between, no ifs, no mights, or under certain circumstances. There is no in my opinion, no I guess, no trader psychology, no herd mentality, no sentiment whatsoever.

The equation is true or it is not. If you can write an equation down which expresses what you say, then to refute it, is to show the **not** equal sign. It goes for all the equations I present. Care is given before putting an equal sign in public view. Once you have an equal sign on the table, you have to live with it, or refute it.

The total output of a trading strategy is: $\,n \cdot \bar x\,$. It is the sum of all accumulated profits and losses over the entire holding period. But, you have only 2 variables, and for a specific output their product could remain constant, meaning that as $\bar x$ increases, $n$ decreases, as in the following chart.

http://alphapowertrading.com/images/divers/n_vs_average_x.png

The chart says for the same output, you could do a lot more work for no added benefit. The following: $n = 1,000,000$ trades with $\bar x = \$\,10$ in average profit per trade, has the same output as: $n = 500,000$ and $\bar x = \$\,20$ with **half** the trading activity and frictional costs.

This raises simple questions: where or how will you find $n$ trades having an average net profit of $\,\bar x \,$? Especially, if $n$ and $\,\bar x \,$ are all you have to work with.

You know you could add more trades for a given fixed $\bar x$. This would shift the curve upward in the above chart. Would this involve more risk? Probably so. But, here the question is being transformed into one of replication, as in: can you do more of the same? You have a trading strategy that generates an average profit of $\bar x$. Can you increase $n$? And, how far? What would be the impact if you do increase it? Where would you get the funds?

I want to design a stock trading strategy, adapted to Quantopian, that will answer to my vision of a trading system. I intend to use any tool available that can help increase performance. My objective is to achieve the following:

$$A(t) = A_0\, + \displaystyle{\sum_{i=1}^n }(H \cdot (1+g(t))^{t-1}\,.^*\Delta{P}) $$Alternatively, it should do the following as well: $\,A(t) = A_0\, + (1+g(t))^{t-1} \cdot n \cdot \bar x\,$, since as previously stated: $\sum_{i=1}^n (H\,.^*\Delta{P}) = n \cdot \bar x$.

The search for this function: $(1+g(t))^{t-1}$ is at the core of this methodology. You accept to gradually transform in time the market's expected payoff matrix into: $(1+g(t))^{t-1}\cdot \text{E}\,\lbrack\,{\sum_{i=1}^n (H_M}\,.^*\Delta{P})\,\rbrack$. And this is what will change your game.

It is an expression for $alpha$ generation, a premium above benchmark averages. Viewing the notion of $alpha$ as presented by Jensen in the late sixties, an expression for the portfolio manager's added skills with nowadays the assistance of his/her trading programs.

I find the stock selection method, though important, of a secondary nature. Sure, I will want to trade the higher capitalization stocks out there with positive prospects and sufficient liquidity. Even so, there will be thousands of probable choices with no way of preselecting the best of the group. Also, what is the use of a good stock selection if the trading strategy itself is not productive?

I will put the stock selection process on the backburner by accepting that the selection made will be adequate enough and justifiable. As if it were a selection that could have been made in real life for some reason or other. My interest will be in a fraction of what will be available anyway. I can always refine the process later. An anticipated beneficial side effect would be to improve portfolio performance even further due to the better stock selection process.

I will be dealing with $H$, the trading strategy. In a Buy $\&$ Hold scenario, a lot more attention would be put on the selection process. But here, the intention is to trade, and trade a lot over the lifespan of the trading portfolio. In such a case, the stock selection process itself might be a byproduct of the search for $\Delta p$. In the sense that you are looking for $\Delta p$'s first, and they are all attached to stocks which consequently become your stock selection.

$\Delta p$ is at the heart of the problem. A completed trade is: $q \cdot \Delta_i p$. What is left is finding ways to detect probable $\Delta p \,$'s, capture some of them, and get a positive average: $\,\bar x > 0$. This, within the mindset of also finding the largest possible $n$.

Now, the problem starts. The holding matrix $H$ contains the trading history, all inventory movements over the portfolio's lifespan. Each time a quantity of shares is added or subtracted from the ongoing inventory, it is recorded in this matrix, with $\Delta P\,$ holding the end prices of the trades. Therefore, $H = B\, .^-\, S$, where the $B$ and $S$ matrices are all the quantities bought or sold in each of the $j$ stocks over the entire life of the portfolio.

Elements of $H$ are given as: $h_{i,\,j} = h_{i-1,\,j} + (b_{i,\,j} - s_{i,\,j}) $. The size of $H$ is determined by the number of rows and the number of stocks $j$ traded. The matrix grows as trades and stocks are added to the portfolio. The trades have for sequence: $i = 1,\, \cdots,\, n$, with $\,n\,$ being the total number of trades.

My trading methods have for main objective to accumulate shares for the long term and trade over the process. Reinvesting accumulating profits generate a positive feedback loop. In itself, it can justify the $(1+g(t))^{t-1}$ function. It has for simple pre-conditions: $\,\bar x > 0$, and: $g(t) > 0$. You intend to grow, build a long term portfolio at a compounding rate of its own $g(t)$.

The original problem has somewhat changed. From the notion of finding procedures to extract profits and live with the results, it is now finding trade opportunities in the millions if feasible. The impact on the problem could be tremendous. It is not the search of a trading method, but the search of a method that will generate as high a number of profitable trades as possible. There is a distinct, although slight, difference in perception.

Question: how many trades can be offered by a 100-day moving average crossover system over a portfolio's lifetime? This is a major question since it tends to greatly limit $n$. On the other hand, your trading system could specialize in areas where $\bar x$ operates at a higher level, requiring a smaller $n$ than expected. See chart $\# 1$ above for the $\,n\,$, $\,\bar x\,$ mix. The objective will be to raise that curve to a higher level. To do so will require raising either $\,n\,$, $\,\bar x\,$ or both.

A moving average crossover system appears to limit the number of trades by its very nature. In the sense that the number of trades $n$ are counted, there is time between crossovers. The alternative in such a case is to increase the bet size which could have the same effect as increasing $\,n$. But that too has its limits. If I need to design trading strategies with a high number of trades, some of the commonly used trading techniques won't be enough by not offering a sufficient number of tradable opportunities.

Breaking it all down, it will go back to the definition of a single trade: $q \cdot \Delta p = x$. It is the outcome of a large number of trades that will average out to: $\frac {\sum ^n (q \cdot \Delta_i p)}{n} = \frac {n \cdot \bar x}{n} = \bar x$. And as previously stated, $\,\bar x\,$ can have an asymptotic limit depending on the trading strategy used.

The payoff matrix for a Buy $\&$ Hold is: $\sum_{i=1}^n (h_0I\,.^*\Delta_i{P})$, and by default will make you win the game just by holding for the duration. $h_0\,$ is the initial quantity purchased in each of the stocks in the portfolio, and $I$ is a one's matrix, composed entirely of ones. Each element of the payoff matrix will be: $h_{i,\,j} = h_{0,\,j} $. Quantities will remain constant for the duration. $\frac {h_{0,\,j} \,\cdot \sum ^n ( \Delta_i p_{i,\,j})}{n} = \frac {n \cdot \bar x}{n} = \bar x$. Here, $h_{0,\,j}$ can be seen as a vector of scalars: $h_{0,\,j} = q_{0,\,j} = b_{0,\,j}\,$. The initial quantity of shares purchased for each of the stocks in the initial portfolio.

A Buy $\&$ Hold portfolio should rise with the secular trend. It means $\,\bar x\,$ will be rising in time too, since $\,n\,$ was made a constant. The quantities of shares in inventory were fixed at $q_{0,\,j}$. Holding for longer time intervals would have a tendency of increasing the average profit per trade. All that might be required to profit from this upward bias is to wait, to sit on one's hands.

However, having a Buy $\&$ Hold portfolio will push portfolio performance toward market average. As stated previously, you want more, doing about the same as the general market is not enough, you want to outperform the market. It is why you are designing these trading programs, to do just that: outperform. Otherwise, what's the use?

What I see most often are stock trading strategies that operate on the premise of finding some kind of anomaly or pattern that the developer hopes will repeat in the future. He tries to select the best methods he has to do the job. But, it still is limiting in the sense that one is not looking to increase $n$ but simply to accept the generated $n$ as if looking only a one way to increase the end result: $\,n \cdot \bar x\,$. It's okay, but one should want more, and could do more.

The other purpose of designing a trading strategy is to have it go live once it has passed all the tests. Not just that it is debugged, does not crash or does not run wild. There are other tests to be conducted before releasing a trading strategy. Still, the ultimate purpose is to have it run live, to let it trade as instructed. To make you the profits anticipated by having the trading strategy behave about the same as it did on past data. You know that your trading strategy will be faced with totally unseen data, and will have to react properly as instructed. Unless, the program itself has flaws in its design, premises, or even its understanding of the game at hand. In which case, a live program might not do what was intended.

Whatever, in the end, it will be your program. So, why not make it a good one?

Anything you put in a strategy that does not resemble reality will find its way back to haunt you, and most probably, hurt you financially. You should not be surprised if reality has its own path and will continue its course in spite of what you think it should be. Look at trading procedures, understand what they do, their side effects and interrelationships with the other procedures within your program. How will your trading procedures evolve in time? They might be fix, they are code after all, but their impact will change as the portfolio grows. So, your methods, procedures should adapt there too.

The money your program will make is not just a fluke. You will have worked for it, you will have earned it, every penny of it.

The payoff matrix does resume all the trading activity into a simple expression: $\sum_{i=1}^n (H\,.^*\Delta{P})$, and $\,\,n \cdot \bar x\,\,$ show what matters in the payoff matrix. Nothing in these expression say how you managed to achieve them, they just represent one way of tabulating the result of having applied a particular trading strategy, nothing more. It was view as a bean counter in the beginning of this series, it still is.

In the search for $n$, you still have to search for $\Delta p$. Asking questions like: how many 10% or 100% moves are there in this stock? Intuitively, your answer will be: there are a lot more 10% moves than 100% moves, and also, 100% moves usually take much longer to be realized. Over a decade or two, how many times did a particular stock doubled? In such cases $n$ is relatively small. However, as was shown in chart $\# 1$, there are many combinations to reach the same portfolio output. So, it is not entirely only the search for $n$. It becomes the search for a methodology.

A trading system that can do all of it. Not just short term but also have a vision of where a trading strategy leads to. If the overall strategy design is such that over time the strategy will have to fail, simply because it was designed that way, then it greatly reduces the strategy's potential as well as the underlying portfolio. Why not design a portfolio's trading strategy to last, right from the start?

© 2016, September 22th. Guy R. Fleury