Showing posts with label trading system. Show all posts
Showing posts with label trading system. Show all posts

Wednesday, 5 September 2018

Simple trading system, does it work in the Nasdaq?

Introduction

There are so many trading styles and the traders can take their decisions from technical analysis, important levels, value investment, quantitative analysis, price movement, and order book study. Some of them combine more than one method at least to have another point of view or to have another idea generation source.

Nowadays, it's easy to find resources for trading. There are plenty of resources online, such as videos and courses. If you are more traditional, you can search for books and see what the people are saying about them.

Some of the most successful traders are known for being contrarians. What does this mean? Maybe they are aware of how powerful the trends could be, however, they are not investing for the long term. They are looking for a quick profit in a short period of time (depends about the how big is the position, who is executing and what are the targets, it can last from a few seconds to less than 3 months).  How do they act? Basically, if a stock or a future has been raising for a while and has a strong trend, they can consider that the product is overvalued and that it will revert to the moving average or at least it will revert enough to make a profit.

The idea

Now, we know what they do. I always thought about it. One of the problems is the timing when I should enter into a trade like that. There are so many statistical methods that you can apply to that. It can be based on the number of days (imagine that the stock has been raising for the last 60 days and you think that every “X” days, there is a retracement), it can be based on the price change (that you can consider it overvalued), it can be a combination of both. We can see that creativity is another part of the trading research. Probably, I will write a post about the whole process in the future but today we are going to review a simple idea.

The trading system is contrarian so it will consider yesterday % change. If yesterday the stock or the underlying product went up, the system will sell it today. And the other way round, if the stock fell yesterday, the system will buy it today.

Nasdaq


I’ve chosen the Nasdaq index as an example. It represents the technology stocks.

    Nasdaq continuous future, daily, source: TradingView

It hasn’t stopped rising since 2010. I wanted to show the period 2014-2018 that I will study in this article. Considering the strong bullish trend maybe I shouldn´t use a contrarian system. I will show you that one of the most important aspects is the risk management (always combine with a profitable system)

Backtest example

Before we start, I need to explain a couple of things. In my opinion, the market behaves differently when it goes up than when it goes down. The falls usually are very sharp. This is why I decided to choose a tighter stop for the sells. I’ve chosen the stops randomly, the buys have a stop of 4 ticks and the sells have a stop of 2 ticks. Let’s check the results:




                                        Backtesting, own elaboration using R

Good news! The mean is positive which is a good starting point. However, making $9.53 per trade is not enough without considering fees and slippage. The system makes $2190 on the best day. The worst lost is $20. The kurtosis is really high because all the values are concentrated around 0. To be honest, the system only makes money on the 3% of the trades. So it’s not tradable even if it makes 103.65% in four years. It would be great if the system had more entry requirements and the number of trades would be reduced. That way the statistics would improve a lot. The Sharpe ratio isn’t great. 



                                                           Max drawdown, own elaboration using R

Considering that the trading system loses in 97% of the trades, the max drawdown is very good. Obviously, each time that it loses, the amount is very small (around 0.2% of the portfolio)



Trading strategy performance, own elaboration 

We can see the characteristics of the system. A few profitable trades and a bunch of losing trades. The probability of taking the loss is very high with our tight stop losses. In other hand, every time that we are right, we make a lot of money.

Sum up

Sadly, there isn’t a good conclusion for this post. I think that I have a lot of work to improve this system.  In addition, this is not a professional way of running a backtest. We should have a period of time in which we test our idea, another period for optimization and different windows of time to test the optimized parameters. Also, we should always consider broker fees and slippage. The system shown is not tradable but it shows that a sounding risk management system is very important. Another idea that we should take from this post is that even a contrarian system can perform in a market that has a clear trend. 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


Thursday, 28 June 2018

Momentum system


Sometimes we look for a clear trend in the different markets. This can be difficult these days because the volatility is back. I believe that there are many opportunities but you need to adjust the strategy’s timeframe. Obviously, when we see the chart at the final of the day,  it´s easy to see the levels where we should have bought or sold. I would be happy as far as you do this in order to learn the order flow and how the news affected the security. However, you shouldn’t take seriously the important levels of the day (if you are only checking the day instead of a longer timeframe) because anyone knows what is going to happen tomorrow. I wouldn´t like to discourage you if it works for you but in my opinion is like singing “if I were a rich man” without trying to make money.

Why is the data important? Introduction to the system

