# The Maths of Trading

https://youtu.be/FlmP183i16I

1.Price Randomness

2.Price Factors

3.Technical Analysis

3.1.Chart Patterns

3.2.Stock Charts

4.Mathematical Expectation

5.The importance of data in trading

6.Risk Management

6.1.Risk of Ruin (RoR)

6.2.Optimal Risk

6.3.Position Sizing

6.4.Variable Risk

7.Parameters of a system

8.TRADING COURSE

What do you know about trading?

Can you beat the markets in time? or is something impossible?

Do you think math can help you design a winning system, or is bankruptcy inevitable?

## 1.Price Randomness

They say that 90 percent of traders lose 90 percent of their money in the first 90 days, which is not very encouraging, but if there are many people who lose, there must be others who win, although… does that mean that Is it possible to predict the price?

There are theories that affirm that the price is completely random (**Random w*** alk*) and the certainty that it does not follow any known distribution, but even the hypothesis that it is impossible to anticipate it (

*), since the markets are efficient and reflect all the advantageous information that exists. This pretty good sounding theory was accepted and taught for many years.*

**Efficient Market**but… since when do markets only act efficiently?, aren’t our emotions part of the game?

If we look at what happens in a **financial bubble**, we can see that a strong sense of euphoria is created, driving the price up irrationally and ultimately leaving stocks overvalued. Something that cannot be explained in the efficient market model, because the price is always perfectly valued.

If we therefore accept the emotional factor, we have the * adaptative market* that brings together the best of both, and better understand the price behavior.

although… how many factors really influence the price?

## 2.Price Factors

Here is a **list** where you can see the majority.

Some are very **psychological** such as the news, publications on networks, and even the predictions themselves, and it is that although it seems a bit strange, the price itself influences the price, curious right?

But one of the most influential factors is **manipulation**. The large whales movements or many investors groups can cause strong rises and falls in a short time. By eliminating many sellers or buyers from the auction at once, the price acquires a very different value, which drags more investors to follow the movement, further delaying its effects.

And there are more influential factors than others.

But… how can math help you in trading?

## 3.Technical Analysis

To analyze a market you can focus on its peculiarities through **fundamental analysis**. If, for example, you wanted to invest in Apple in the long term, you would study its sales data, economic reports, and information about the company to make a prediction of the true value of its shares.

On the other hand, a trader focuses mainly on a technical analysis of the price, since according to * daw’s theory*, the historical already shows all the factors that influence it.

And here again mathematics helps us… but what are those factors?

### 3.1 Chart Patterns

Technically analyzing a market involves analyzing price trends and their corrections to take advantage of them.

And for that, **trend lines**, **supports** and **resistances**, **Fibonacci levels** or **Elliot waves** are drawn, which are nothing more than graphic elements that mark patterns with the price and have a certain **statistical success**.

For example, any trader knows that when a very strong resistance level such as an **all-time high** is broken, the price is likely to pick up more momentum. This is just an example, but these tools allow you to easily design a system with a high percentage of hits.

### 3.2.Stock Indicators

The problem is that there is no rigorous consensus to use them, because each analyst traces these elements in his own way. So if you want more unified buy and sell signals, there are **stock indicators**. These are nothing more than graphs that are drawn with mathematical calculations, and that give us all the **same signals**.

An example is the **moving average**, which is simply a line where each point is calculated with the average value of the periods that we want. If, for example, we choose a moving average of 9 periods, each point is obtained with the average of the 9 previous prices. In other words, a line of averages is drawn, and it is done this way to soften the noise caused by short-term factors such as some news or manipulations. The moving average summarizes general information better and is **useful on a visual level**.

There are different **moving averages types** and they differ mainly in the priority they give to the values of those averages. Most of the indicators use **exponential averages**, because they give more importance to the last price values.

But going back to the topic, do you want to see some indicator?

The simplest that exists is a **crossing of moving averages**, where two moving averages of different periods are superimposed, a faster and more sensitive line of fewer periods, compared to a slower and unalterable one of more periods, and the relationship is studied. Can you imagine how?

The **cut points** represent moments where the short term diverges from the long term and therefore a possible purchase or sale.

Notice that when they cross there is usually a change in price. Although note that there is also a **delay**.

Another of the most common technical indicators is the **MACD**, which looks for another line crossing, in this case a faster one obtained with the subtraction of two moving averages, one of 12 and one of 26, with a slower one obtained by smoothing this signal with a average of 9 periods.

But there is also the **RSI** or relative strength index, which tells us if the asset is considered overbought or oversold, when it reaches levels above 70 or below 30. However, there are also indicators created by mathematicians, such as **BOLLINGER BANDS** that represent with its amplitude the market volatility.

