Progress Update 10

    I just got back from a weekend getaway yesterday so now I am back to work. During this getaway, I brought my laptop and book Conquering The Seven Faces of Risk by Scott Juds to get some work done while away from my desk. I did more reading than coding this weekend so I learned a lot more from reading this book than I did making progress on coding on QuantConnect. So let me share a few things.

    To start off of what progress I made in my coding, I started to make less progress today as I run into some compatibility issues. These issues are mainly coding issues with me trying to figure out how all of my Python classes will communicate with each other. Let me explain.

    According to QuantConnect, a good trading algorithm consists of 5 models (Python classes) which all handle different parts of the algorithm. The diagram below from QuantConnect shows how these 5 parts interact with each other to create a trading algorithm.




    The Universe Selection model's purpose is to quantitatively select assets to trade. This can be used for purposes like filtering out low liquidity penny stocks so your algorithm doesn't accidentally pump and dump small cap assets. I have this model super simple with just 1 symbol in it (for now): SPY.

    The Alpha Creation model is the meat of the algorithm because this is where your strategy will generate Python objects called "Insights". Insight objects are a neat way of packaging signal information to be eventually sent to the Portfolio Construction model. Insights can tell you what direction the signal is in (up or down), a confidence level in the signal, the weight of the signal (strong or weak signal), and other info. I have my Alpha model creating up or down insights depending on my strategy. Here is where my current problem lies. I am having trouble figuring out where to create the indicator data. If the indicator data is created outside the Alpha model Python class, then I am having trouble calling the data into it. I will eventually figure this out. It will just take time. I am just glad my problem is a coding problem and not a problem with my core strategy (hopefully...).

    The Portfolio Construction model is used to determine how seriously to take the Insight objects that are given to it. Here is where I take the up or down Insight objects generated by the Alpha model and set the trade size to 100% of my trading equity. This is basically an "all-or-nothing" approach where all the money the algorithm has is either all in a trade or all out. No fancy position sizing. I am doing this because my Alpha model is only based off of 2 indicators, that isn't enough to determine confidence levels and the weight of the signal to eventually determine how much trading equity should go into that trade. In the future, I hope, I will have created enough Alpha models to use everything in one algorithm as an "all weather" algorithm.

    The Execution model is used to take the determined position sizes and send the trades combined with stop-losses generated from the Risk Management model. My execution model is simple where I just take the position sizes from the Portfolio Construction model and directions from the Alpha model to make a market order for that direction. If I am already in a position where the Insight generated was in the same direction, then it is ignored. If I get an opposite Insight generated while in a position, it liquidates my current position and replaces it with the new direction.

    Lastly, the Risk Management model is used to, well, manage risk. I created mine in the form of a trailing stop loss function that was already created by QuantConnect. So it made it easier to just call that function. But I would also like to modify it in the future as well. This isn't my first priority since my first priority is to get the algorithm working in the first place. But eventually I would like to have the trailing stop losses adapt to current volatility. If there is no volatility, I can have a looser stop loss. If there is high volatility, I can have a tighter stop loss to minimize draw-downs.

    So that is where I am at with my programming work so far in these past few days. Now let's get into all the cool stuff I learned from reading a lot of the book Conquering The Seven Faces of Risk by Scott Juds. Below is a picture of the book and here is a link to get a copy if you are just as intrigued as I am about creating a profitable trading strategy and converting it into an algorithm.

    Over this weekend and today, I read about how the Hurst exponent can be used to quantify a trending market and about how signal to noise ratios can be used in financial markets.

    The Hurst exponent is a number used to quantitatively measure how "trending" a market is. The values of the Hurst exponent, range from 0 to 1, can be subdivided into 3 categories: trending (1 > H > 0.5), random-walk (H = 0.5), and mean-reversion (0.5 > H > 0). The formula to find the Hurst exponent of any given data, which I'll be strictly talking about applications of this formula in financial markets, is calculated using what's called re-scaled range analysis (R/S analysis). The formula from the book shown below, calculates the Hurst exponent (R/S(n)) by finding the average of the selected widened time interval t = 1 to T of the maximum range R within the time interval n of said range R, divided by the standard deviation of the collected data in R's time interval n.




    The number, between 0 and 1, that is spit out from this equation will allow you to mathematically determine if the time selected range of values within the set of data given is trending in a clear direction (1 > H > 0.5), sideways A.K.A mean-reversion (0.5 > H > 0), or non-trending and random (H = 0.5). Obviously within a trending market, the probability is higher that the next set of data points A.K.A next couple of bars, will stay within the trend rather than changing trend. Within a sideways market where the Hurst exponent is showing signs of mean-reversion-like action, a financial market looks to be trading within a range.

    When I was diving deeper in learning about the Hurst exponent, I started to think about how the outcome of a single candle can drastically change this value to "make a trend". This thought process then led me to think a lot about Chaos Theory. If you don't know what Chaos Theory is, it is the theory that in the prevalence of randomness you cannot predict the outcome of said "randomness" A.K.A "chaos" but you do know that the "chaos" is heavily determined on the initial conditions. One aspect of Chaos Theory that most people know about is the Butterfly Effect: the larger effect that one smaller action can have down the road.

    So in terms of financial markets, I would always think: "would sentiment still be bullish/bearish if XYZ didn't happen?". This is the perfect example of the Butterfly Effect and Chaos Theory. So in summary, quantitatively defining randomness (H = 0.5) and trends within financial markets using the Hurst exponent could probably benefit my algorithms by enabling myself to add a confidence level to every Insight generated within my Alpha models. I want to look into messing around with using the Hurst exponent within my trading algorithm soon but not now. Like I said above, my first priority is to have the code work in the first place then mess with the properties of the trading system.

    Moving onto the last bit of info I learned from reading this weekend. I read and learned a lot about how signal to noise ratios can be used in financial markets to sift through "noisy" indicators and pluck out a reliable signal. This is commonly used in electrical engineering but according to Scott Juds, can be used in financial markets as well.

    If you don't know what "noise" is in a financial market, it is essentially a lot of up and down "chop". Noise can be found in any financial chart more so if you zoom into smaller time-frames like a 1-minute chart.

    Having a larger signal to noise ratio effectively "smooths out the chop" to have a clearer indicator; in Scott Juds' case, a momentum indicator. These individual momentum indicators which is each produced from a different ticker, can then be compared to each other to determine which asset has the most momentum in that certain period in time. This is what Juds' refers to as "owning the fastest horse".

    Using that strategy to own the asset which has the most upward momentum, you can systematically flip-flop between assets to have the best gains of all selected assets and have the least draw-down of all selected assets. Don't confuse "owning the fastest horse" strategy with owning everything all at once in a typical "diversify and re-balance" portfolio. "Owning the fastest horse" is meant to have all your chips in one basket at a time and constantly switch baskets whenever one outperforms the others.

    This strategy that Scott Juds uses is a very interesting topic. I look forward to reading more about it this week and also look forward to (hopefully) solving my coding problems soon. That was a quick summary of what I learned during my weekend getaway. Will update more of my progress soon.

-Jamie




Comments

  1. Thank you! Glad you enjoyed it! I am aiming to complete this little goal of mine before I go back to school in 2 weeks. So there will be a lot more content in the meantime.

    ReplyDelete

Post a Comment