As I said indirectly in the first paragraph, I don’t know what the asset prices are going to do tomorrow. The most important for me, leaving my thoughts apart, is the historical data. Here is where statistics takes importance. Let’s get biased for a minute thinking that every time that the price is above an indicator (or another variable) we should buy and every time is below the chosen variable we should sell.


Let´s take the Moving Average 9 as this variable and check the probabilities.

                                               Probability table, example own elaboration

Only to sum up, we have a buy signal every time that the opening is above the MA9 and a sell-side every time the opening is below this indicator. This example is not the best one. I wouldn’t publish this screenshot in a book. Apart from this joke, we had 426 buy signals but only 203 days that the future closes above the opening. Investing in a strategy that has 47.7% success ratio doesn´t seem the smartest thing to do but this is where the money management comes! In the case of the sell signals, it's slightly better showing 52.4%.

Backtesting

Before I show the results I would like to confirm that I´ve used the 5-day moving average instead of the MA9.  The main reason is that the performance was better and the drawdown was lower. This test has been done with the FESB historical data (Eurostoxx Banks). The reason why I chose this product is because I thought that it was directional enough to apply the strategy.





                                                  Backtesting statistics, own elaboration using R programming

As you can see the backtesting results are not bad. Each trade generated 6.42 EUR on average. The biggest win was 740 euros which is great considering that we started with 10000 EUR. I used a tight stop loss, only 2 ticks. Even with that, we can see that the FESB is very directional and the stop was hit only on 53% of the trades. The return has been 56.60% in almost 3 years and a half.



      PnL curve, own elaboration using R programming


The most interesting thing is that after the max drawdown (1570 between the 98th day to the 270th day) it has been rising. Obviously, when your portfolio has grown and you are using the same money management and risk management, the drawdowns are smaller than at the beginning. 



                                                      Max drawdown, own elaboration using R programming


Each trade was simulated with 2 lots and the maximum daily loss was 20 EUR (2% of the initial capital)

Sum up

I like analyzing trading systems and I´ve been working on this strategy for a while. I´m surprised about its performance because I expected worse statistics. Surprisingly, the % of successful trades were almost the same as the previous example shown above. This post doesn´t show the real performance because the commisions are not included. I will write a post in the future explaining why the short-term moving averages fit better than the long term in this kind of 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

Saturday, 6 January 2018

Trading system based on proprietary indicator, Part 3


This is the third part of the series of posts about the trading system based on my own indicator. We will see how the commissions affect the performance of the system. I will compare with the benchmark in the future.

Comparison table




Comparison table including the backtesting with the commissions included and deducted from the portfolio, own elaboration

