Showing posts with label performance. Show all posts
Showing posts with label performance. Show all posts

Monday, 13 April 2020

6th day, no gain no loss…



As you can imagine after reading the title, it was a flat day. Actually, I made a small profit but it didn’t cover the commissions. Let’s see what happened during that day in the EUR/USD and GBP/USD futures:


British Pound


It was a directional day for the British Pound without any big spike or swings as we saw in the previous days.  This was explained by the increase of COVID-19 cases in the US and the expected approval of further help by the FED.

6B 06/20 


It raised almost without stopping until 14:30 where the price was ranging between 1.2387 and 1.2405. In one of these retracements, the algo was triggered and it sent a buy of 5 lots. I wasn’t sure about opening the position considering its morning trend and range. One of the best aspects of using algos is that we remove discretionary decisions and feelings. After entering in the position, like the most part of the times, the GBP/USD futures fell to 1.2374. After that, it rebounded breaking the highs of the day and it reached the 1.2429 level. It couldn’t breach these levels and it went back to 1.2400 where the algo closed the position.

6B 06/20 trade chart


This chart shows more detailed of what I explained in the previous paragraph.

6B 06/20 trade


In contrast with other days, the MAE ($437.50) is around 1/3 of the MFE ($1281.25) and this shows how well the market behaved for the algo I’m using. One of the problems is that the ETD is still high because the algo is not closing with a signal. Until now, the algo has closed according to the time configured.


Euro FX


The Euro vs the US Dollar didn’t have a clear trend. It was a total swing. It seems that the EUR was stronger in the morning while the USD took its place in the afternoon.

6E 06/20


As you can see, and as it was expected, the algo was triggered in a retracement. It performed well during the first hour. After that, the Euro dropped strongly but seems that the traders didn’t believe in this movement and the buying pressure took the price to the point in which the position was open. At this point, it continued to rise to 1.0909 where the dollar strength came back. The position was closed at 17:08 London Time

Trades and account balance


I didn’t get profit in both trades. I lost $398.75 in the EuroFX trade including commissions and I won $395.75 in the British Pound also including commissions.

08/04/2020 trades


I shouldn’t be upset… I made a profit without considering commissions. At the end of the day is not real money and this is good learning and I would like to remember that in my opinion the commissions and the slippage should be included when you are backtesting a system. In my experience, if the system is not good enough this will make the difference between making profit or loss.

Account Balance


One of the conclusions that I found in the first 6 days is that probably I should implement a fixed take profit or maybe consider a trailing stop. It’s early to say but probably I will run some tests to see if the statistic ratios are better than my current algo.

Thanks for reading this post!


#algorithmic_trading, #Trading, #Euro, #EUR, #GBP, #British Pound, #USD, #EURUSD, #GBPUSD, #Dollar, #performance, #profit, #loss, #FED, #COVID-19, #Robotrader

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.

Sunday, 4 February 2018

Buy the red candle strategy


We have seen how the indexes around the world have been raising since the financial crisis. Obviously, the best strategy was buying in 2009 and holding. I’d like to introduce a trading system based on buying at the final of the day if the underlying is down “X”% and selling before the close of the following day.
In order to make it simple and with statistical meaning, I decided that the system would buy when the underlying security is down 0.20% or more.
The underlying
I´ve chosen the Vanguard S&P500 ETF that is an exchange-traded fund that tracks the S&P 500 index. The ticker is VOO.


     VOO, daily

The period studied is from 2012. As you can see this ETF has doubled like the S&P500.



     VOO daily returns own elaboration

The most part of the daily returns were positive for the period studied. I would like to highlight that there were more down days in the first 4 years (2012 to 2016) than in the last 2 years. As you can see almost every negative day trigger the signal to buy.

Performance of the system


Now it´s time to check the performance of the system. Sadly is not as good as the buying and holding strategy. The starting capital is 100000$.


       Trading system statistics own elaboration

The system returns 94$ per day on average. The maximum profit was 4372$ while the worst loss 4634$. I don´t like the fact that losing this amount of money in a day so it would be interesting to set up a reasonable stop loss. The system returns 43084$ in 6 years without considering commissions. The winning trade ratio is not that good, but we can optimize the target return to trigger the signal in order to get better results in terms of performance and risk. The Sharpe ratio is not that good.


       Maximum Drawdown own elaboration

The maximum drawdown was 13269.14$ which was the equivalent of 11.90% of the portfolio. As far as the drawdown is below 20%, I’m happy.


    Portfolio performance own elaboration

It has grown consistently but as I said before I would like to see a smooth line. Adding a stop loss can improve the trading system.

Sum up


We have seen a simple trading system. Sadly on this occasion, its performance is worse than its benchmark. There are a lot of things in which I can improve this system such as adding a stop loss or modify the return that triggers the signal. We need to be careful with the overfitting. In addition, the commissions are not included in the trading system. I hope you like it.

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

#ETF #performance #Rprogramming #risk #S&P500 #systematictrading #Trading #Vanguard

Thursday, 7 December 2017

Trading system based on proprietary indicator, Part 2


