One line of code makes all the difference

<div>
<a href="https://www.onestepremoved.com/one-line-of-code/"><img title="Live demo trading of Pilum" src="http://d1p9cjl89wwo3v.cloudfront.net/wp-content/uploads/2017/02/DetailedStatement-300×73.gif" alt="Live demo trading of Pilum" width="300" height="73" /></a>
</div>
<p>I was really excited about my Pilum strategy two months ago. The research looked great and everything was ready to rock and roll. Demo testing began and then… not much happened.</p>
<p>The Quantilator is (mostly) finished, which finally gave me time to circle back and review what happened with Pilum.</p>
<div>
<div><p>Live demo trading of Pilum. Dec 9, 2016 to Feb 7, 2017</p></div>
</div>
<p>The expected outcome was that I would win 75% of the time. Trades were infrequent, so I thought maybe I'm just having bad luck. But then my win rate remained stuck around 50%. Simple statistical tests told me this was unlikely to be bad luck.</p>
<p>I used the research time to pour over my research code and to compare it with live trades. What I found was that <strong>a single line of code</strong> (AHHHHHHHHHHHHHHH!) was incorrectly calculating my entry price, dramatically overstating the profits.</p>
<p>The <strong>flawed</strong> code produced this equity curve from a single combination of settings:<br />
</p>
<p>When the actual, correct result looks like this with those same settings:</p>
<div><p>The accurate backtest of Pilum</p></div>
<p>I'll be honest… I like the flawed backtest a lot more!</p>
<p>The new, single-setting backtest isn't as good, but it's still trade-worthy. There are some characteristics that I dislike and features that I love. Let's dig into those.</p>
<h2>What I dislike</h2>
<p>The frequency of trades is very low. Out of 19 months there were a total of 43 trades. 43 trades to comprise a backtest on 40+ instruments is a very small number.</p>
<p>If it weren't for the statistical pattern backing up the frequency, I would not consider the test. However, there are 20,000 bars each on the 44 instruments. There are 880,000 total bars used to analyze whether my Pilum pattern offers any predictive value.</p>
<p>The most valuable predictions, however, are also exceptionally rare. That's why I'm not able to get the trading frequency higher, which would potentially smooth the returns.</p>
<h2>What I love</h2>
<p>My previous systems like QB Pro and Dominari traded actively for relatively small wins. Trading costs exercised a massive impact on the overall performance.</p>
<div>
<div><p>The accurate backtest of Pilum</p></div>
</div>
<p>Now look again at the correct equity curve (the image to the right). Do you see the final profit of roughly 0.14? That's a 14% unleveraged return over a 19 month period.</p>
<p>Allocating 2:1 or 3:1 leverage on this strategy could average annual returns of 15-25%.</p>
<h3>Detecting hidden risk</h3>
<p>A key measure of risk is skewness. You may not use that term yourself, but it's something most of you already understand. The biggest complaint about people trading Dominari was that the average winner relative to the average loser was heavily skewed towards the losers.</p>
<p>Dominari wins on most months, but when it lost in December it was devastating. I implemented what I thought was a portfolio stop after the December 9th aftermath. Then I had a smaller, but still very painful, loss in January. The portfolio level stop loss of 3% should prevent future blowouts now that I know what goes wrong.</p>
<p>I still believe in Dominari. But, I obviously lost the work of most of the year due to those events.</p>
<p>Knowing that skewness is a good measure of blowout risk (even if you've never seen it in a backtest, like happened with Dominari), Pilum looks extremely encouraging.</p>
<p>This is a histogram of profit and loss by days. You should notice a few things.</p>
<p></p>
<p>The tallest bar is to the right of 0. That means that the most frequent outcome is winning.</p>
<p></p>
<p>The biggest winning day is dramatically better than the worst losing day. The worst outcome was a loss of 2%. The best outcome is gains near 10% in a single day (unleveraged!).</p>
<p>This is the statistical profile of an idea that's much more likely to grab an avalanche of profits than it is to get blown out.</p>
<h2>It gets even better</h2>
<div>
<div><p>Would you say that the blue and red equity curves are highly or loosely correlated? Look closely.</p></div>
</div>
<p>Writing this blog post made me think carefully about the Pilum strategy. I decided that maybe I should see if all of the profits are coming from different settings at the same time. There's very little risk of overfitting the data as my strategy only has 1 degree of freedom.</p>
<p>The blue bars are the equity curve of Setting 1.</p>
<p>The red bars are for Setting 2.</p>
<p>Do you think these are tightly or loosely correlated?</p>
<p>If you said loosely correlated, then you are correct. Notice how each equity curve shows large jumps of profit. Did you notice how those profit jumps occur on different days?</p>
<p>The blue setting skyrockets on a single day in November 2016. It leaves the red equity curve choking in its dust.</p>
<p>But then, look what happens as I advance into December. The red curve dramatically catches up to the blue curve and even overtakes it.</p>
<p>The correlation between the 2 strategies is only 57%.</p>
<h2>Combine multiple settings into 1 portfolio</h2>
<div>
<div><p>This is a much nicer equity curve!</p></div>
</div>
<p>Loose correlations are a GIFT. Combining two bumpy equity curves into a single strategy makes the performance much, much smoother.</p>
<p>The percentages of days that are profitable also increases. Setting 1 is profitable on 58.0% of days. Setting 2 is profitable on 53.5% of days.</p>
<p>But… combining them makes Pilum profitable on <strong>68.2%</strong> of days. Awesome!</p>
<p>That also provides more data, which puts me in a stronger position to analyze the strategy's skewness. Look at the frequency histograms below. They're the same type of histograms that I showed you in the first section of this blog post. As you'll notice, they look a lot different.</p>
<div><p>The most probable outcome for any given day is a small winner</p></div>
<p>The tall green bar is the most probable trading outcome for any given day with filled orders. The average day is a positive return of 0-1%.</p>
<p></p>
<p>The small <span>red bar</span> is the <span>worst</span> trading day of the combined strategy.</p>
<p>The small <span>green bars</span> are the <span>best trading days</span> of the combined strategy.</p>
<p>Look how far to the right the green bars go. The largest winner is more than 3x the biggest loss. And, there are so many more large winners compared to losers.</p>
<p>Giant winners are far more likely than comparable losses.</p>
<h2>The Plan</h2>
<p>I immediately pushed Pilum into live trading this combination of two strategies. I expect that adding a second degree of freedom and running about 30 different versions of the strategy – <strong>all with different settings</strong> – will add to the performance and smooth the returns even further.</p>
<p>Dominari hasn't been working on my FXCM account, which is very difficult to accept because the lacking performance seems to be a buried execution issue. Pilum, however, trades very infrequently. It's unlikely that execution quality will make a dramatic difference in the long term outcomes.</p>
<p>So, I'm going to convert the FXCM account to trading Pilum exclusively. That will be offered as a strategy on Collective2 within the next few weeks, a company with whom I've been working closely. Their users are more investor rather than trading oriented – they're far more likely to view low trading frequency as a good thing. I suspect that most people here have a different opinion and want to see a lot of market action.</p>
<p>I'll write an <a href="https://www.onestepremoved.com/painful-hits/">update on Dominari</a> shortly.</p><p>The post <a rel="nofollow" href="https://www.onestepremoved.com/one-line-of-code/">One line of code makes all the difference</a> appeared first on <a rel="nofollow" href="https://www.onestepremoved.com">Algorithmic and Mechanical Forex Strategies | OneStepRemoved</a>.</p>

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *