Thursday, August 06, 2020

What is the probability of profit of your next trade? (Introducing PredictNow.Ai)

What is the probability of profit of your next trade? You would think every trader can answer this simple question. Say you look at your historical trades (live or backtest) and count the winners and losers, and come up with a percentage of winning trades, say 60%. Is the probability of profit of your next trade 0.6? This might be a good initial estimate, but it is also a completely useless number. Let me explain.

 

This 0.6 is what may be called an unconditional probability of profit. It is the same for every trade that you will ever make (unless your winning ratio changes significantly in the future), so it is useless as a guide to whether you should take the next specific trade or not. It can of course tell you whether you should trade this strategy in general (e.g. you may not want to trade a strategy with an unconditional probability of profit, a.k.a. winning ratio, less than 0.51). But it can’t do so on a trade-by-trade basis. The latter is the conditional probability of profit. As the adjective suggests, this probability is conditioned on the specific market environment at the time when you expect to trade.


Let's say you are trading a short volatility strategy. It can be an algorithmic, or even discretionary, strategy. If you are trading it during a very calm market, it is likely that your conditional probability of profit would be quite high. If you are trading during a financial crisis, it could be very low. The conditions that can determine the probability may even be quantifiable.  The level of VIX? The recent SPY returns? How about the interest rate change or Nonfarm Payroll number just announced? Or even the % change in Covid-19 cases on the previous day? You may not have taken all these myriad numbers into account when you were building your simple trading strategy, or when you decide to make a discretionary trade, but you can't deny they may have an impact on the conditional probability of profit. So how are we to compute this probability?


Spoiler alert: computing this conditional probability helped us earned 64% YTD return as of June 2020. You can find out how to do that with predictnow.ai. But more on that later.

 

The only known way to compute this conditional probability is machine learning. Let's return to the example of your short volatility strategy above. Suppose you prepare a spreadsheet of the returns of the historical trades you have done, like this:

 

Figure 1: Spreadsheet with historical returns of short vol trades.


Figure 1: Spreadsheet with historical returns of short vol trades.


Again, these trades could be due to an algorithm, or it could be discretionary (perhaps based on some combination of fundamental analysis and intuition like what Warren Buffet does).

 

Now let's say we only care about whether they are profitable or not, so we ignore the magnitude of returns and label those trades that are profitable 1, otherwise 0. (These are called "metalabels" by Marcos Lopez de Prado, who pioneered this financial machine learning technique. They are “meta” because he assumed the original simple strategy is used to predict the ups and downs of the market itself – those are the base predictions, or labels. The metalabels are on whether those base predictions are correct or not.) The resulting spreadsheet looks like this. 


Figure 2: Spreadsheet with labels: is historical return of short vol strategy profitable?


Figure 2: Spreadsheet with labels: are historical returns of short vol strategy profitable?


Simple, right? Now comes the hard part. Your intuition tells you that there are some variables that you didn't take into account in your original, simple, trading strategy. There are just too many of these variables, and you don't know how to incorporate them to improve your trading strategy. You don't even know if some of them are useless. But that's not a problem for machine learning. You can add as many variables, called features / predictors / independent variables, as you like, useful or not. The machine learning algorithm will get rid of the useless features via a process called feature selection. But more on that later.

 

So let's say for every historical trade (represented by a row in the spreadsheet), you collect some features like VIX, 1-day SPY return, change in interest rate on the previous day, etc. We must, of course, ensure that these features' values were known prior to each trade's entry time, otherwise there will be look-ahead bias and you won't be able to use this system for live trading. So here is how your spreadsheet augmented with features may look: 


Figure 3: Spreadsheet with features augmented.


Figure 3: Spreadsheet with features augmented.


OK, now that you have prepared all these historical data, how do you build (or "train", in machine learning parlance) a predictive model based on that? You may not know it, but you have probably used the simplest kind of machine learning model already, maybe way back in a college statistics class. It is called linear regression, or its close sibling logistic regression for our binary (profit or not) classification problem. Those features that you created above are just the independent variables, often called X (a vector of many variables), and the labels are just the dependent variable often called Y (with values of 0 or 1). But applying linear or logistic regression on a large, disparate set of features to predict a label usually fails, because many relationships cannot be captured by a linear model. The nonlinear co-dependences between these predictors need to be discovered and utilized. For example, maybe when VIX <= 15, the 1-day SPY return isn't useful for predicting the probability of profit of your trade. But when VIX >= 15, 1-day SPY return is very useful. This type of relationship is best discovered using a "supervised" hierarchical learning algorithm called random forest, which is what we have implemented on predictnow.ai

 

A random forest algorithm may discover the hypothetical relationship between VIX, 1-day SPY return, …, and whether your short vol trade will be profitable as illustrated in this schematic diagram: 


Figure 4: Example classification tree generated by predictnow.ai internally.

Figure 4: Example classification tree generated by predictnow.ai internally.


To build this tree, and all its cousins that together form a "random forest", all you need to do is to upload your spreadsheet above to predictnow.ai, click a button, and it will probably be done in less than 15 minutes, often much sooner. (Certainly faster than a pizza delivery.)

 

Figure 5: Choosing training mode at predictnow.ai.


Figure 5: Choosing training mode at predictnow.ai.




Figure 6: Uploading training data.


Figure 6: Uploading training data.


Figure 7: Choosing hyperparameters for building random forest.


Figure 7: Choosing hyperparameters for building random forest.


Once this random forest is built (trained) with historical data, it is ready for your live trading. You can just plug in the latest values for VIX, 1-day SPY, and any other features into a new spreadsheet like this:


Figure 8: Live trading input


Figure 8: Live trading input.


Notice that the format of this spreadsheet is the same as the training data, except that there is no known Return of course - we are hoping to predict that! You can upload this to predictnow.ai together with the model you just trained, press PREDICT, 


Figure 9: Live prediction.


and voila! You can now download the random forest's prediction of whether that trade will be profitable, and with what conditional probability.



Figure 10: Live prediction, with probability.

One of the output files (left in Figure 10) tells you the most likely outcome of your trade: profit or not. The other file (right one in Figure 10) tells you the probability of that outcome. You can use that probability to size your trade. For example, you may decide that if the probability of profit is higher than 0.6, you will buy $10K of TSLA. But if the probability is between 0.51 and 0.6, you will only buy $5K, while if the probability is lower than 0.51, you won’t buy at all.

 

Typically the live prediction will take 1 second or less, while the training (which may not need to be re-done more than once a quarter) typically won't take more than 15 minutes even for thousands of rows of historical data with 100 features. You can make live predictions as frequently as you like (i.e. as frequently as your input changes), but if you are a high frequency trader, you would want to use our API so that our predictions can be seamlessly integrated with your trading system.


But predicting the conditional probability of profit for your next trade is not all that we can do. We can also tell you what features are important in making that prediction. In fact, you may be more interested in that than a black-box prediction, because this list of important features, sorted in decreasing order of importance, may help you improve your underlying simple trading strategy. In other words, it can help improves your intuition about what works with your strategy, so you can change your trading rules.

 

Going back to our example, predictnow.ai can generate such a graph for you: 




Figure 11: Features with decreasing importance


You can see that VIX was deemed the most important feature, followed by 1-day SPY return, the latest interest rate change, and so on. Our internal predictive algorithm will actually remove all features that are "below average" and retrain the model, but you may benefit from incorporating just VIX and 1-day SPY return in your simple strategy when it generates a trading signal. Remember, your simple strategy does not need to be an algorithmic strategy. It could be discretionary.

 

(For the machine learning mavens among you, we use SHAP for feature selection, as discussed in our paper.)


You may wonder why our predictive service is restricted to only taking your strategy’s historical or live trades as input and predicting their probabilities of profit. Why can’t it be used directly to predict the market’s return? Of course it can: you only need to pretend that your strategy is buy-and-holding the market. It can even predict the magnitude, not just the sign, of the return. But as we all know, it is very hard to predict the market’s movement, because of low signal-to-noise ratio. Your own strategy, however, has presumably found a way to filter out those noise, and machine learning prediction is more likely to succeed in telling you what “regime” is favorable/unfavorable to your strategy, and with what probability. Another usage of our service is to use it to predict numbers that are not subject to arbitrage, things such as a company’s earning surprise, credit rating change, or the US nonfarm payroll surprise (as we have already done successfully). In these usages, there are no adversaries (your fellow traders) that are trying their hardest to arbitrage away your trading alpha, so these predictions will be more likely to work far into the future. 


(For machine learning mavens, you may wonder why we have only implemented random forest learning algorithm. The beauty of random forest is that it is simple, but not too simple. Complicated deep learning algorithms such as LSTM can indeed take into account the time series dependence of the features and labels more readily, but they run serious risk of data snooping due to the large number of parameters to fit. GPT-3, the latest and hottest deep learning algorithm for natural language processing, for example, has more than 175 billion parameters to fit. Imagine fitting that to 1,000 historical trades!)


