Introduction to AI: Refining our Linear Regression Algorithm

In the first part, I stumbled upon an issue where the algorithm wasn’t digging deep enough to generate the exact source code of the compiled program it was trying to reverse-engineer, so here, we’ll go through the algorithm step-by-step to see what nee…


This content originally appeared on Level Up Coding - Medium and was authored by Besarion Turmanauli

In the first part, I stumbled upon an issue where the algorithm wasn’t digging deep enough to generate the exact source code of the compiled program it was trying to reverse-engineer, so here, we’ll go through the algorithm step-by-step to see what needs to be changed or added in order for it to give us exactly what we need — a 100% accurate result.

By the way, you can check the previous tutorial in case you haven’t seen it already:

Introduction to AI: an A to Z Tutorial for Building a Basic Linear Regression Algorithm from…

If you’re a bit confused as to how linear regression could be applied to reverse engineering compiled programs, seems like too simple of a method for an overwhelmingly difficult task — the software in this case is a trading bot, it processes historical price data to generate buy and sell trading signals, we know what kind of data goes in and what comes out, and that’s where linear regression shines, however, this method won’t work on trading bots that combine two or more trading logics in one, we need specific input, specific output, and only one algorithm that is responsible on that output. I’m not saying reverse-engineering more complex programs is not possible, but it takes more than just coding skills to do that…

First thing first I need to make sure my trading bot is doing what it’s supposed to:

I added vertical lines in order to easily identify where the RSI values are, and I think we missed one crucial component: as you can see on the first trade, RSI is above 20, there’s nothing wrong with it because the bot opened a buy trade based on previous candle’s price— or when the next candle was opened, RSI is based on close prices. To verify, we can change RSI setting to work with open prices instead:

That’s exactly right, there could be an issue with our price data export bot, it may not be exporting candle data just before the entry, but the entry candle data, and if that’s indeed the case, everything shall work perfectly on our slightly modified chart.

As you can see we have 456 trades in our backtest, we’ll need that number later for comparison:

Here’s the output of our data export bot:

Let’s see what we’ve got:

According to this, our last trade is a buy, which is true:

Does the OHLC data match to actual OHLC?

Not at all — the last trade exported by the bot is actually the trade before the last trade, however, there are exactly 456 exported trades and the RSI values are all over the place in exported data:

Seems like we found a problem — it’s in our data. Now let’s modify the data manually and make sure the algorithm works, I set all buy RSI values to 5 and all sell RSI values to 95, if AI identifies the entry conditions correctly, it works perfectly and we just need to fix the data export issues, our output shows 456 trades indeed, let’s check the rest…

2021–06–05 03:31:59 displaying final raw results..
2021–06–05 03:31:59 # of sell trades is 241
2021–06–05 03:31:59 # of buy trades is 215
2021–06–05 03:31:59 displaying the number of trades by side..
2021–06–05 03:31:59 Array ( [1] => 215 [-1] => 241 [0] => 0 )

Buy conditions minus (without) sell conditions:

l2 > l &&
h3 > h &&
c2 > c &&
l3 > l &&
o > c &&
o2 > c &&
c3 > c &&
o3 > c &&
o3 > l2 &&
h3 > o &&
h3 > c2 &&
o3 > l &&
o2 > l &&
h2 > c &&
h3 > c &&
c3 > l &&
h3 > l &&
10 > RSI5[1] &&
20 > RSI5[1] &&
40 > RSI5[1] &&
60 > RSI5[1] &&
80 > RSI5[1]

Perfect!

And now sell conditions minus (without) buy conditions:

c2 > o3 &&
o > o3 &&
c > o &&
h > h2 &&
c > c2 &&
h > h3 &&
c > o2 &&
c > c3 &&
c > o3 &&
h2 > o3 &&
c2 > l3 &&
o > l3 &&
c > l2 &&
c > l3 &&
h > o2 &&
h > o3 &&
h > c3 &&
h > l3 &&
RSI5[1] > 5 &&
RSI5[1] > 10 &&
RSI5[1] > 20 &&
RSI5[1] > 40 &&
RSI5[1] > 60 &&
RSI5[1] > 80

Perfect again! As you can see, this is actual source code (trading logic) generated by our AI algorithm that we can just copy and paste in Metaeditor IDE, it also generates JSON output with detailed information about statistics and accuracy that we went through in the previous tutorial.

Thanks for reading!

For more Machine Learning tutorials, please check the links down below:

Have a great day!


Introduction to AI: Refining our Linear Regression Algorithm was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Besarion Turmanauli


Print Share Comment Cite Upload Translate Updates
APA

Besarion Turmanauli | Sciencx (2021-06-05T19:29:24+00:00) Introduction to AI: Refining our Linear Regression Algorithm. Retrieved from https://www.scien.cx/2021/06/05/introduction-to-ai-refining-our-linear-regression-algorithm/

MLA
" » Introduction to AI: Refining our Linear Regression Algorithm." Besarion Turmanauli | Sciencx - Saturday June 5, 2021, https://www.scien.cx/2021/06/05/introduction-to-ai-refining-our-linear-regression-algorithm/
HARVARD
Besarion Turmanauli | Sciencx Saturday June 5, 2021 » Introduction to AI: Refining our Linear Regression Algorithm., viewed ,<https://www.scien.cx/2021/06/05/introduction-to-ai-refining-our-linear-regression-algorithm/>
VANCOUVER
Besarion Turmanauli | Sciencx - » Introduction to AI: Refining our Linear Regression Algorithm. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/05/introduction-to-ai-refining-our-linear-regression-algorithm/
CHICAGO
" » Introduction to AI: Refining our Linear Regression Algorithm." Besarion Turmanauli | Sciencx - Accessed . https://www.scien.cx/2021/06/05/introduction-to-ai-refining-our-linear-regression-algorithm/
IEEE
" » Introduction to AI: Refining our Linear Regression Algorithm." Besarion Turmanauli | Sciencx [Online]. Available: https://www.scien.cx/2021/06/05/introduction-to-ai-refining-our-linear-regression-algorithm/. [Accessed: ]
rf:citation
» Introduction to AI: Refining our Linear Regression Algorithm | Besarion Turmanauli | Sciencx | https://www.scien.cx/2021/06/05/introduction-to-ai-refining-our-linear-regression-algorithm/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.