Showing posts with label algo. Show all posts
Showing posts with label algo. Show all posts

Sunday, 19 April 2020

8th day small profit that helps me to keep going in the competition



After a successful week and most importantly from recovering almost $6k, I wanted to consolidate my positive results. My desire was to build up the account to be able to deal with possible drawdowns.


6B 06/20 day chart
6B 06/20 future























Monday was a very quiet day in comparison with the previous days. The British Pound jumped 
almost 50 pips early in the morning but after that, the USD recover its strength. This changed again after midday when the price started to rise again.


6B 06/20 13/04/2020
6B 06/20 trade chart

I realized that I had a notification. My algo bought 5 lots during a retracement. In the beginning, it went against me, but it quickly recovered. It didn’t make a big movement but was more than enough to finish the day with a small profit. I personally don’t like to take positions at that time on the day because the algo closes the positions around 17:00. To be honest, it doesn’t matter if I like it or not, what I need to do is check that it’s statistically significant.  


Profit and new account balance



Trade 13/04/2020
Trade 13/04/2020

As I said, it was a small profit, but these kinds of days help to build up the account. The maximum adverse excursion was small. The algo closed the position close to the maximum favorable excursion which I’m very happy about. I have the feeling that I’m leaving a lot of money on the table. I am allowed to make one change in the algo during the competition and I’m seriously considering adding a take profit. These will reduce the time in which the algo maintains positions open and more importantly it will secure profits. On the other hand, it won’t let the profits run as much this is why I need to carefully check before I implement the change.


Account balance and realized PnL
Account balance and realized PnL


The account balance at the end of the day was $1003468.75. Even if it’s not real money, I feel very well because the algo is behaving as I expected and it’s able to recover from drawdowns.

Thanks for reading this post!

Thursday, 16 April 2020

7th day, huge profit


After almost recovering the losses from previous days, I had a lot of energy and I wanted to switch on the system as soon as possible. To be honest, this doesn’t matter. When I was designing the system, I decided to set up a time window to be able to control the algo and make sure that the positions were closed before the end of the day.

6E 06/20 breaking
6E 06/20 breaking moment


I was expecting that the Fed approval of its new loan program and I knew that it will have a big impact in the markets that the algo trades.
Early in the morning, the USD was stronger than the Euro and the British Pound. The algo was triggered in both crosses almost at the same time while the futures were retracing.  Let see how these currency futures behaved during the day:

Euro FX

As I said before, the algo was triggered just after 11:30 London Time. I was a bit surprised but all of the conditions were met and the algo sent the market order. After that, I was monitoring the pile of red candles until 12:45. At that point, the market started recovering. Considering the news, I hoped that the market would break the highs of the day.

6E 06/20 trade chart
6E 06/20 trade chart


At the beginning of the US trading session, the news started coming up.  The FED approved the new loan to help to bolster local governments and small and mid-sized businesses. Obviously, all central banks and governments are trying to help their economies as much as they can. I believe that some of the measures will be highly effective while other ones will only help to increase the debts of the countries. At the same time, the initial jobless claims data was released. It was far worse than expected. The Euro rocketed from 1.0900 to 1.0960. After this moment, the market stayed ranging between 1.0940 and 1.0960 for four hours.

British Pound

6B 06/20 trade chart


The case of the British Pound was exactly the same but the daily range was lower than in the Euro. As you can see the retracement was bigger in the GBP/USD at least until 17:30 where it rebounded aggressively.

Trades and Account

It was a great day in terms of profit. The algo generated $3220 in the Euro and $688.75 in the British Pound.

Realized profit by the algo applied to EuroFx and British Pound Futures
Realized profit by the algo applied to EuroFx and British Pound Futures
It was the first day with a positive P/L and it was a boost to my confidence.

Account


Summary

When you have an algorithmic or even a simple trading strategy is difficult to deal with the news and the macroeconomic data releases. In the example shown, the market when in the direction of the algo but you should be aware that sometimes it will go against you. I would like to recommend to always use stop losses.

Sunday, 12 April 2020

Day 5, Profit after a hard day


The 5th day was a positive day. It was the first day in which the algo was triggered in Euro FX future, known as 6E in CME. Until this moment, the algo was executing orders only in the British Pound futures. Let’s have a look at both instruments:

Euro FX

The algo performed very well showing its real purpose. It entered long in a retracement and luckily after that, the Euro went up. It was a very directional day.

6E 06/20 

 
As you can see there were only 2 moments in the day in which the position was losing money.


Orders 6E 06/20

The final profit was $1657.50. 


British Pound

As I said before this currency cross has been recently quite volatile in comparison with the Euro/USD. I believe that the news has a bigger impact on this instrument.

6B 06/20