So does this stuff really work? We have implemented this machine learning system for our Tail Reaper strategy in our fund around the August of 2019. Yes, the 64% YTD return as of June 2020 (net of 25% incentive fee!) is nice, but what's more amazing is that the machine learning program told us to not enter any trade (due to the low conditional probability of profit) from Nov 2019 - Jan 2020. In retrospect, that made sense because Tail Reaper is a crisis alpha, tail hedge strategy. There was no crisis, no tail movement, from which to reap profits in those calm months. But suddenly, starting on February 1, 2020, this machine learning program told us to expect a crisis. We thought the machine learning program was nuts - there were just a handful of Covid-19 cases in the US at that time! Nonetheless we followed its advice and restarted Tail Reaper. It went on to capture over 12% return later that month, and the rest is history. (Past performance is not necessarily indicative of future results. For detailed disclosure of this strategy, please visit qtscm.com.)


Figure 12: Tail Reaper equity curve


Figure 12: Tail Reaper equity curve.


For readers interested in a free trial or to participate in a live webinar on how to use predictnow.ai to predict the conditional probability of profit of your trades, please sign up here.

 




31 comments:

  1. Great article ernie!
    surely will test my discretionary strategy ,with some extra features, with your tool.

    Just a small question : Had your machine learning model seen some crisis situations in the past . If not, what features ( in the meta label model ) do you think hinted the model in feb that there was trouble ahead?

    Thanks much.

    ReplyDelete
  2. Great article ernie!
    surely will test my discretionary strategy ,with some extra features, with your tool.

    Just a small question : Had your machine learning model seen some crisis situations in the past . If not, what features ( in the meta label model ) do you think hinted the model in feb that there was trouble ahead?

    Thanks much.

    ReplyDelete
  3. Hi John,
    Yes, the machine learning model was trained using data that contained the 2015 Q4 Chinese stock market crash (even though the base model only trades the ES futures), 2018 Q1 Volmageddon. As mentioned in my article, the out-of-sample test includes the 2020 Covid crisis.

    The features include financial inputs from around the world only (no "alternative" data).

    Ernie

    ReplyDelete
  4. Hi Ernie,
    Thats great!
    Do you have a course / workshop where you teach your tail reaper strategy? (I have all three of your books, but they don't mention any tail strategy) .
    Thanks a lot!

    ReplyDelete
  5. Hi John,
    Actually, my previous blog post mentions some reference articles to trend following strategies that resemble Tail Reaper. Also, my 2nd book Algorithmic Trading did discuss similar momentum strategies as well. I do offer a Quantitative Momentum pre-recorded course that dicusses that. Please see http://epchan.com/EP%20Chan%20Course%20Offerings.pdf
    Ernie

    ReplyDelete
  6. Thanks for the article Ernie. How often do you recommend re-training the model?

    ReplyDelete
  7. Hi Alex,
    I recommend re-training whenever your data changes by 5% or more.
    Ernie

    ReplyDelete
  8. Hi ernie,
    Yes, i just read your tail paper . That provides a ton of context.
    In "machine trading " you wrote about hidden markov models to tell whether we are in bull or bear market . Have you seen the model giving trouble pointers during march collapse? Or do you recommend for me to test that strategy too on s&p ?
    Basically does HMM have the potential to be used as a tail risk strategy?
    Thanks again for all your teachings . It has been so much valuable in my trading journey!
    Best,
    John.

    ReplyDelete
  9. Hi John,
    Yes, I heard that HMM already performed well in predicting tail regimes.
    Ernie

    ReplyDelete
  10. Hi Ernie -

    You are doing some interesting things!

    ReplyDelete
  11. Shouldn't predicted direction accuracy > baseline win rate?

    baseline 54-57% win rate -> 66-67% filtered via backtest win rate -> PredictNow.ai 48-49% win rate (predicted direction accuracy vs backtest actual p/l)

    Ernie, I spent few hours playing with the PredictNow.ai tool and listened to your June presentation on it. I either am not doing it right, or it's not adding value to models I thoroughly backtested and am live trading. The 2 main models I tried are based on capturing the overnight return in certain equities, buying the close and selling the next open. In the baseline, taking all signals, the win rate would be 54-57%. By adding 10-30 filters and taking only the most productive 1/3rd of the signals, the win rate goes up to around 66-67%. Enter PredictNow.ai, I took my daily data with the variables used in my filters, and the training data results are all below 50% accuracy (ACCURACY SCORE FOR CV = 0.49; AUC SCORE FOR CV= 0.48). Shouldn't predicted direction accuracy > baseline win rate?

    ReplyDelete
  12. Mark,
    Yes, if your filters are useful for predicting whether your signals will be profitable, the predictive accuracy and AUC score should be higher than 50%.

    Please feel free to email me at ernest@predictnow.ai (with your predictnow.ai username), and we will take a look at your files to see if there is anything amiss.

    Thanks,
    Ernie

    ReplyDelete
  13. Hi Ernie,

    One follow-up question on how to use the service. I have a bunch of features that I created from which I create a strategy. So in my case, the strategy is a function of all the indicators I have (i.e: the average of all the indicators). As I understood the service, the indicators are the features and the strategy output the labels.

    When I read the post, I was under the impression that the strategy must be somewhat uncorrelated to the features. In other words if f(x) is the strategy, then x should not include the indicators used as the features of the model prediction. I assume that otherwise we end up with a conditional probability.

    Have I gotten this wrong?

    Thanks

    ReplyDelete
  14. Hi Alex,
    Indeed, the features you use for metalabeling should be different (not necessarily uncorrelated or orthogonal) from the indicators you already use in your base strategy. Otherwise, metalabeling can't add too much value to your current strategy. The idea is to scour the world of predictors that can tell you whether your strategy is in a good "regime" to trade or not, predictors that are not already part of your strategy.

    Hope this makes sense?
    Ernie

    ReplyDelete
  15. Hi Ernie.
    Interesting post. Would this work on sub-daily frequency features? I have a strategy that holds asset for a few days, but checks conditions intraday.

    Also - would having Binary features be a problem?

    ReplyDelete
  16. Hi Ankit,
    You can apply it to any frequency. It all depends on your labels. Labels can be 1 minute returns, or 1 month returns.

    Yes, we can take binary, or in general categorical, features.

    Best,
    Ernie

    ReplyDelete
  17. Hi, I am posting this comment with the permission of Ernie to introduce my work called yMTa and hopefully have a broader audience for it's recognition. Thanks Ernie.

    yMTa, is a freely available Windows software and includes many Market Trading related tools.

    I am a developer and have implemented many trading algorithms for the past decade and always looking to find professional traders and include their working trading algorithm in yMTa software for free.

    Please note that, I am not looking for a job or fund and just want you take a look at my work in yMTa or let me have an opportunity to show what can be done using yMTa. I also could be able to add new tools or algorithms to yMTa based on your advise or your more specific requirements.

    Right now I am looking to find professional people in the field and be able to demonstrate what are the benefits of the tools in yMTa and find ways to make it more useful and have the right path in adding new tools to it.

    Please take a look at my software and let's talk if you are interested.

    yMTa,
    A freely available Windows software, Includes many Market Trading related tools.
    t.me/yMTaCh
    Yashil MultiTrding
    https://t.me/yMTaCh

    Email: yashil1@yahoo.com
    Telegram: @Yashil1

    yMTa Download:
    https://drive.google.com/drive/folders/1BHzFSr2pCve2-3KJCRkVOBjYXxaubFx9

    yMTa English Telegram channel: t.me/yMTaCh

    Old yMTa Persian Telegram channels:
    https://t.me/yMT4ch
    https://t.me/yMT4notify
    https://t.me/yMT4demo

    ReplyDelete
  18. Hi Ernie,

    I am confused with the label part. As I understood, I can enter in the label my discretionary trades. So 0 when i made no profit and 1 when I made a profit.

    How do i handle days where no trades (entry or exit) happened? for example say I use the SMA_10 as a features, the SMA_10 has 100 rows (i.e: 100 days lookback). Within these 100 days, say I traded half of the time. Would i just drop the days in the SMA_10 columns where no trades occurred?

    2nd question related to the first one, Marcos Lopez de Prado talks about the triple-barrier method to label the trades. Am I supposed to label the data using this method or is the service doing this?

    Thanks for the consideration,

    Carlos

    ReplyDelete
  19. Hi Ernie,

    Do you have any recommendation on how might one incorporate an LLC to benefit from active trader status? I am working full time, but also execute more than 80-100 trades a month in a personal trading account. I am thinking of eventually quitting my job and trade full time. Should I register as an LLC ?

    Thanks

    ReplyDelete
  20. Hi,
    Yes, if you want to limit your liability in case of Black Swan loss, you should incorporate.
    To incorporate a LLC is quite trivial if you intend to be the sole member. Just go to bizfilings.com.
    Ernie

    ReplyDelete
  21. Hi Ernie,

    Not sure my previous comment made it. I wanted to know if for the labels I need to apply the triple barrier method before uploading it to PredictNow.ai or it is something that the service does automatically?

    Also I wasn't sure if for trades that are long for multiple days or weeks, if my indicators are daily, which categories should these labels be if 1 is for profit and 0 is for loss?

    Thanks,

    Carlos

    ReplyDelete
  22. Hi Carlos,
    Currently, you will have to create your own labels, as we do not know what your stop loss and profit target are.

    The labels for 0 and 1 are generally for a round trip trade. If you have a portfolio with many stocks, you may instead want to predict the daily returns of the portfolio. That way, you can adjust the capital of the portfolio instead of a single constituent.

    Ernie

    ReplyDelete
  23. Thanks Ernie. Got it. Do I still need to apply the triple barrier-method as mentioned by Lopez de Prado? or is that not necessary to create proper labels?

    ReplyDelete
  24. Thanks Ernie. Got it. Do I then need to create the labels using Lopez de Prado's triple barrier method or is that not a must with your service?

    ReplyDelete
  25. Hi Carlos,
    Yes, if you plan to use stop loss and profit target, you need to use triple barrier labels. Otherwise, you can apply two, or even just one, barrier.
    Ernie

    ReplyDelete
  26. Hi Ernie,

    This is a great piece, and very timely for me since I've just begun to consider how ML can augment my deterministic trading strategies.

    I have a strategy framework where lots of trading system signals are aggregated at the symbol level to arrive at a final allocation that varies slowly over time. For example, AUDCAD may have an allocation of 0.10 one minute (indicating a 10% long allocation), and an allocation of 0.15 the next minute, a net change of 5% long. It can also turn negative, so the allocation may change from 0.10 to -0.25, indicating a 25% short allocation of capital, and a change of 35%.

    How could I use PredictNow to improve my trading of the aggregate signal on whole symbols? Due to the features I intend to use, I'm unable to use PredictNow to forecast the probability of success of the individual trades whose signals (short, neutral, long i.e. -1/0/1) contribute to the aggregated symbol allocation. So rather than a single discrete trade whose outcome is well-defined, all I have to go on is the net signal applied to the symbol which varies over time.

    Do you have any recommendations on how I could use PredictNow on this aggregate signal?

    Regards,

    James

    ReplyDelete
  27. Hi James,
    Thanks for your kind words!

    You don't have to predict probability on a per trade basis. You can predict them on a daily basis.

    Are you trading just one symbol? Or do you want to allocate across different symbols?

    If it works better for you, please email me (ernest@predictnow.ai) and we can set up a call to discuss.

    Best,
    Ernie

    ReplyDelete
  28. Hi Ernie,

    Thanks for your response, I'll certainly get in touch once I'm closer to being able to incorporate PredictNow into my framework.
    In the meantime I figured I'd ask my other questions here for the benefit of other readers.

    A few years ago you proposed generating synthetic data on which to backtest strategies to correct for overfitting. The strategy parameters that perform well on the synthetic data are the ones that should be selected for live trading. I'm wondering if such a procedure still has a purpose after consideration of a trade outcome classifier, like PredictNow.

    Say, for example, I have three parameters to fit for my strategy, and each can vary across 10 levels. That gives me 10x10x10=1000 possible parameter combinations for my strategy. I could generate 100,000 synthetic price series on which to test each of the parameter combinations, performing 100 million backtests in the process. I would then keep all parameter combinations that perform well, on average, across those 100,000 synthetic price series, discarding the rest.

    Say I were to instead train the trade outcome classifier on trades placed by each of those 1000 parameter combinations. Would synthetic data backtesting continue to add value for assessing overfitting? Presumably the trade outcome classifier would be able to determine which of those parameter combinations overfit the data, giving them consistently low probability forecasts as a result and limiting their influence on the 1000 system trade signals. Does synthetic data backtesting serve any purpose in the presence of a trade outcome classifier like PredictNow?

    Regards,

    James

    ReplyDelete
  29. Hi James,
    In theory, that would work. In practice, it is extraordinarily hard to generate realistic time series with all the quirks of a real financial time series. So parameters optimized that way may not be suitable for real life.

    Using our Conditional Parameter Optimization technique, we learn from real time series, but with many combinations of parameters to simulate different backtest outcomes. This technique is made possible by Predictnow.ai's API, and I am happy to disclose more privately!

    Best,
    Ernie

    ReplyDelete
  30. Hi Ernie

    Will including the strategies positions as a feature worsen or improve the algorithms performance?

    Thanks

    ReplyDelete
  31. Hi,
    I don't think positions as features would help, but recent performance of your strategy might.
    Ernie

    ReplyDelete