Backtesting

Backtesting is the process of testing a trading strategy on historical market data to see how it would have performed under those trading conditions. Quantitative Developers and Analysts will use a market simulator (like CloudQuant) to evaluate the trading strategy. Key statistics that show performance are shown on the CloudQuant scorecard. Statistics include Sharpe Ratio, Calmar Ratio, Kelly Edge Percentages, Profit/Loss, Drawdown.

Backtesting Quantitative Algorithms on CloudQuant

Posts

85 Percent of Data is Unstructured

Is Crowdsourced Data Reliable?

,
“Bring us your ideas and we will share the money with you,” agreed Morgan Slade, CEO of the crowdsourced algorithmic trading startup CloudQuant. “For us, engagement means breaking it down into a contractible problem.”
RSI

Technical Analysis Library (TA-LIB) for Python Backtesting

Anyone who has ever worked on developing a trading strategy from scratch knows the huge amount of difficulty that is required to get your logic right. … TA-LIB Turbo-Charges Your Research Loop: TA-Lib is widely used by quantitative researchers and software engineers developing automated trading systems and charts. This freely available tool allows you to gather information on over 200 stock market indicators.
data scientist researching trading strategies

Algos and Ethics – a response to a LinkedIn Post

Algorithmic Trading and Ethics

Alessio Farhadi posted “A.I. Trading – A Question of Ethics” on LinkedIn.  His main point is that machine learning and algos do not have ethics.  His thoughts may be overly influenced by the referenced Flash Boys book that painted the trading industry with a somewhat cynical brush. Just as AI technology has enabled growth in professional algorithms, it has also spurred growth and opportunity for the regulator, broker-dealer, exchanges, and even the average joe who wants to get involved. Fairness to the industry requires that one should review the steps that have been taken by innovators, regulators, broker-dealers, and exchanges to mitigate any potential dangers of using computers and algorithms to trade.

AI, Algo Trading and the Regulators and Watchdogs

The regulators, self-regulatory organizations, and exchanges have all been active in improving the integrity of the industry. These activities include:

AI, Algo Trading, and the Innovators

Innovative firms have seen the need and are helping the industry by responding to the urgent need. The term REGTECH applies here. A few examples include:
  • Vertex Analytics with their amazing ability to see patterns in the market data and highlight cheaters.
  • Trading Technologies’ Neurensic product that uses machine learning to catch spoofers, front-runners, layering, pump and dump, and more forms of illegal trading.
  • Edge Financial Technologies and their KillSwitchPlus tool that catches run away algos and limit breaches at the time of the order.
  • Catelas with its surveillance ability to catch collusion between traders or inappropriate use of insider data.
Even the algorithmic trading technologists and firms are getting into the game. At CloudQuant anyone can develop an algo. By democratizing the access to formerly restricted algorithm development tools anyone can participate in the algo world. The restrictions on historical data, technology, capital, and exchange membership are falling. 

AI, Algo Trading, and the Average Joe

Improved access to information is also making it easier for the world to see what is going on with their investments. StockTwits, Alexandria Technologies, Twitter, LinkedIn, Reddit, Quora, and more are all publishing insights into the world. Individuals, both professional and personal, are publishing more insights into the world. Google, Bing, Benzinga, Bloomberg, Reuters, and others are all making it easy to find data that previously were not easily available to the average investor. YouTube, LinkedIn, Quora, SMBTraining, QuantInsti and others are all teaching anyone interested in trading and algorithms secrets and insights that 5 years ago were not available to anyone other than a select privileged few at well-capitalized trading firms. Tools like Python programming language, Jupyter Notebooks, Technical Analysis Library TA-Lib, and our own CloudQuant are making it easier for anyone to enter the world of algorithmic trading.

AI and Machine Learning for Algo Trading isn’t to be Feared

Trading moved from being manual pit trading to computer screens. At that time people had legitimate concerns. Those were addressed. Similarly, we are moving to a more algorithmic world of trading. Concerns are again being addressed.   My point in all this is not to contradict Mr. Farhadi’s thoughts but to present additional, hopeful information. While the world of investing is changing, the safety systems and the participants are also changing. This doesn’t mean that the industry should stop adjusting to change. The technologists, regulators, broker-dealers, exchanges, and vendors all need to continue to innovate and adapt. This will lead to an ever-increasing stable and reasonable marketplace where all can fairly participate.

CloudQuant’s Production Algos & Ethics

CloudQuant licenses algos from algo creators who use our website and tools to backtest their strategies. During our due diligence process, we review the orders, positions, and trades that the algo did in backtesting. We are looking for any breach of trading rules that may cause issues. As a trading firm primarily we know that the issues of ethics and rule violations are never to be taken lightly. Our licensing process and ongoing oversight of algorithmic trading keep us on a solid ethical footing. Furthermore, all our trading is watched by compliance utilizing technology too.     Happy Algo Trading, Tayloe Draughon
Open, Close, High, Low

Share Ordering Demo using Market, Limit, and Midpoint Peg Orders

The CloudQuantAI github repository holds the share_ordering_demo tutorial/code that demonstrates ways to buy and sell stocks in the CloudQuant backtesting engine using Market, Limit, and Midpoint Peg Order types. There is no single “right way” to do any of these. You will have to think carefully about your algorithm, how it determines when to buy and sell, how large a trade you want to implement, and how quickly you need your orders filled. To give an example, let’s imagine a hypothetical stock XYZ, at time t0 with bid prices at 29.95 and ask prices at 30.05.

