May 1, 2021

Of the published automated stock trading strategies, you are presented with a diamond in the rough once in a while. You either ignore it or recognize it as such and try to find out if indeed it will have some real value after being cut and polished. It is a choice you have to make. You will still have to work to extract that gem and then enhance its value. To your credit, this is a very simple strategy.

April 1, 2021

This is a follow-up to my last article Basic Stock Portfolio Math. Trying to provide a different look at the inner workings of the In & Out stock trading strategy which is freely available on QuantConnect where you can modify it at will. The intent is to show how this strategy is making its money. It should prove interesting. The strategy is composed of only a few parts: a stock selection process, a trend definition section, and a trade execution method. Nothing very complicated.

March 9, 2021

The following HTML file deals with some of the basic math of a long-term stock trading portfolio. It reduces the problem to two numbers, one of which is a simple counter. Because trading over the years can imply a lot of trades, we have to look at the problem in terms of averages. What will the average net profit per trade tend to when you have a large number of trades? It is a basic question that appears difficult to solve, and yet, it can be greatly simplified. That you trade automated or by hand, the equations presented will still hold. The final outcome of a trading strategy is the result of simple math, simple equations, nothing complicated.

Feb. 19, 2021

Designing a successful stock trading strategy has about the same objectives as developing your own money printing machine. That you trade on a discretionary basis or use some elaborate trading program to execute your trades does not guarantee you to win at this game but you can easily put the odds in your favor of doing so.

In reality, the problem is very simple: you buy some stock (whatever the reason) and resell it later at a profit. You do it often. That is it. That is all the game. You do not need much to understand the mechanics until you do more than a few hundred trades. Then, you get to realize that the “game” is a little bit more “complicated”.

Feb. 6, 2021

You design an automated stock trading strategy and will use historical data for your simulations. Right off the bat, all the stock prices you will use are part of recorded history, and therefore, what kind of “discovery” are you going to make should be the question?

All the data is already there in plain sight. All you have to do is access it. Somehow, for some, it is as if the price of AAPL over the last 20 years has eluded them? As if they had never seen it before, or did not know what it did or what it stood for? AAPL and its related data is there, and that up to yesterday. Period. We can immediately see the hindsight problem this can create.

Jan. 24, 2021

Here is another post made on a QuantConnect forum. It could be viewed as a follow-up to the articles Stock Portfolio Backtesting and The In & Out Stock Trading Strategy

Is there something in @Vladimir's In & Out strategy (version 1.5)? What I see is that there is money in there. But, you have to determine that for yourself. What follows is not intended to convince you, you have to do your own homework.

Is there an edge that could persist going forward? Is it of any consequence what this strategy did over its simulated past? Is this strategy overfitted or not? In all simplicity: is it worth it? There is so much that could be said about this strategy.

Jan. 12, 2021

The following post is in reference to a question asked on overfitting in a QuantConnect forum.

Any stock trading strategy designer should have views on this subject since somehow it gets in the way if not at the heart of any such strategy that it be live or simulated. I find overfitting indirectly related to the law of diminishing returns. Meaning that going forward, your trading strategy will produce less over time. However, it can also be viewed in light of another problem, and that is to think that the market will strictly follow our often misconceived and poorly designed trading strategies. It should be forcefully noted that the market has no such obligation.

Nov. 16, 2020

Following Quantopian's shutdown, some of Quantopian's members moved the In & Out strategy to QuantConnect. I moved there too and started reading the documentation. Also started analyzing this adapted strategy and doing some simulations of my own. The following is my first post on QuantConnect relating to this freely cloneable strategy.

Nov. 1, 2020

I was about to answer a question in a Quantopian forum when they opted to shut down their community website. Here is that post anyway. It is trying to answer: could someone use stocks based on highest relative strength above a market average proxy? The strategy's code was given in the thread titled: New Strategy — “In & Out” where anyone could make a copy of it and then modify it at will.

I had this prepared answer, so figured it would do no harm to provide it anyway before everything was erased. I will definitely miss Quantopian participants and would like to express my thanks to all for their comments and contributions over the past few years.

Oct 17, 2020

The previous post showed the outcome for long-term portfolios where returns were randomly generated. Even under randomness, it resulted in return degradation making the game not worth playing. Adding some alpha would make a portfolio profitable. And, if you added more alpha, the long-term CAGR could increase even more.