And others like **VOLUME**, widely used by some traders.

All of them also serve to design systems with a good **probability of success**, and since many analysts use them, in the end they also end up influencing the price. A bit paradoxical right?

And it is that the indicators can have some effectiveness, but that does not mean that they are always right. Notice that in the MACD, when there is a big change in the trend, there is a crossover in the indicator, however, the price impulse does not always have the same strength when the crossover occurs. You have to be very clear that the indicators are calculated from the price and not the other way around, and that if the price changes, so does the indicator, because it is drawn with **data from the past**. That is why you must be careful since the momentum of the price can take any indicator ahead. You’re warned!

It is important that before using them you know very well all their strengths and weaknesses (so if you would like to learn them, take a look at the course that I have prepared below).

## 4.Mathematical Expectation

Note that although we do not have a crystal ball to guess the price, we have introduced a concept that can win you over. **statistical success**.

And it’s not necessary to know what the price is going to do at all times to have a profitable system.

But how do we know if it is profitable?, do you think it can be known?

Actually it is very simple, a system is **profitable** when the benefit of all the positive operations exceeds the loss of all the negative operations, that is to say that the balance between winning and losing operations is positive.

As simple as that, what did you expect?

But if you summarize that **average balance for a single trade**, you get the **mathematical expectation** of the system. Which is how much money you earn on average for each operation.

And it is calculated with the **hit percentage** (winning trades) and the **win/loss ratio** from all of them.

But let’s go with an example!

Imagine your system was like **flipping a coin** with **2 rules**. If it comes up heads they pay you another coin, but if it comes up tails you lose the coin, that is to say that your risk benefit ratio is 1 to 1 (1 coin you can win for every coin you can lose). Since the probability of getting heads is 50 percent, the ** law of large numbers** assures you that after many spins you would have a hit percentage close to that value (that is, after many spins you would have something very similar to 50 percent of heads, and 50 percent crosses), and since the prize when you win is the same amount as you lose when you lose, you would have a system that neither wins nor loses. That is, mathematical expectation 0.

Now look at this other one that does **5 operations**. 3 of them are positive (which is a success rate of 60 percent), and a risk benefit ratio of 2 to 1.

If we use the formula, he has an average profit per trade of 1.6, which means that so far his hope is clearly a winner.

However, if I show you this other one, you may think that it is not, because it has a **hit percentage of less than 50%**, right? This is just a perception, because in this case the ratio compensates for the other variable.

Although the opposite can also happen. Systems with a high percentage of hits may not be profitable if the risk-benefit ratio does not ultimately compensate. And I tell you this because some people take advantage of this perception to sell you **trading bots** which have a high percentage of hits, but when they lose they do so with such large amounts that they stop making it profitable. Unfortunately all the benefit until the catastrophe is just a **statistical illusion**, so be careful.

Always remember that **a system is winning only when its mathematical expectation** is, and not any of the two variables separately.

## 5.The importance of data in trading

But if you are a good observer, you would tell me that 5 operations are not enough to guarantee a certain **confidence level**, because for that you need a much larger **sample of operations**. And the truth is that you would not be wrong, since to obtain decisive conclusions it is necessary to test any system first in the **simulator** with enough data.

So don’t even think about trading in real without knowing your expectation well!

Although do not go overboard with the **history size**. Keep in mind that markets are adaptive and change over time, which means that neither the success rate nor the risk-benefit ratio will always tend to the same value, and if you include data that is too old, you may obtain **outdated conclusions**. Remember that the statistics show us how the system has behaved up to the **present moment**, but not how it will do in the future. That is why it is more interesting to see how they evolve, than to draw conclusions with useless data.

## 6.Risk Management

Now you have a way of knowing when a system is profitable, but is that enough to win?

The answer is no, and the **math** is going to prove it to you.

### 6.1.The Risk of Ruin (RoR)

Even if your system is very good, if you risk more than necessary for each trade, you are likely to lose.

Even if you have a 60 percent success rate if you risk a lot of capital in each operation, it is enough that you have a **negative streak of operations** to liquidate your account, because 60 percent is not that decisive either, and even if you had 99 percent it could happen to you.

The key is to know that probability of ruining yourself, which is precisely the **probability or risk of ruin(RoR)**. which depends on the parameters that you already know of a system but also on the risk that you want to assume. The more you risk your system, the greater the chance that a series of negative trades will ruin you (in fact this relationship is exponential).

So it is not enough to just have a positive mathematical expectation!