I was looking at the different parameters when the notification popped up on my screen. At that moment, I had a feeling that this trade couldn’t end up in profit. I saw the P&L falling continuously for an hour. After that, the price went up to the point in which I entered. I felt a little relieved but I knew that it won’t last. It dropped again making a double bottom. Even if I don’t believe or follow the charts, I had a little belief that maybe the price will go up again breaking the confirmation line. I was right. The price went from 1.2292 to 1.2395. As soon as the US trading session started, the USD raised versus other currencies. This pair plunged to 1.2303 from the maximum of the day. I believe that after a big movement the prices always revert to their mean but we need to be careful in the current situation. I was lucky because the price recovered more or less 60% of the last downside movement and at that time, my algo closed the position making a small profit.


Trade 6B 06/20


As you can see the MAE shows that at 1 point I was losing more than $1400. We can also see a big MFE showing almost $1800, that was reached after the double bottom. Sadly, as you know, even if it’s not real money, the final profit was far from the MFE. This is why the End Trading Drawdown shows up as $1373.75 the difference between the maximum favorable excursion and the final profit.


Final Profit


The final result was $2127.50. I was happy to have this profit after the losses from the previous week.

Thanks for reading this post. 

Friday, 10 April 2020

The algo, day 1, 2, 3 and 4


Hi, I would like to start this post introducing the idea behind the algo. Also, I would like to highlight that this is not financial advice because the purpose of this algo is to participate in a simulated algo trading competition.

Current situation

One of the first questions that came to my mind was about the current situation with the Covid-19 and how it would evolve during the competition. At that point, was very tricky because it’s very difficult to forecast the future and to be honest, I don’t know how the markets will react to the help provided by the central banks. I see some similarities with the financial crisis, but I believe that there are more unknowns and the lockdowns extensions can trigger some bankruptcies for small and medium businesses. This will result in a decrease in consumption and the gross domestic products will reflect this as well. The financial situation of some companies and individuals will deteriorate and this will affect the banking sector. This issue can have a domino effect. Luckily, the central banks and the national governments are taking measures to try to avoid the spread of the disease and try to go back to normality (even if it’s done gradually)

The algo

I was considering different types of algos before the competition. As you know, some of the most important algo types are:
  • trend following 
  • mean reversion
  • volatility breakout
  • range algos

As I explained in the previous paragraph, the situation was one of my biggest concerns and I was expecting the volatility to continue at least for 3 months. Considering that the central banks were approving measures, I thought that the markets could have some rebounds. This is why I decided to design an algo that is able to catch the trend after a retracement. The main indicators used are two Exponential Moving Averages and a Stochastic.

I chose the Euro FX (6E on CME) future and the British Pound future (6B on CME) and every time that the algo is triggered, it sends a 5 lots order.

Day 1, 2 and 4


The algo was triggered only in the British Pound futures during the first 4 days. I lost $655 in the first trade, as you can see it wasn’t the best day. Its maximum adverse excursion was $875 and the maximum favorable excursion was $500 (this explains that the position was showing $500 profit at a certain time during the position was open) 

The second day was far worse because it hit the stop loss. The similarity with the first trade is the maximum favorable excursion that reached $562.5 at some point during the session.

I didn’t have any entry on the third day.

Finally, I had a small profit on the 6th of April. It was the most volatile day.




Summary

I have introduced a brief opinion of the current situation and I have explained how it was one of the most important facts to choose the algo for the competition. I have shared the idea of the algo and I have reviewed the first 4 days. I will keep posting how the algo is performing and interesting facts that can explain some movements in the Euro and the British Pound futures.

Wednesday, 8 April 2020

Robotrader2020, algorithmic trading competition


I decided to participate in Robotrader and I believe that is worth to share my experience here.

I consider Robotrader as one of the referents in algorithmic trading education in Spain. It offers a series of lectures or seminars with some of the best professionals in algorithmic trading, investment banking, and technology.  In addition, it holds a competition in which the participants need to create an algo to trade automatically for two months. This is the 10th edition and it’s been a great so far.

The main purpose is to introduce the world of trading and automatic investing to students and invite them to do it using different programming languages.
I think that it is a great initiative even if you have knowledge about investing in financial markets. It is very difficult to find professionals with knowledge in both areas. To be honest, it helps you to understand how difficult is to try to merge one traditional area like trading with technology. Obviously, it depends on each student, some of them will focus on high-frequency trading systems while others will focus in a more traditional trading system.  One of the things that I like the most is that it challenges you on the technology side. I mean, it’s not only programming the algo. It involves making research, try to understand how the markets move, designing the algo, backtesting, optimizing, choosing the right money management system, and putting this in production through a paper trading account. And when you think that you are done…  don’t forget to deal with connectivity because if you don’t connect, the orders won’t be sent to the exchange.



I will be sharing my experience during the competition. It started last week so I have a couple of articles to post.

Finally, I would like to thank the Universidad Politecnica de Madrid (and everyone that is supporting this event) for this initiative.  Please see this link if you want to have a look:




Thanks for reading this post. 

Saturday, 18 November 2017

How can we make a strategy profitable modifying a couple of things?

Nowadays trading is in vogue, even more, if we consider the new cryptocurrency trend. Basically, everyone wants to jump in. The trader lifestyle is desired by all the people. Sadly, trading is harder than what the social media shows. The industry is changing a lot. Concepts such as machine learning, artificial intelligence are taking importance in leading investment banks and hedge funds as they are heavily investing in it.

Why do the biggest companies invest in machine learning, artificial intelligence, and algorithms?


It´s very difficult to replace an experienced trader because he knows how to adapt the strategies in different economic cycles and conditions. Some hedge fund managers are hiring a lot of developers and programmers to create algos that emulate the behaviour of their best traders. This seems really expensive, at least in the first years, but I believe that in the long run will save money for the hedge fund. How can you emulate the trader behaviour? In my humble opinion, I would divide the strategies applied by the trader in little pieces and I will study the trader´s track record in order to study the conditions (price, type of order, macro events on that day, news) of the trades. Once I understand the reasons I will try to replicate its piece of strategy and I will code it. Once it’s coded and tested, I will assign a subaccount to use this strategy and I will do the same process for each strategy. To sum up, I will have a trading account made-up of subaccounts that run a specific strategy. We can say that the main account is the portfolio and the subaccounts are different traders or fund managers.
This process can take a lot of time and some parts can be difficult to replicate.

What aspects should we modify to make a simple strategy profitable?


The strategy is based on the EURUSD futures but I'm not going to explain how it works. The main purpose of this post is to show you how to modify a simple strategy to improve the profitability and reduce the risk. It only trades once a day if the conditions are met. This backtest shows the last 5 years. The initial portfolio was 50000 USD.

Plain strategy



This is the strategy without any modification. 

     Statistics of the strategy, own elaboration using RStudio

The mean is positive and it shows that the system will make on average 16.21 USD per day. Sadly is not that easy, because there are winning days and losing days. The best day it banked a 3250USD profit. On the other hand, the worst day shows a loss of 2440 USD. The Sharpe Ratio is very low. The returns’ distribution was a normal distribution around 0. The main problem is that there were trades that lost a big percentage of the portfolio. This is why I decided to limit the loses in the second strategy. Let’s see the maximum Drawdown.


     Max drawdown and track record of the strategy, own elaboration using RStudio

Any serious investor can’t tolerate this drawdown considering the size of the portfolio. I wouldn’t be confident to use this system after reviewing the track record. Basically, it goes sideways.

Strategy 2, limiting loses


In this case, I decided to limit the loss to 600USD per day. Let’s see if the system has improved or not.



     Statistics of the strategy, own elaboration using RStudio

In general terms, this system is worse than the first one. The system makes 15,19 USD per trade on average, which is  1 dollar less than in the first strategy. The worst loss has been limited but the distribution contains more days on the negative side. The days with big swings generated the most part of the loses. The return is only 19.96% in the backtesting.




     Profit and Loss from trades distribution, own elaboration using RStudio

The losing days are concentrated around the maximum loss allowed.


     Max drawdown and track record of the strategy 2, own elaboration using RStudio

The distribution is not appealing to me. The best thing is that the max drawdown is smaller than in the first strategy. This system is clearly limited by days with big ranges.

Strategy 3, looking for different entries


Once I limited the losses of the first system and I checked that it wasn’t working as I would like it, I decided to change my entries. Will this be the solution?


     Statistics of the strategy, own elaboration using RStudio

Modifying the entries improved a lot the system. Now the system mades 49.88 USD per day. The standard deviation is lower. It would have returned 81.4% in 5 years, around 17% per year. What a change!! The winning days' percentage has increased and the Sharpe Ratio is very good. You should think that the commissions are not included.


    Max drawdown and Track record of the system, own elaboration

This is the best point. Look at the line! Now the system is consistent and the maximum drawdown has decreased a lot.

Conclusion


Even if you have read or heard about a successful trading system, you shouldn’t trade it without testing it before. We have seen that with minor tweaks the strategy can improve a lot. I hope that this post will help you to understand the process. The sky is the limit, in this field, the creativity doesn’t have limits. If you are a professional trader this can help you to test ideas and become more confident. Another important point is that you shouldn’t invest in these strategies even when the statistics are good. You should test them with a paper trading account and compare that the behaviour is similar to the previous backtesting. This is crucial because there is the risk of overfitting. I hope you like.

Have a good trading!



Disclaimer

I wrote this article myself, and it expresses my own opinions that shouldn't be used as a trading advice. Trading carries considerable risk due to the high leverage involved

8th day small profit that helps me to keep going in the competition

After a successful week and most importantly from recovering almost $6k, I wanted to consolidate my positive results. My desire was to b...