tomas.vanek

The Psychology of Back testing: Avoiding Overfitting and Confirmation Bias

Back testing is a common practice in financial analysis, where analysts test trading strategies using historical data. While back testing can be a powerful tool for predicting future market trends and generating profits, it can also be prone to errors due to two key psychological biases: overfitting and confirmation bias.

Overfitting occurs when a trading strategy is designed and tested using historical data that is too specific and too limited. This can result in a strategy that is too closely tailored to the past and may not perform well in future market conditions. Confirmation bias, on the other hand, occurs when traders only look for evidence that supports their preconceived notions about the market, rather than seeking out contradictory evidence that could challenge their assumptions.

To avoid these psychological biases and make the most of back testing, here are some practical tips:

  1. Use diverse data: When back testing a trading strategy, it’s important to use a diverse range of historical data that includes a variety of market conditions. This can help prevent overfitting by ensuring that the strategy is designed to perform well in a range of different scenarios.
  2. Test multiple scenarios: To further prevent overfitting, it’s also important to test the trading strategy against multiple scenarios. This can help ensure that the strategy is robust and can perform well even in unexpected market conditions.
  3. Use out-of-sample testing: In addition to testing a trading strategy against historical data, it’s also important to use out-of-sample testing. This involves testing the strategy on data that was not included in the original back test, which can help reveal any potential weaknesses or flaws in the strategy.
  4. Challenge assumptions: To avoid confirmation bias, it’s important to challenge assumptions and seek out contradictory evidence. This can involve testing the strategy against different data sets, seeking out alternative perspectives, and looking for evidence that contradicts your initial assumptions.
  5. Avoid data snooping: Data snooping occurs when traders search through large data sets to find patterns that may not actually be significant. This can lead to overfitting and false conclusions. To avoid data snooping, it’s important to have a clear hypothesis and methodology in place before conducting any analysis, and to be transparent about the data sets and variables used.

By following these tips, you can avoid the psychological biases that can undermine the effectiveness of back testing, and make more informed decisions about their trading strategies. Ultimately, this can help improve your chances of generating profits and achieving long-term success in the financial markets.

How Swap Rates are Calculated in MetaTrader 4 and 5

If you’re new to trading forex or other financial instruments, you may have heard the term “swap” being used in MetaTrader 4 and 5. In this post, we’ll explain what swap is, how it works, and how you can use this information to improve your trading performance.

What is Swap?

In simple terms, swap is the interest rate that is charged or paid for holding a trading position overnight. It is also known as an overnight or rollover fee. When you open a trading position, you are essentially borrowing one currency to buy another. The interest rate on the currency you are borrowing is usually higher or lower than the interest rate on the currency you are buying. This difference in interest rates is reflected in the swap rate.

If the interest rate on the currency you are buying is higher than the interest rate on the currency you are selling, then you will earn a positive swap. This means that you will receive a small amount of money in your trading account for holding the position overnight. If the interest rate on the currency you are buying is lower than the interest rate on the currency you are selling, then you will incur a negative swap. This means that you will have to pay a small amount of money from your trading account for holding the position overnight.

How to View Swap in MetaTrader 4 and 5?

To view the swap rate for a currency pair in MetaTrader 4 and 5, you can follow these steps:

  1. Open the Market Watch window by clicking on View > Market Watch in the main menu.
  2. Right-click on the currency pair you want to view and select “Symbols” from the context menu.
  3. In the “Symbols” window, click on the “Properties” tab.
  4. You should now see the swap long and swap short values listed for that currency pair.

The swap long value represents the interest rate you will earn for holding a long (buy) position overnight, while the swap short value represents the interest rate you will pay for holding a short (sell) position overnight.

It’s worth noting that the swap rate can vary depending on the broker you are using and the currency pair being traded. Some brokers may also adjust their swap rates to reflect market conditions or other factors.

How to Use Swap to Your Advantage

Knowing the swap rate for the currency pairs you are trading can be useful in several ways. For example, you may choose to hold a position overnight if the potential profit from the trade exceeds the cost of the negative swap. Alternatively, you may decide to close a position before the end of the trading day to avoid paying a high negative swap.

Some traders may also use swap rates to inform their trading strategies. For example, they may look for currency pairs with high positive swaps and hold these positions over a longer period to maximize their returns.

Positive Swap:

Suppose you have a long position in the AUD/USD currency pair with a trading volume of 1 lot (100,000 units of the base currency – Australian dollar). The current interest rate on the Australian dollar is 0.5%, while the interest rate on the US dollar is 0.25%. The swap long rate for this currency pair is +3.3 pips.

In this scenario, you will earn a positive swap of $3.30 per day for holding the position overnight, as you are borrowing the US dollar and buying the Australian dollar, which has a higher interest rate. If you keep this position open for one week, you will earn a total of $23.10 in positive swap ($3.30 x 7 days).

Negative Swap:

Now suppose you have a short position in the EUR/GBP currency pair with a trading volume of 1 lot. The current interest rate on the euro is -0.5%, while the interest rate on the British pound is 0.1%. The swap short rate for this currency pair is -9.8 pips.

In this scenario, you will incur a negative swap of £9.80 per day for holding the position overnight, as you are borrowing the British pound and selling the euro, which has a lower interest rate. If you keep this position open for one week, you will have to pay a total of £68.60 in negative swap (£9.80 x 7 days).

It’s worth noting that swap rates can change over time, so a position that was earning a positive swap one day may earn a negative swap the next day. It’s important to stay informed about current swap rates for the currency pairs you are trading to make informed trading decisions.

Conclusion

In conclusion, swap is an important concept to understand in forex trading, as it can affect your trading profitability. By knowing how to view the swap rate in MetaTrader 4 and 5, and how to use this information to your advantage, you can make more informed trading decisions and improve your overall trading performance.

CAGR: Understanding the Concept and Its Practical Applications

Compound Annual Growth Rate (CAGR) is a financial metric used to measure the growth of an investment over a specified period of time. It is a smoothed and annualized rate of return that represents the average growth rate of an investment over a certain period. It gives a more realistic picture of the investment’s growth rate by taking into account the effects of compounding over time.

The formula for CAGR is: CAGR = (Ending Value / Beginning Value)^(1 / number of years) – 1

Here, the ending value is the value of the investment at the end of the specified period, and the beginning value is the value of the investment at the start of the specified period.

Practical Examples of CAGR

  1. Investment in the Stock Market One of the most common uses of CAGR is to measure the growth rate of an investment in the stock market. For example, if you invested $10,000 in a stock five years ago, and its value has increased to $15,000, the CAGR would be calculated as follows:

CAGR = ($15,000 / $10,000)^(1 / 5) – 1 = 0.10 = 10%

This means that the investment has grown by 10% annually on average over the last five years.

  1. Retirement Planning CAGR is also used in retirement planning to determine the growth rate of a retirement account over time. For example, if you are saving $5,000 annually for your retirement, and after 20 years, your retirement account has grown to $200,000, the CAGR would be calculated as follows:

CAGR = ($200,000 / ($5,000 * 20))^(1 / 20) – 1 = 0.06 = 6%

This means that the retirement account has grown by 6% annually on average over the last 20 years.

In conclusion, CAGR is a useful financial metric that provides a more accurate representation of the growth rate of an investment over time. It takes into account the effects of compounding and gives a more realistic picture of an investment’s performance. Whether you are investing in the stock market or planning for your retirement, understanding CAGR can help you make informed investment decisions and achieve your financial goals.

The Sharpe Ratio: Understanding and Using it for quant trading strategies

The Sharpe Ratio is a widely used metric for evaluating investment performance and risk-adjusted return. It measures the excess return per unit of risk taken by an investment and helps investors compare different investment options. In simple terms, the Sharpe Ratio indicates whether an investment’s returns are due to smart investment decisions or a result of excessive risk-taking.

The formula for the Sharpe Ratio is:

(Return of the Investment – Risk-Free Rate) / Standard Deviation of Returns

The risk-free rate is typically represented by the return on a government bond and is used as a benchmark for measuring an investment’s excess return. The standard deviation of returns measures the volatility of an investment’s returns.

An investment with a higher Sharpe Ratio is considered to be more attractive than an investment with a lower Sharpe Ratio as it indicates a higher return per unit of risk taken.

Example:

Consider two investments, Investment A and Investment B, with the following returns:

Investment A: 10% return with a standard deviation of 5% Investment B: 12% return with a standard deviation of 8%

Assuming a risk-free rate of 2%, we can calculate the Sharpe Ratio for each investment as follows:

Investment A: (10% – 2%) / 5% = 1.2 Investment B: (12% – 2%) / 8% = 0.7