All simulations were unique. A new random return series would be generated for each and every one of the tests (over 300). We could anticipate that most tests would come out close to some average, whatever that average might be. This was illustrated in the charts, figures, and equations in the previous post.

Oct. 10, 2020

The previous notebook put some emphasis on having an edge to overpower built-in long-term return degradation. There are many ways of doing this. The payoff matrix equations can have gazillions of solutions. They all depend on how you deal with the ongoing inventory matrix H. Trading implies doing a lot of trades, and doing so brings along with it the Law of large numbers.

Oct. 8, 2020

Posted a Jupyter notebook on Quantopian. Here is a link to its HTML equivalent(Sorry for the Quantopian links, the community website has shut down)

In the notebook, random return series were generated using a normal distribution with a 3% standard deviation over 1, 2, 5, 10, and 20 years to show the impact of trading over the long term. Such a strategy will breakdown over time. In the beginning, it might not be that visible, but as the time interval increases, it becomes more and more apparent since return degradation is technically built-in.

Sept. 16, 2020

The automation of a stock trading strategy appears at first glance as a simple process. You program what you think you might have done on a discretionary basis, except your computer can do it much faster and more often. You try to transfer to a program your acquired knowledge, understanding, logic, and trading methods by first simulating the outcome of your procedures over past market data.

Sept. 10, 2020

The following was posted in a Quantopian Forum expressing
my point of view on the highlighted stock trading strategy.

No one seems to be much concerned by the stock selection process used when it has a major role to play over the long term. First, let's set “long term” as 15 years or more. I would prefer 20-30+ years, but we do not have that much data available.

Sept. 1, 2020

A lot of emphasis was put on a payoff matrix equation (see my last article) to represent a long-term rebalancing stock portfolio. From it, we could estimate the number of trades the rebalancing might generate over the life of the portfolio. However, that was still only half of the solution. What was also needed was an estimate on the profitability of such a trading strategy. That part of the equation is more complicated and has a lot more than just one solution, even though, it too has a simple formulation.

Aug. 17, 2020

You start a stock portfolio with the intention of using scheduled rebalancing, meaning that the stocks in your portfolio are readjusted to a fixed weight on a yearly, monthly, or weekly basis. This portfolio management decision is simple, however, it does have ramifications.

An equal weight is easy to determine, it can be made proportional to the number of stocks j in the portfolio w = 1 / j. It does not say which stocks will be in your portfolio, only that the actual number of stocks will tend to j or less: → ≤ j. Fixing the number of stocks to be traded will also set the initial bet size which will depend on the available initial trading capital.

Aug. 4, 2020

The following was posted in a Quantopian forum on a trading strategy I greatly modified in order to have it follow its payoff matrix equation directives. It is also the fifth walk-forward performed on this trend-following trading strategy over the past 3.5 months. The strategy used a leveraged adaptive exponential betting allocation function to increase its long-term performance.

July 13, 2020

The following was posted in a Quantopian forum dealing with “Quality Companies in an Uptrend”. The original strategy template is available free for anyone to copy and use as they see fit. The trading strategy itself is fairly basic: it selects a set of the highest momentum stocks from top quality companies that are estimated to be in an uptrend. The assumption is made that such a trend would continue forward. The portfolio is rebalanced at the end of each month. Thereby, continuously chasing the higher momentum stocks. Nothing unreasonable about that proposition.

June 29, 2020

The way you design your stock trading strategy can force it to react in very specific ways. Pointing toward the need to gain a long-term portfolio management perspective since the primary objective of any strategy designer should be to structure these automated trading strategies so that they can, not only survive but also generate above-average returns over 20+ years. If you cannot achieve that, it is very simple: you failed. All you might have to help you is your skills, some math, and the analysis of past history.

June 25, 2020

The more you look at the stock market game, the more you realize you need to play for the long term even when you are making short-term trades. Also, the more you trade over the short term, the more those trades will be faced with random-like outcomes, and the more trades you will need to reach your long-term goals whatever they are. As if there was a contradiction in purpose and means to achieve those goals. Nonetheless, most often, it remains quantifiable. The presented equations will govern it all for some planned and preset strategies.

June 22, 2020

