Thursday, April 20, 2017

Stochastic Systems Analysis

Engineers will recognize that this post is about stock trading, others may wonder what is a stochastic system.

Market price data is a time series of mostly random data, a stochastic system.  So a Day Trader is a Stochastic Systems Analyst - now doesn't that sound fancy!

Investopedia Simulator
The one thing I learned over the years is that if you want to make money from trading stocks or futures, then you need to have a simple and well defined system, with easy to calculate entry and exit criteria, otherwise you will eventually lose your shirt.

As the late Douglas Adams, the famous galactic economist of Bistromatics fame said:   
When it is infinitely improbable that something will ever happen, 
it will happen almost immediately.

Price data is mostly random.  In retrospect it seems to follow a trend and engineers and computer programmers get duped into thinking that they can easily devise a system to do automated trading based on historical and real-time data, with some Digital Signal Processing applied to detect a signal in the noise.  I tried it too decades ago, but downloading price data and adjusting for stock splits and companies changing names and ticker symbols is a huge problem and if you then devise an automated trading system it may work for a while, but eventually it will diverge and you can lose your shirt.   

An automated trading system requires constant work, which defeats the original idea!

Mutual Funds / Exchange Traded Funds / Hedge Funds

The only people that make money from mutual funds are the people that manage the mutual funds.  In Canada, they make money twice - when you buy and when you sell - a total rip-off.   

So instead of investing in a mutual fund of a bank, rather buy the stock of the bank, pocket the dividends and stop complaining about how they rip people off.
The exception is when you live some place without proper internet access, or if you are too old and demented to do a proper job yourself.  In that case maybe, investing in ETFs may be a good idea.

Long Plays

One problem is that any trade also influences the market - it is a feedback loop.  One can get price volatility with a purchase of only a few hundred shares in a blue chip company, if nobody is selling at that nanosecond instant.  Now imagine trying to manage a pension fund and buying and selling tens of thousands of shares.  This is why there is always room for the little guy - us.

To build real wealth, you need to be in the market for the long haul - decades.  The pension funds periodically 'balance their portfolios' - usually in March and October and that can cause wild volatility and crashes.  So a good long strategy is to Buy in March and Sell in September, then buy in November and sell in February.  If you are in cash, then you can buy the crash.  If it doesn't crash, just buy it all back again a month later. 
An Apple a day, keeps the doctor away:
The best financial site is still

For example, when I bought four blue chip stocks in my RRSP  (my buy in March entry), within a few minutes I lost $200 - bah, humbug.  If you trade long, don't look at the real-time graphs too much! 

To control the risk, buy at least 5 stocks for your RRSP and set stop loss orders 5% to 7% down - but you need to keep resetting them, since they expire after a few days/weeks.  If you use OCO orders effectively, then you can run your own mutual fund - periodically check and adjust your orders and keep the management fees.

Day Trading

Day trading is for making a little money to live on now.  Investing is to make a lot of money to retire on in 30 years.  It requires different strategies.

Day trading is also a nice mental exercise to keep your brain from atrophying while you wait for the  market grass to grow.

There are few millionaire day traders.  There are however many people who sell books and training courses on day trading.  Selling books and training courses is clearly more profitable and less risky!

You have to read two or three books (No more than three. Stop and practise instead), to learn the lingo and methods, just don't believe in it as the one true gospel - try to find the idea behind it

Bear in mind that if someone sounds like a second hand car salesman selling a lemon, he probably is.  Motley Fool is an example of a group that buys penny stocks, then hype them furiously to get others to buy into their scheme.  It creates an artificial market price bump, which they and a few followers can then profit off.   There are several other groups that do the same thing.  This is not for me.

Day trading is limited by what a human being can manage.  People can juggle 3 to 11 complicated things at the same time in their head.  The result is that a futures trading system is best limited to a pot of $5000 to $15000 and trades limited to 1 to 5 per day.

As Lazarus Long, the famous American futurologist said:  
The odds are terrible, but if you don't play, you can't win.

If you trade with E-mini futures, buy and sell one or two contracts at a time, then you could make $50 to $200 a day.  Buy a contract and sell when it is up by 8 ticks or down by 3 ticks.  On average you should win some - not much, but enough to pay the bills.  If you don't know what you are doing yet, you can loose $50 to $200 a day - so you have to practise in a simulator.