As you can see there are big differences between the backtesting without commissions and the ones that include them. The daily average return differs in the amount I chose as a broker fee. In this case and considering the size and the price of the security, I decided that the commissions will be 40 Euros per trade (20 Euros per side, buy and sell) Obviously the maximum and minimum daily profit differs in the amount of the broker fee. (There is one problem that I haven't fixed in the 10 Yrs backtesting and 10 Yrs backtesting with Fees. The max profit differs due to an early error in the data) The skewness and kurtosis are exactly the same. The returns have been significantly affected by adding the commissions and taking out the value of the portfolio.In the case of the 5 Yrs Backtesting the return is almost half due to the commissions. Considering that the system trades the same size all the time, this issue was expected. The advantage of that is that as soon as the portfolio grows, and even if the loss is the same amount as the beginning, the loss represents a lower percentage of the portfolio. I chose this way as a risk management in which I risk more in the early years while the portfolio is growing. Probably I should link the trade size with the value of the portfolio but depending on the system or the period studied can generate worse performance and could be riskier. The Sharpe Ratio is affected as well because the returns are lower. Another important point is that including the fees the max drawdown is worse than the one shown before. Depending on how we invest our savings, we should run an extra spreadsheet with all the cost related to the investments. 


Graphical description of how the fees affected to the different backtesting


5 Years test


    Differences between the portfolio with and without commissions, own elaboration


Sometimes a chart represents an idea better than the words. Here we can see the impact of the commissions in the system. The difference in the last trade is almost 5000 Euros. The system returns 37.15% which is the equivalent to 7.43% per year. It´s a good return considering the risk taken. The system without including commissions returns more than 12% per year.

10 Years test


     Differences between the portfolio with and without commissions, own elaboration

The differences are bigger in the 10 years study. The difference between both systems is 28000 euros. At this point is better not to do these numbers, giving away this amount of money is crazy. The best aspect is that after fees it returns an incredible 425%.


Sum up


I hope you like it. You shouldn´t focus on the effect of the commissions or the performance. The most important idea is considering all the cost related to running the trading system or the investments. In this case, I simplify the idea considering that a broker executes the trade on your behalf. If you trade on your own, you should add the market data, the brokerage commissions, and the trading platform costs. There is another point that I haven´t commented, the taxes. Sadly the trading costs and the taxes (if you make money) will reduce your profits.

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, 26 November 2017

DBK Trading System

Deutsche Bank is one of the biggest banks in Europe by total assets. During the last years, it has been struggling to adapt to the new low-interest rate environment.The losses from the financial crisis were very big. In addition, the big provision for fines and lawsuits drove its profitability to the negative side. Therefore, its shares have been dropping these years. In response to these problems, John Cryan, Deutsche Bank CEO, decided to implement a restructuring plan some years ago. 

    Source: TradingView, Deutsche Bank shares, daily

Even with the above, I believe that this bank offers value from a trader or investor’s perspective. Analyzing this bank is not the purpose of these post.  

Trading System Intro


I consider Deutsche Bank as one of the most important banks around the world and I believe it will be a reference in the coming years after resolving its problems. This is why I created a short-term trading system to buy the weakness of the stock. The system is based on risk management, the maximum risk taken per trade is 1% while the take profit is set at 10%. With these numbers in mind, we can expect a lower rate of successful trades.

Backtesting from the 30/10/2013 to 17/11/2017


Let’s see the theoretical behaviour of the system


     Statistics of the DBKT trading system, own elaboration using R Programming

The system makes 84.20 EUR per trade on average which is 0.8420 EUR per share considering that it trades 100 shares each time.  The distribution of returns is not as good as I would like it but I expected this problem before I tested the system. The biggest profit was 2290.05 EUR. The worst trade lost 478 EUR. It would have made 5304.77 EUR profit which is the equivalent to 26.52%. It’s a modest return but as we will see later it’s adjusted by risk. The Sharpe Ratio is good.

       Return’s distribution, own elaboration

Sadly some of the returns were worse than the max loss of 1%. This was due to the gaps in the opening. There are ways to solve this problem but it’s interesting to see this kind of problems in order to avoid miscalculations in the future. 


     Max drawdown and performance of the system, own elaboration

As you can see the worst loss was 2773.79 EUR which was the equivalent of a 12% loss for the portfolio.  However, the rise of following days offset the loss and drove the system to profitability. After that, the system was steady without important changes.

      Portfolio evolution, own elaboration


To sum up

We have seen a simple trading system applied in DBK equity. I would like to remind that analyzing this company wasn´t part of this post. I've chosen this security for its volatility. This system hasn´t been improved and it had some problems addressed above. The performance is good considering the 12% max drawdown. I've played with different portfolio sizes before publishing this post but I thought that the 20000 EUR portfolio was the best in terms of risk-reward. A 10k EUR portfolio would have returned 40% profit with 23% max drawdown but I prefer smaller drawdowns. 
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



Sunday, 8 October 2017

Quantitative Strategy FGBL Futures

Some time ago, I was checking some charts when I decided to create an algorithm. The product chosen was the FGBL, the Euro-Bund futures. Basically, I thought that was a relationship between the past and the future. It sounds familiar, doesn't it? I found the historical and I started working on it.
First I run the strategy without any stop or money management strategy but I was disappointed with the results. Sadly I don't have any screenshot of that.
Second, I decided to apply risk management and limit the amount I could lose.
This improved a lot the strategy but I wasn't happy at all. Using my background, reading, and learning, I started applying money management. It had a better risk-reward, but it was riskier. I backtested this system from the 04/01/2016 to the 30/12/2016.
These are a couple of tables that explain some ratios: 

Initial Portfolio
50000 euros
Final Portfolio
77140 euros
Annual Return
54,28%
Positive days
457
Negative days
548
Positive trades (% of the total)
44,46%
Negative trades (% of the total)
53,31%
Mathematical Expectancy
9,1299
Positive days average
192,36 euros
Negative days average
-143,99euros
Max Drawdown
28,55%












Portfolio value
Lots
Max risk per trade
40000 euros
3
1.5%
60000 euros
4
1.33%
80000 euros
5
1.25%
Please have in mind that I haven't included the cost of trading (execution costs, market data, trading platform) I believe that the execution cost would be around 12-13k, so the profit would be half of the figure shown above. It's riskier than a normal hedge fund because they normally have less than 20% drawdown. The asymmetric leverage is really important. I've never traded with this system and I can adjust the risk management and the money management to meet certain goals. I should have backtested at least 5 years and then do the out of sample to check that it behaves like the backtested sample. This is only an example of how to design a trading system. 

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