In this case, Investment A has a higher Sharpe Ratio of 1.2 compared to Investment B’s 0.7, indicating that Investment A provides a higher return per unit of risk taken.

In conclusion, the Sharpe Ratio is a useful tool for evaluating investment performance and comparing investment options. By measuring the excess return per unit of risk taken, investors can make informed decisions about the potential return and risk of their investments.

How big impact has smooth execution of algos on your trading results?

Having all systems online is crucial for every AlgoTrader. Enjoy your life with confidence that your trading robots are working without any obstacle and your VPS is running smoothly. 

In this article we will talk about how big impact has the smooth execution on your trading account. Everything we will explain on examples and live simulations.

First of all, let me explain, which situations could happen?

  • Unexpected shutdown of the platform
  • Unexpected loss of connection to the broker
  • Low margin
  • Disabled Automated trading

Let’s simulate how these situations can impact your trading performance and your balance on your trading account. We will use Quant Analyzer software What-if scenario and Monte Carlo function for this.

What can happen if our platform has experienced unexpected shutdown?

Some trades can be running on the account without managing therefore our algos cannot manage trailing stop, profit target or exit of the trade at certain time (Dangerous holding during weekends.).

Here is result of original strategy

Result of original strategy

If we miss only 1 % of profit trades we can see performance impact

If we miss only 1 % of profit trades we can see performance impact

If we take only every 5 trade we can see performance impact

If we take only every 5 trade we can see performance impact

Comparison of all graphs above: Green: original Purple: every 5 trade Yellow: 1 % missed trades

Comparison of all graphs above: Green: original Purple: every 5 trade Yellow: 1 % missed trades

We can see that impact of smooth execution of trades is very important. Return Drawdown ratio has dramaticly dropped from 9 to 3.

Monte Carlo Analysis – 10 simulations of Random Skip trades with 5 % of probability.

During these unexpected moments it is crucial to be informed about these events ASAP. Therefore, we are offering professional solution which can immediately notify you via email or SMS when something unexpected happen. You will have time to solve the issue and prevent loses. This is what our monitoring platform can do. Try our monitoring platform and have all your algos monitored.

Check for FREE how can QuantMonitoring help you

Receive 30 days free trial period + access to interesting know-how

How to install Metatrader 4 under Linux

n today’s tutorial, I would like to show how to install Metatrader 4 or Metatrader 5 for Debian Linux distribution. The license fees for Windows Server are more than high and this can be the way how to save money for the VPS or physical server operating system.

Considering that some unexpected installation issues may occur during the installation or when running the Metatrader 4/5 process alone, this article is more considered for advanced users.

So let´s start. What are we going to need?

Now let’s start with the Wine installation:

 1. In order to avoid writing sudo with every command, switch to root user with the command and insert password.

su –

password:

2. First we allow the installation of the 32-bit packages

dpkg –add-architecture i386

3. Add a key for wine repository:

wget -nc https://dl.winehq.org/wine-builds/Release.key
apt-key add Release.key

4. Add this repository line to the file /etc/apt/source.list file

deb https://dl.winehq.org/wine-builds/debian/ jessie main

5. Install package support from https using the command:

apt-get install apt-transport-https

6. Then update the list of packages from the repository using the run command:

apt-get update

7. Then install Wine using the command:

apt-get install –install-recommends winehq-stable

8. After Wine is installed, it is necessary to configure the wine and run it with the command:

winecfg

after running this command, the pop up window will appear with the message that there are missing additional packages, that has to be installed, so click to download and install them.

9. When you start a winecfg, you need to set the emulation for Windows 7 (check the screen bellow):

We can now install Metatrader 4

1. Run the Metatrader 4 installation package and change the installation folder

2. Run Metatrader 4 and enter your login details

If we want to install MT5, we will use the same procedure. Metatrader 4 runs on Linux directly in portable mode, but the MT4 data are in a different location than in Windows.

!!! ATTENTION !!! Metatrader 4 data with strategies and indicators can be found in the following folder:

/home/USER_NAME/.wine/drive_c/MT4/MT41/MQL4/

Note at the end

I wanted to know how the MT4 on Linux is demanding CPU vise, so I made an experiment. I ran the same amount of MT4 instances on Linux and Windows. My measurements were clear, the Windows emulation is worth some HW costs. On Linux, the CPU usage was roughly twice as on Windows.