Today I will show the trading system behaviour from October 2008. Let me introduce the macro situation before I review the backtesting results.

Brief description



The financial crisis started later in 2007. The stock market suffered a big correction in 2008. The volatility was far higher than nowadays. The central banks implemented the quantitative easing programs in order to stabilize the economies around the world. This is an example of the German Dax index and the Eurostoxx index.

     Source: TradingView, DAX vs Eurostoxx futures, daily, from 2008 to 2018


Results from October 2008


      10 Yrs Backtesting results, own elaboration with Excel and RStudio

The main difference is the volatility in the underlying. As you can imagine later in 2008 the volatility was really high and the stock market was in free falling until it bottomed in 2009.
As you can see the big bounces in 2008 are the reason for the big range shown in the backtest.

Comparison with the 5 Yrs Backtesting

                                          Comparison between the 5Yrs and 10Yrs backtesting, own elaboration

You can see a big improvement in the 10 Yr study vs the 5 Yr. The average profit was 151.28 EUR vs 95.86 EUR. The standard deviation and variance were higher due to the volatility from 2008 and 2013. The range is bigger as well because the stock was trading higher. Considering the strict risk management, I´m surprised about the winning trades percentage. I believe that a mean reversion strategy was the best one at this time, even more with the actions taken by the central banks. In addition, the return’s distribution changed and it shows higher extreme figures (in the positive side, which means a high probability of bigger profits) The system traded 733 times vs 130 times in the last 5 years, the profits are concentrated in the first 300 trades. The Sharpe Ratio is slightly worse.



                                          Max Drawdown, own elaboration using RStudio

I´m happy with this figure, losing 2820 EUR was the equivalent to 3.16% of the portfolio. This is a very conservative figure which I consider ideal. Sadly this is not applicable to another kind of strategies because the system opens and closes the positions on the same day.


         Portfolio growth, own elaboration using RStudio

There is not much to say about this chart. You can see the change in volatility from the first years to the recent years. The biggest profits are concentrated in the first 300 trades. The initial portfolio was 20000 euros. I haven´t included the commissions.

Sum up


We have seen how this system behaved during the last 10 years. You can think that is overfitted and this post doesn´t have value because I tested the system in the right period. This is not the purpose of this little article. I´m surprised with the performance but if you had bought the Dax in 2009, you would have multiplied your portfolio’s value by almost 4. In the next post, I will compare the trading system vs the DAX. I hope you like it. Thanks for reading.

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

Sunday, 3 December 2017

Trading system based on a proprietary indicator Part 1


This is a new concept. I will do three parts to analyze the trading system in a better way and compare it with a benchmark. The idea is introducing the trading system, showing the backtesting (last 5 years), comparing with the 10 years backtesting, studying the system vs the benchmark and applying money management to see how the performance and risk parameters change.

Brief explanation of the trading system


The system is based on a proprietary indicator as you can see in the title. The idea behind this system is mean reversion. The levels are chosen from the study of the returns’ distribution. Does it sound familiar to you? In addition, a strict risk management system has been applied. The maximum loss allowed is 0.5% as we will see in the next points. The trading system trades 1000 shares in each trade (in the future I will apply money management) The initial portfolio

 


Results after the last 5 years (backtesting)



Backtesting statiestics from RStudio and Excel
     Backtesting statistics from RStudio and Excel, own elaboration


As you can see the system makes 95.86 euros on average per trade. I would like to make clear that the system traded 133 trades and the commissions are not included. The maximum profit in a trade was 1650 euros while the biggest loss was limited to 100 euros.  The return was 12750 euros which is the equivalent of 63.75% in 5 years (around 12.75% per year). As you can imagine, considering the strict risk management, the losing trades percentage is higher than the winning trades percentage. But the average winner is higher than the average loss. The Sharpe Ratio is 4.32, which confirms the profitability of the system.



Max Drawdown, own elaboration
                                  Max Drawdown, own elaboration using RStudio


This is the measure that I like the most. The system only loses 925 euros in the worst trading period. If we check in percentage terms, it represents a 3.53% loss. According to the asymmetrical leverage rule with a gain of 3.57%, we offset the loss. This shows the importance of risk management.

Portfolio performance
      Trading system track record, own elaboration using RStudio


Here you can see how the portfolio has been performing. The most important is its consistency.

As a curiosity, performance comparison with different initial capital


comparison

With these numbers, we would be tempted to invest 5000 euros or less. The system doesn’t require a lot of capital. The main problem with a 5000 portfolio is that we will struggle because the costs are not included and we couldn´t trade 1000 shares each time.


Conclusion


This has been the first part of a series of posts about the same trading system. In my opinion, the performance and the risk metrics are good. In the next post, I will review the 10 years backtest. The purpose of that is to check that the system hasn´t been overfitted for the last 5 years and show how it performed in a longer period. I hope that you like it.

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



Thursday, 9 November 2017

Why should we use R to backtest some strategies? Quantitative approach

We live in a technological era. Basically, we can have whatever we imagine. Walt Disney said once: “If you can dream it, you can do it”. What happens if we put together the technology and the investment world?