My last article: Stock Trading Game - Gambling It Out was making the point that stock prices could be considered as having the number of up and down days close to the equivalent of a coin toss. There was no need to look at thousands of stocks to validate this hypothesis. Even a small sample over an extended period of time would be more than sufficient to make that point. Nonetheless, some 21 years of data (5,473 trading days) was used to assess the general direction of the daily price movements and their long-term outcomes.

June 15, 2020

If you knew that if you played the stock market game and that you would win no matter what, even if it took a long time, would you not find the time and resources to play your expected winning game if you could?

June 10, 2020

You want to win the stock trading game, even with all its uncertainty. However, it should not be just winning it. It should also be with a higher purpose. Maybe, something like building up your own retirement fund or help someone else build theirs. One thing you should want, no matter what you do in managing that stock portfolio is to make sure you will win and make it so you outperform the expected long-term averages.

Outperforming the long-term averages is the only reason for you to undertake such a tasking endeavor yourself. Otherwise, simply buy a market average surrogate (such as SPY or some equivalent), or find someone that could do better than you which would have been more productive moneywise and with a lot less work.

June 4, 2020

A stock trading strategy can often be simplified to its most basic components, and there are not that many of them. In fact, maybe just two. Those trading strategies cannot be considered that complicated either if whatever their outcomes, they will end up as being the result of two numbers, namely: the number of trades executed over the life of the portfolio and the average net profit per trade. Due to the continuous trading, it transforms the expected portfolio profit problem into a long-term statistically driven and dynamic inventory management problem under uncertainty.

May 30, 2020

In this third installment, I would like to concentrate on the second part of the equation presented in my previous post. It is also where you can find an explanation for a trading strategy's overall return.

But first, a point to be made again, if your stock trading strategy is not built to last, what is it good for? Why build something and see it blow up in your face after a number of years? Wasn't your goal to build your retirement fund or someone else's, or build a legacy fund for some reason or other, and that it would, at the very least, have a positive ending value?

May 24, 2020

My last article (The Inner Workings Of A Stock Trading Program - Part I) stated that a single line of code was dictating the long-term behavior of a stock trading strategy. And that this scheduled rebalancing was sufficient to explain the number of trades that would be carried out over the life of this portfolio. In that article, the first part of the presented equation provided this estimate of the number of trades that would be performed over the years.

Other important observations could be directly extracted from the same equation. Having a portfolio's payoff matrix equation to explain an automated trading strategy implied that the outcome did, in fact, answer to mathematical functions. And that it is these mathematical functions that are driving the show.

May 22, 2020

My last article admitted that the trading strategy used was effectively trading on market noise. Even under those conditions, it could win and win big. It is surprising that, after such a statement, system designers were not in an uproar and making all those points that could be made to rebuke the claims. The article went even further by providing a portfolio payoff matrix equation which enabled making long-term estimates of the portfolio's future value.

May 18, 2020

My last series of articles (The Portfolio Rebalancing Gambit, I, II, III) was about a trading strategy that dealt with its long-term payoff matrix as if playing a game where some randomness appeared to prevail, and a lot of it did. Even in that kind of trading environment, the strategy was doing more than quite well.

A stock trading strategy operates quite differently than a long-term investment strategy. The latter is awaiting capital appreciation from reasonable investments for periods of 20-30+ years. Doing so, almost assuring itself of winning simply by holding most of the stock positions for long periods of time. As an example, see Berkshire Hathaway.

May 6, 2020

In my previous article, the point was made that you could win the game relatively easily simply by prescheduling your future trading activity based on your portfolio's initial set up. The portfolio value equation was put on the table with a reachable long-term objective giving a purpose to the whole process. You did it for your own retirement account or as some legacy fund you might want to leave behind or build a generational fund with philanthropic views. Those are things for you to decide. All I can do is help you design your long-term portfolio for whatever reason you may have.

I will build scenarios based on the portfolio payoff matrix equation presented in the prior two articles of this series (see related articles below). The purpose is to show the range of what you can do based on your own portfolio settings and long-term objectives and also show where's the money. I hope that with the examples provided you will be able to build your own and know what to expect based on your numbers.

May 3, 2020

Whatever your automated stock trading strategy, it needs a purpose, an objective. You need to plan for where you want to go and how you will get there. From my previous article, you can estimate how many trades will be executed without even writing a single line of code knowing you will be scheduling a periodic rebalancing procedure over your portfolio's life cycle.

This article continues in the same direction as the preceding ones (see related articles below), going from the endpoints and designing a trading strategy backward from the perspective of its long-term objectives. And then, redesign the trading strategy for going forward. All in the process of trying to answer the question:

What does my trading strategy have to do to reach its long-term objectives?

April 30, 2020

Often, we ignore the very structure we have given our automated stock trading strategies. We code them to behave in a certain way for as long as they will be executed. For example, in most Python programs showcased on Quantopian, we can find variants of the following line of code:

schedule_function(rebalance, date_rules.month_start(), time_rules.market_open())

It instructs the program to rebalance its portfolio the first trading day of each month as the market opens. That single line of code will execute, on its preset schedule, no matter what. Other programming languages would use a different syntax and wording to accomplish the same task.

April 24, 2020

We often design stock trading strategy simulations by first programming them on some economic notion and then observe the outcome. As if the trading procedures, over the long term, would resolve the appreciation problem all by themselves, when a more global view should be taken. The where you want to go and how far will it take you?

Most of it could be determined beforehand. More planning and a better outlook as to what you really want to do.

April 20, 2020

We design stock trading strategies simply to make money. The more the better. But it all has to be done within constraints of available capital and minimizing overall risks. Trading has a number of differences when compared to long-term investing in many regards. A trade, almost by definition, is seen as a short duration thing that can come out profitable or not. While in the long-term setting of investing, durability, appreciation and overall trends gain more importance. Short-term fluctuations are practically ignored while trading might live by them.

But whatever the trading strategy, it has some basic math to explain what it does. Not sophisticated math mind, as will be demonstrated here, but inherent structures nonetheless that are dependent on the how the trading is done. Most of the text that follows is about averages, and we can use these averages due to the large numbers that will be used. In all cases designing diversified portfolios with hundreds of stocks and thousands of other possibilities.

April 16, 2020

Usually, in designing automated stock trading portfolios, all the attention is put on the program's code. The trading procedures, the decision making, the gathering of relevant information that needs to be analyzed, interpreted, and acted upon. Often, our initial capital is a limiting factor just as our ability to extract a decent long-turn return.

Here, I will go about it in reverse. From the final objective, it will be to break down the trading strategy into what needs to be done to achieve these long-term returns. Something like starting from the end results and asking the question: how did we get here? Or more to the point: how could I get there? The “I” here is you.

April 13, 2020

The following is a post made on a Quantopian forum related to my recent articles on the subject of a portfolio's doubling time (see related files below).

I like the notion of doubling times for a portfolio. It indicates, on average, how much time was required for the portfolio to double in value. It is all a matter of the strategy's CAGR, its compounding rate.

April 9, 2020

I thought it might be an appropriate time to make a walk-forward test on the strategy presented in my January 8th article: Financing Your Stock Trading Strategy which showed a 16.9-year simulation with an ending date of 1919-11-29. It would make this new simulation a walk-forward, out-of-sample, test where the strategy would not have seen the last 3-month of market data.

March 31, 2020

My previous article dealt with The Making Of A Stock Trading Strategy's mathematical backdrop. Designing automated trading strategies having for objective to prosper over the long term. There are a multitude of ways of doing so. A trading portfolio, even with its short-term vision, needs to view its final outcome in light of a long-term compounded return. This is where a portfolio's average doubling time takes some importance.

March 28, 2020

The making of an automated stock trading strategy is relatively simple. It is made of 3 distinct processes: selecting some stocks on some reasonable quantifiable assumptions, determining the logical trading rules and procedures that will be applied, and executing them. The trading process can be enclosed in a single do-while loop and be executed until reaching the end of the program, that it be up to a past or future date.

March 16, 2020

We can represent stock trading systems with equations and not necessarily know that much about their future market returns, except general expectations and/or educated guesses. However, with these equations we can determine what is needed, over the long term, to trade and win.

Jan. 24, 2020

This is a follow-up to my last article, an attempt to answer the question: can you do more?

Two of the most important traits of any stock trading strategy should be its durability and its scalability. The first so that the strategy does not blow up in your face during the entire trading interval, and the second so that a portfolio can grow big.

Jan. 8, 2020

In my previous article was shown 17 simulation results of a stock trading strategy as found on the Quantopian website. On that basic template, I added optional functions in order to increase and control performance.

This intermediary step is part of my analysis of the strategy's worthiness since I am still exploring its capabilities: limits, strengths, and weaknesses. I present 12 new simulations using 160 stocks.