Market Orders

One option is a simple market order: order_id = order.algo_buy(self.symbol, algorithm=”market”, intent=”init”, order_quantity=num_shares) This means that your order will fill at the lowest price someone is actively willing to sell it at. In real trading, you would never buy significant shares of stocks like this, because people will raise their ask price when they realize someone is buying large volumes on market. In backtesting, however, it is essentially assuming you are buying at the ask price for that time, which is reasonable. Your order will always fill immediately, and the only risk is that if the stock price shoots up, you will be paying whatever price the stock goes up to. In our example of stock XYZ, you are buying at 30.05 at t0, though if your order is placed at t0, you may be purchased at the ask price at time t1, which could be different from the ask at t0. Market orders will simply purchase at whatever that ask price is.

Limit Orders

Another way is to initiate a limit order, based on the ask price: order_id = order.algo_buy(self.symbol, algorithm=”limit”, price=md[self.symbol].L1.ask-.01, intent=”init”, order_quantity=num_shares) or order_id = order.algo_buy(self.symbol, algorithm=”limit”, price=md[self.symbol].L1.ask*.99, intent=”init”, order_quantity=num_shares) These two algorithms place an order for a stock with a limit on the price. In the first case, we set a limit one cent below the ask, and in the second our limit is 99% of the ask price. These are likely to get filled, but not guaranteed, though they will get a better deal than a simple market order. The farther below ask you go, the better a deal you might get, but the higher a chance that you won’t get filled. The lowest you can go is probably 95% ask or 5 cents less than the ask. If it’s important that you get your order filled immediately, you will want to place a more aggressive limit, such as the ask price PLUS 5 cents or 105% the ask price. This is similar to a market order but will keep a lid on how much you actually will pay for the shares. This is a critical distinction in live trading, but less important in back-testing. In our example of stock XYZ, if we, at t0, place a limit order one cent below the ask, we are essentially offering at t1 a price of 30.04. Cloudquants backtesting environment does its best to approximate whether someone would have been likely to meet our price limit or not. If the price of stock XYZ moved up at t1, there is a very high chance we would not have been filled. If, however, we set a limit of ask + 5c, we would have placed a limit at $30.10, and we would have likely been filled unless the stock shot up more than that.

Midpoint Peg Orders

Finally, we have a slightly more complex way of computing our trade price, using a “midpoint peg.” This algorithm is only available in the elite version. order_id = order.algo_buy(self.symbol, algorithm=lime_midpoint_limit_buy, price=md[self.symbol].L1.ask*1.05, intent=”init”, order_quantity=num_shares) order_id = order.algo_buy(self.symbol, algorithm=lime_midpoint_limit_buy, price=md[self.symbol].L1.ask+.05, intent=”init”, order_quantity=num_shares) You will also, earlier in the code, need the lines: lime_midpoint_limit_buy = “4e69745f-5410-446c-9f46-95ec77050aa5” lime_midpoint_limit_sell = “23d56e4a-ca4e-47d0-bf60-7d07da2038b7” Though the exact algorithm is only available in the Elite CloudQuant version, you could approximate it in lite by using the mean of the ask and bid prices. This is similar to what the “Lime” midpoint peg does, but the real version should include elements such as the volume of the shares to more accurately estimate where the price would have been. If your trade doesn’t need to urgently fill, the lime midpoint peg is a good way to go, however, if your trade requires an immediate fill, this may give you unrealistic purchase prices, and make your algorithm seem better than it really is. In our XYZ example, this essentially assumes we would always be purchasing shares of XYZ for $30.00 at t0, and then the average between bid and ask at t1, and so on. The public scripts with these examples are available for your copy and re-use.
Improved Breakout Strategy

Industry News: Machine Learning and Artificial Intelligence News November 13, 2017

AI & ML news covering: the creative process, improving skills, ETFs, Risk, Supervised Learning, RiskGenius, Robo Cops, Fears, NVidia, Quickbooks, SEC Edgar …
Trading Strategy Scorecard from CloudQuant

52 Traders Interviews Morgan Slade

, ,
The podcast on Massive 30,000 Trades Daily, High-Frequency Quant Trading with Morgan Slade including an interesting breakout trading strategy.
Machine Learning, Quantitative Investing News

Industry News: Machine Learning and Artificial Intelligence News 10/30/2017

AI and ML for CloudQuant, ArcaEx, Corporate earnings reports, Hedge Funds, Microsoft, Alexa, Saturday Night Live, the apocalypse, Elon Musk, and more …
Crowdsourcing Algorithmic Research

​CloudQuant Is a Trade Strategy Incubator That’s Looking to Develop and Fund Algorithm Traders

, ,
A rising population of programmers, data scientists and mathematicians are now looking to write complex codes for automated investment strategies of their own. This is crowdsourced algorithmic trading.
Scorecard

Backtest Visualization on CloudQuant

,
The Quantitative Strategy Backtest ScoreCard is saving time for crowd researchers who are able to visualize the results of multi-day backtests quickly, even as the backtest is running.
Daily ROIC Prior to improvements

Improving A Trading Strategy

TD Sequential is a technical indicator for stock trading developed by Thomas R. DeMark in the 1990s. It uses bar plot of stocks to generate trading signals. … Several elements could be modified in this strategy. Whether to include the countdown stage, the choice of the number of bars in the setup stage and countdown stage, the parameters that help to decide when to exit and the size of the trade will affect strategy performance. In addition, we could use information other than price to decide whether the signal should be traded.