The methods are the same for day trading stocks, but you would need a bigger pot of money - about $25,000 to play with -  
You can also improve your yield by buying more stocks than you have cash on hand - by buying on margin - borrowing from your brokerage.  Interactive Brokers offer margin rates of less than 2%, so if you can make only 5%, then you are good. Of course, your risk is then also higher.

In general, don't day trade with more than 1% of your pot of money to keep the risk down and test your system in a simulator for a week or two before turning loose on live trades.  If you only make one trade a day, then two weeks of practise is only 10 dummy trades - precious little.  If you cannot make money in a simulator, then real live trading will be even worse and you will join the crowd of suckers at the bottom of the heap.

If you are good, then you should invest half your monthly profit for the long haul in blue chips, like that nice fruit company mentioned above...

Trading Software

Trading software programs now are a dime a dozen - there is no need to write your own anymore.  Ninjatrader is popular for futures trading, but your own bank probably has a system that is good enough - a fancy expensive program will not magically make you a better trader if you only do one trade per day.

TD Bank for example has four trading systems that I know of, the default Webbroker system, a more advanced Java based Advanced Dashboard program that you can download from the Webbroker site, which provides real-time data and also ThinkOrSwim and the related TD Ameritrade -

Note however that the TD Bank Advanced Dashboard only works properly in North America.  In my experience it doesn't work in the Middle East and it doesn't work in Central Europe and probably doesn't work in many other places too (it just sits there and shows some useless error messages when you click on a stock ticker) and they will happily charge your account a usage fee for your frustrations too.
TD Bank Web Broker works anywhere, but for Mutual Funds specifically, you cannot set smart orders like One Cancels Other, or even a simple Stop Loss order - any order executes immediately.   So if you use the TD Bank trading system and you own Mutual Funds, then you practically cannot go on a remote outback holiday - you can lose your shirt while you are away.  For stocks and ETFs though, you can do it (Click Sell, Strategies), so this could be another reason not to buy Mutual Funds.
The lowest cost reputable international broker that I know of, is Interactive Brokers.  If you do more than one trade per day of a few hundred stocks/futures, then they may be the best, but figuring out exactly how much it will cost you is difficult, since they have a complex pricing schedule -
Interactive Brokers do work all over the world, so it is one of the best if you travel around.

Depending on how much you trade and how much you have in your account, a trading platform will cost about $60 per month.  So the cost is not ridiculous if you are dedicated to trading and not just doing it for fun.  Also write down the help phone number of your trading system, so that you can call them when you have a computer or network problem and cancel your trades.

Historical Analysis vs Reality

If you find an elevator stock that goes up and down, then you can trade it and make money every few hours or days simply by sitting and staring at the real-time price graph, but eventually something will change.  There will be a war, a plane crash, a court case, a dishonest CFO, a SARS-COV2 lockdown... and you may loose your shirt.

It is therefore important to use simple statistics and stop loss orders to control the risks and identify opportunities, but you should steer clear from very complex systems, since finely tuned systems will only work in the short term 
A One Cancels Other Order, is a good way to lock in profits and protect against disaster: 
  • Set the Sell Limit at 20% above the buy price
  • Set the Sell Stop Loss at 5% below the buy price
  • Set the duration of the order to Good Till Cancelled 
  • Now, you can go on holiday!
Note that by the time that you buy the book of a successful trader, he is already retired and canoeing in the Caribbean and his lucky streak has long since ended.  So whatever you do, always bracket your holdings with an OCO order to protect yourself.  Don't think that what you read in a book (or in this article!) will always work.

You can learn from the past, but the past will never be repeated exactly the same way.

Simple Statistical Analysis

The Greek philosopher Democritus said that a thing is worth whatever someone is prepared to pay for it and the stock market to me resembles a pack of lemmings running over a cliff, with traders trying to outbid each other before the inevitable market crash, which happens on average every 4 years - but you don't know which year it will be.

The first book I read on stock trading was clearly written by a trader who was just lucky (or had inside information).  He made an enormous amount of money with Eli Lily when they invented the anti-baby pills.  His 'head and shoulders system' was impossible to recreate and everything worked only in retrospect, not with real data.  Successful plays almost always resemble a 'head and shoulders' graph - after the fact.   It is very easy to predict that you should have bought a stock last week.

