DEV Community

Cover image for Trading stocks with machine learning
Abzal Seitkaziyev
Abzal Seitkaziyev

Posted on

Trading stocks with machine learning

Description

There are three main forms of securities trading: day trading, swing trading and long-term investment. I wanted to compare long term investment with swing trading for the same stock. For example, I believe in the product or service of some company XYZ and it shows stable growth with good potential to grow further. My question: can I get potentially higher return on investment(ROI) when I switch from long investment to swing trading, by buying low and selling high and repeat it multiple times for stock XYZ for long period. Also, will my risk change, with increasing reward?

Modeling & Results

To predict when to enter into the position, I used risk scorecard model, which based on the logistic regression. To get correct exit point, I applied trailing stop-loss. Due to the nature of the target, model picked up some local minima with order of less than 10 days, which created more false positives than I expected. However, with correct implementation of stop-loss, I minimized losses at real false positives entries.

I observed, that choosing stocks without prior screening still could be profitable, but cannot beat the long term investment return.

However, individual models were able to beat long term investment. Model works better in conjunction with balanced trading strategy.
On the example of S&P 500 index, I did backtest from 05-2017 till 05-2020. I got ROI of 1.5 using ML model compare to ROI of 1.22 when just doing long investment.

Alt Text

Conclusion
It is possible to get higher ROI using ML model, than just staying in the long position. Risks of loss could be controlled by proper strategy.

Future work
I would like to select initially high potential portfolio to feed my model and optimize exit strategy using resistance/support lines individually per each stock. As well, I want to explore how to get better ROI than popular trading algorithms.

Link to github repo.

Note: This is a concept check project, which I did as part of my educational goal to learn time-series in data science. This blog is not a financial advise and I am not a broker or professional investor. Stock investing is risky and can lead to loosing money. Please consult a licensed stock advisor before investing.

Top comments (4)

Collapse
 
abebur profile image
Abebur • Edited

If there’s one thing I’ve learned from years of crypto trading, it’s that consistency beats luck every time. Trading bots like Petrousus offer that consistency. In the fast-paced world of crypto, it’s nearly impossible to catch every opportunity manually. That’s where bots come in. Petrousus allows you to automate trades based on preset strategies that are tailored to different market conditions. One feature I love is how Petrousus integrates machine learning to analyze patterns and trends, making it one of the most advanced bots out there. It doesn’t just follow rules, it learns from the market’s behavior and adjusts accordingly. The platform is also very accessible; whether you’re a complete beginner or an experienced trader, Petrousus has tutorials and customer support that guide you through the setup. The level of control they offer over your trading strategies is incredible, allowing you to tweak parameters as much as you like. If you’re looking to make smarter, data-driven trades without being glued to your screen 24/7, I highly recommend giving it a go at petrousus.io. 😊 With a bot like this, you can trade confidently, knowing you’re maximizing every opportunity.

Collapse
 
mattewadams profile image
MattewAdams • Edited

That's a fascinating question regarding the comparison between long-term investment and swing trading. When looking at stocks like XYZ, it’s important to note that swing trading offers the potential for quicker returns as you buy low and sell high multiple times over a set period. However, it can come with increased risk due to the frequency of trades. Tools like risk scorecards and stop-losses can certainly help mitigate these risks. You might also want to balance these strategies with your overall risk tolerance. For those interested in other forms of active trading, Pocket Option might be worth exploring. You can check out a detailed review of the platform at this link httрs://revieweek.com/review/pocke... which provides insights into the benefits of using it for binary options trading. In essence, swing trading can complement long-term investments, but finding the right tools is key to managing the potential risks and rewards—much like in any trading environment, including Pocket Option.

Collapse
 
bmor2552 profile image
Boi N Moriba

Congratulations Abzal on you final project and completing the program!

Collapse
 
xsabzal profile image
Abzal Seitkaziyev

👍