Algo Functionality or develop from scratch with a programming language


I know that there are a lot of trading platforms that offer their own easy language or built-in algo functionality, sadly, in my opinion, is not flexible. Let me explain in a better way, you can do a lot of things but mostly it’s focused on Technical Analysis.
Using programming languages allows you to apply whatever you have in mind as far as you can code it. However, it´s more difficult and learning takes time. There are a lot of books and online courses.  
I started with R a couple of years ago. It’s an open source programming language and software environment focused on statistics. I think is one of the easiest and it has similarities with Excel. There are a lot of specific packages that contain different functions and studies. It’s a powerful tool to backest some strategies.

     R Studio screenshot, own elaboration

Create your own systems


Let me sum up some of the advantages and disadvantages of developing a trading system in R.

Advantages

  • You can analyze and backtest large datasets
  • The statistical insights you get from the data can help you to build new systems.
  • It’s more flexible, you can base your decisions purely on the data or even support with some technical analysis.
  • You can optimize the different variables and see how it affects to the system
  • Once the system is live, the risk management won´t be discretionary and you will know the maximum risk you are taking.
  • Attaching  risk management systems and money management systems provide interesting scenarios to consider


Disadvantages

  • Takes time to learning about programming
  • I would recommend to have a good knowledge of trading or investing
  • You will find out that the most part of your ideas are not profitable
  • Programming some of the trading ideas is challenging
  • Linking with the Brokerage API can be difficult


Successful Hedge Funds and Market Makers

There are a lot of Hedge Funds that are known for their specialization on systematic trading using only quantitative models.  Renaissance  Technologies is well known in the sector and they started this way of trading a long time ago. In the recent years, more hedge funds are following these methods and some of the reasons are above. Developing and applying these systems are the hardest part.  Can we emulate this activity in our home? Well, in my humble opinion, we can try. First, we should now that our possibilities are reduced in comparison to a hedge fund or investment bank. These companies employ big teams of people, they can afford to invest money in the latest technology and they have been a long time in the business.

What is the process I follow?

First is the idea generation. Before this step, you should be familiar with the product and understand how it moves. It can be as simple as buying at 9:00 and selling after 5 minutes. You can complicate as much as you want but you should think that you need to code it later. Adding variables to the system will reduce the times that you trade and you will need a larger data sample to meet statistical significance.

Second, you need to download the data from your trading platform or data vendor. Remember to check if the data contains any error. Even if you know the product, I recommend analyzing from a statistical point of view. This can provide you better insights than the chart. The size of the sample should be big enough to meet the statistical significance

Third, code your strategy. Try to make the code as flexible as possible because you will need to optimize some variables in future tests. I would recommend focussing on the risk management and money management because they are key parts for the success of the system. Add ratios to measure the performance, the risk-reward, the biggest drawdown, the success ratio…

Four, applying the strategy to the data. If you are not happy with the ratios shown, try to optimize some variables.

The last step should be adapting your code to the brokerage API to execute the trades.

My little system


I’m not going to disclosure the strategy but it’s based on mean reversion. I chose the Euro-Bund (FGBL) for its liquidity and I believe that we can see significant moves in the near term. The system is designed to open and close positions on the same day. I do apologize for any error as the strategy is at an early stage. Let’s check how is performing from the beginning of the year.

The initial portfolio was set up as 20000 Euros.
    Statistics and ratios from the strategy, own elaboration using R Studio

Let me briefly comment these ratios. As you can see each trade generates 79.35 EUR gain on average, please consider 77 trades because the system doesn’t trade every day. The biggest gain was 910 EUR. The worst day it lost 620 EUR, which shouldn’t be right because I limited the losses to 250 EUR per day. After a while, I discover that it was due to an error in the data. The system has generated 6110 euros this year that considering the initial portfolio of 20000 euros brings a 30.55% return. The probability of a successful trade is 59.65%. The Sharpe Ratio is 2.38.




   Histogram of the closed trades, own elaboration

This is the distribution of the PnL generate by each trade. Sadly it’s concentrated around -250 euros and this is because some movements trigger the stops. 


   PnL Curve since the beginning of the year, own elaboration

I like this chart because it shows that in general terms the system is making money consistently. There are certain drawdowns that I would like to smooth if I decide to optimize some variables of the system.

Finally one of my favourites metrics, the maximum drawdown:


    Max Drawdown, own elaboration

The maximum drawdown is 2650 Euros which was the equivalent to around 10% of the portfolio at that time. It happened between the trades 51 and 62.
I think that the metrics are good, but discussing the performance is not the purpose of this post. You should focus on the process and how to get the advantage of that. Don’t think that every mean reversion system is profitable, I’m sure that if I change the risk parameters and I run the backtest again the system can show loses.

Conclusion


I hope you like it. If you like trading and coding, I recommend following this kind of approach at least for a second opinion. Some of the biggest hedge funds are investing in this kind of technology and they are trying to create systems that emulate the most experienced and successful traders. Thanks.

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


#trading #quantitativeanalysis  #tradingstrategies #tradingsystems #Rstudio #riskmetrics #performance #FGBL


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...