But for you to fully convince yourself I have created a **trading system simulator** where you can try all these concepts. And I am going to introduce a system that is profitable under the numbers, with a fairly high **risk per operation** of 40%. You can see that what seemed like a winner turns out not to be. Surprise!

And it is that many systems with positive mathematical expectation can ruin you just the same if you do not have correct **risk control**. Because even if they are long-term winners, hope does not take into account that **your capital is limited**, and that if you go bankrupt you will not be able to prove that it is profitable, because you will not have a balance left to recover.

Keep in mind that the success of trading is based on operating many times, so if you want to have a future as a trader you will have to control this parameter.

That is why we are going to try to reduce the risk in the simulator, so that you can see how this time the system can make you **invincible** in the long term.

DOWNLOAD TRADING SYSTEM SIMULATOR

You just discovered the holy grail of trading, how about you give me a like or share it?

### 6.2.The Optimal Risk

Now you only need to know what numbers are appropriate…so the question you should ask yourself is exactly how much risk do you have to take?

Years ago, the mathematician **Ralph Vince** discovered that there is an optimal risk (optimal f) to obtain the greatest possible benefit, but unfortunately, as you will see, you have to assume a percentage that is too high.

The idea to avoid having **draw downs** or falls that are too large is to assume a **small percentage of risk**. But which one exactly?

For this I want you to see a graph, where you can see how many negative trades in a row you need to ruin yourself with some common risks. Note that a low risk allows you a much larger **margin to fail**.

And although any of these risks could work for you, **there is no one optimal risk for everyone**, because each system is different and each person is different. Everyone tolerates risk in their own way and is not willing to risk the same amount for the same benefit. True?

More risk means growing faster, but also more chances of ending badly. So depending on your system and your **tolerance**, you can assume higher or lower values, but what you can never do in any way if you care about your capital, is assume a percentage that endangers your account.

Now you know what mathematics is for. But… how do you calculate the investment size if you have to take into account that there is also a stop loss?

### 6.3.Position Sizing

To calculate the your position size for a certain **risk** and **stop loss**, it is done with the following formula:

where we introduce both parameters together with the equity, and it calculates the exact amount to invest.

Although in practice this is adjusted **manually** by setting the stop loss, and adjusting the entry to obtain the** percentage of risk** that we want, although it is important that you know how it is calculated.

Now you have learned how to calculate the risk for each operation, but what happens if you do not want to assume a fixed percentage? In that case, do not worry, because there are also **variable risk systems**.

**6.4.Variable Risk**

Imagine that you start with an account of **$10,000** and a **risk of 1%** (that is $100 per trade). And that after a while operating you manage to increase your account to 15,000. If you keep the same percentage, in the next operation you will risk 150, because it is now calculated on 1 percent of 15,000. With a **fixed percentage** you also risk more when your account is bigger, and that means your **chances of ruin** remain the same, because 1% is always going to be **proportiona**l to the size of your account. I’m saying that if you want your system to become less vulnerable as you grow, then you should use a **variable risk** system.

Going back to the example, what do you think would happen if in each operation you always assumed $100 instead of 1 percent? The answer is logical, that you would risk less percentage as you grow, and that’s great. But neither would you grow faster, because with the **same risk** you would always opt for the **same benefit**. So you should only do it if your benefit seems enough to you.

Assuming the same amount is not perfect either, but… do you think you could **reduce the risk** and the **increase the benefit** at the same time? Answer as you would in the comments!

In case you’re interested, there are multiple fixed and variable risk systems such as ** fixed risk** or

*with their advantages and disadvantages, but unfortunately I don’t have that much time in this video to explain them to you.*

**fixed ratio**## 7.Parameters of a system

The important thing is that now you can control the most essential **variables**, although these are not all. The mathematical expectation, or the risk of ruin, are just some of the many **parameters** that exist to analyze a trading system.

Within a **backtest**, many others can be measured, such as the **Sharpe Ratio** to measure profitability based on risk, or the **Z-Score** to determine the randomness between operations. Although there are many more and it is important to know them in detail if you want to correctly measure your system.

And in the end, deciding whether an **expert advisor** or any system is appropriate or not, comes down to assessing a series of numbers that indicate whether it is **suitable for your operation** or your tolerance. And as always mathematics is in everything.

## 8.TRADING COURSE

If you have been wanting to **expand** or **deepen** with the patterns and technical indicators, to **discover** the different risk systems that exist, or to **know** these parameters well, I am developing a **trading course**, where I explain all these concepts **in detail** and **with examples**. . So if you are interested in learning **trading from scratch** with a mathematician, don’t miss this opportunity. I’ll leave you a link when it’s available.

If you are interested, **left a comment**.

¡see you in the course!