Much later, I encountered a book by Burton Malkiel,  'A random walk down Wall Street', which rigorously proved with Montecarlo analysis that most hedge and mutual fund traders were just lucky and will blow up eventually.  It is a very dispiriting book, but it proves that one cannot predict the market by looking at price data only - you need to have inside information also.  Ordinary mortals don't have inside information, but big traders and institutions do (the managers sit on multiple company boards and are all golf buddies) and they are the ones leading the pack of lemmings.

The front running big lemmings will never admit to randomness explaining their strings of successful trades, since that will make them look dumb and they will not admit to having inside information, since that is supposed to be illegal.

Successful trading systems for small time investors invariably boil down to a price moving average and a standard deviation calculation, plus a volume indicator.  A Bollinger band is very good to see what the price is doing, while a trading volume indicator (there are many), can identify what the other lemmings are doing and the trick then, is to run with the pack just a little bit and stop, before they fall off the cliff.

The Lemming Effect

Successful trading strategies look not only at price, but also at volume and track price volatility to get a handle on the Lemming Effect.  The big lemmings out in front of the market are the institutional investors with inside information who run our pension funds - successful small trading systems calculate how to follow the fat lemmings for a little while.

Bulls make money, and bears make money, but pigs get slaughtered.

When the market is stable (going sideways) or going up (bullish), then you can buy low and sell high and make money, a little bit at a time.

However, when the market is stable or going down (bearish), then you need to reverse things to (short) sell high and buy low.  It is exactly the same operation, just reversed in time - but more risky, since the stock can drop to zero.

As Shane, the famous American cowboy said: If god didn't have a sense of humour, then he would be a very lonely man.

Here is a good write-up on Bollinger Band trading -

So how do you know when to buy long, or sell short?  Look at the long term trend - where are the lead lemmings going.  Is the market going up, or going down and if you get a losing streak of five dud trades - reverse what you are doing - don't fight the market - flip your strategy around - ping-pong -

Practise Makes Perfect

It all sounds easy until you try to place a trade, then you wonder what amount to enter at the stop buy, what is the ADR and the profit target and what to enter in the stop loss and would the profit be big enough to cover the trading fees - and by the time you figured it all out, the opportunity has passed.  

Therefore you have to make a spread sheet or prepare a programmable calculator with your formulas so that you can enter and place a trade quickly.  You need to keep a spread sheet of your trades anyway, since come tax time, you will need it.

How do you find a penny stock to day trade?  Well, that is the boring part.  Here are some clues:
  • Daily volume between 500K->25M shares
  • Stock price < $30
  • Range between hi & low to be > 50c
  • Look for a 20c gain on 1000 shares, for a $200 day.
There are not all that many.  You could play with Bank of America (The one that Warren Buffet made his fortune on) in a simulator to get started.    

Keep it simple, and practise in a simulator or for a few weeks before you risk real hard earned moolah.

OCO and FOCO Orders

In my experience, the most important thing is the One Cancels Other order, which I mentioned above, but which should be mentioned over and over.  An OCO is a two legged order, only one leg of which will execute - the other will be cancelled.  In TD Webbroker, click Sell, Strategies to do multi leg orders.
One cannot normally enter two orders on a single holding - the broker software will not allow you to do that.  An OCO provides a pair of linked orders to actually do exactly that:
  • Set the Sell Limit at 20% above the buy price
  • Set the Sell Stop Loss at 5% below the buy price
  • Set the duration of the order to Good Till Cancelled 
  • (Check it every day, since it can get cancelled!)
With a properly set OCO order, you can make a some money on almost any stock.
There is also a three legged variant which you can use to set up the whole buy and take profit (or stop loss) in one go.  It is called a First Triggers One Cancels Other order. The First leg is used to buy the stock, then the other two legs do the profit/loss taking and the neat thing is that you can enter it all at once and then go and get another coffee.
If you carefully calculate and enter a First Triggers One Cancels Other order and it immediately crashes out, causing you to lose 5% - don't be annoyed - get a cup of hot chocolate instead and find a better stock.

Taxi Drivers and Hair Dressers

There may be exceptions to this rule, but when your taxi driver or hair dresser starts to talk about making money in stocks, then the market is far over extended and due for a serious crash:  
SELL everything and go on a long holiday.
La voila!