quantitative trading lab - percorso opzioni quantoptions · 2020. 5. 13. · 1 quantitative trading...

212
1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: [email protected] Skype: prof_ddo web: www.quantoptions.it

Upload: others

Post on 10-Oct-2020

6 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

1

QUANTITATIVE TRADING LABORATORY

DOTT. DOMENICO DALL’OLIO

MAIL: [email protected]

Skype: prof_ddo

web: www.quantoptions.it

Page 2: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

2

PART 1

INVESTMENTS:

how to take effective investing decisions in the

algo trading era

Page 3: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

3

3

What is an investment?

An investment is the commitment of money and/or other resources today under the

expectation to get some kind of benefit tomorrow.

It is not all just about the money: sometimes we invest our time in activities given ofsome expected future value, possibly higher than the actual one.

You are here today because you are investing your time and your money in exchange

for skills and competences you expect will give you the chance to fully achieve yourprofessional and personal goals.

The main risk here is that the real value of an investment could be much different from

the expected value!

A common feature in any investment: we sacrifice something today under the hope toget something of a higher value tomorrow. Only in the end we will know if we did right

or not.

It’s a sacrifice because in allocating money to an investment we give up the chance touse that money for something else, and we cannot know which choice would be the

best, until it will be too late.

It’s the so called opportunity cost of capital.

Page 4: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

4

4

What is an investment?

The problem is due to the fact our capital is limited: given some amount of money, time

or other resources we always have to choose within a range of investment alternatives,all theoretically replaceable one another.

In the end we will have to pick only one or some, and this puts us in front of an implied

cost, given by the risk that after a while we could find out that our choices were notoptimal.

An issue here is how much choices are replaceable one another: to be able to state

that choices A and B are replaceable implies that we are able to compare themperfectly, so to be able to state which one is better (or that they are completely

repleaceble each other). But since we cannot exactly foretell which of the two willactually be better in the end, we can only take decisions in uncertainty conditions and

incomplete information.

What we need in the first place is to find a unique yardstick, some way to comparedifferent investment choices and to be able to sort them on some scale, that is to

decide which one(s) provide better expected results.

Page 5: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

5

A paramount concept

In a few words, in the field of investments it is all just about risk and return

In making an investment usually people ask themselves how much they could gain; very

rearly the expectation about profits is based on scientific criteria: more often it is the

result of a hope originated by the will to satisfy a contingent need of some sort.

Only a few investors take time to think better about this central issue and ask themselves

the only right question: how much could I reasonably earn given the risk I am assuming?

The strict relationship between risk and return is the starting key-point: it is not only amatter of where I am in the beginning and where I am in the end, but also of how I get

from the beginning to the end.

The path of an investment in time, indeed, is as much important as its final result.

Page 6: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

6

It is all just about risk and return

The basic rule, then, is that return always comes with risk: where there is no risk there

cannot be any return.

Experience in the field teaches that under “normal” market conditions (that is, whenthere are no external factors coming into play) risk and return are substantially

proportional: if we want to gain more, we have to suffer a higher level of risk. And if riskincreases we want the chance to gain more, otherwise we will not take that risk.

Here a paramount problem comes into play, though: it is all a matter of perceived risk

and expected return: real levels of risk and return are hardly predictable in the momentwe take the investment. Indeed, investors can only make hypothesis, in the first place.

Real results will be revealed only at the end of the period.

Here psychological issues also come into play: given the impossibility to take decisionson the basis of sure facts, tolerable risk levels are different among different investors.

Generally speaking, different investors acting on the markets tend to have different risktolerance levels, and different expectations in terms of returns, even when they are put

in front of the same investment opportunities.

Risk, by the way, is subjective: ask ten different investors to quantify risk of an investmentand you will likely get ten different evaluations!

Page 7: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

7

Misleading advertising

Today surfers on the internet are pounded over and over by banners and advertising

spaces pointing out at easy profits on the financial markets, usually on the Forex marketor on binary options or on CFDs. The story is more or less always the same: it takes just a

few euros to open the account, 15 minutes to read a pdf and understand everything,20 minutes a day to earn 5k euros per week.

It is misleading advertising under several points of view:

• with just a few euros on the account you will survive (financially speaking) only a fewminutes: the leverage that allows you to trade with just a few euros can make you gain

a lot but also lose a lot;• return is not possible without risk, and to gain a lor of money you need a lot of money

(apart from very rare exceptions);• the trading job is as sophisticated as brain surgery; if it takes 10 years to become a

good brain surgeon, how could it possibly take only a few minutes to become asuccessful trader?

The point is not to be able to gain a thousand euros in one day, but to be able to do it

every day, to end up after a year with a positive balance on the account, having

suffered a bearable risk in between.

Once again, the path of the equity line is as important as its final value.

Page 8: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

8

A small step ahead

One of the most dangerous mistakes many people do is to think they can make a

lot of money without taking any risk and with a very little capital. The truth is that

the trader who makes a 25% return systematically every year is an excellent

trader. Moreover if his returns have two characteristics:

1. low volatility among different years (stable profits year after year);

2. low volatility within each year: to have a +25% at the end of the year after being

-50% at some time during that year is not positive.

In order to understand the importance of volatility among different years, let’s

consider two investments: one makes a 20% return for three consecutive years, the

other makes +50% the first year, -30% the second, +40% the third. They have the

same final result (not considering compounding), but for sure they are not equal!

Stable earnings, almost predictable, in the first case; totally unpredictable in the

second.

For the third time: the path of an investment is as much important as its final value.

Page 9: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

9

A small step ahead

Speaking of the volatiity within each year, the problem is to be able to define a

sustainable threshold: some people cannot stand the risk of losing some part of

their capital; some other don’t mind.

The fact is exactly this: the risk tolerance level is not the same for all investors.

And moreover, given the same perceived risk, different investors could likely have

different expectations about a return sufficient to justify taking that risk.

There’s a clear subjectivity issue in the evaluation of risk and return.

Market models suggest that two investments having the same perceived risk level

should have the same expected return, otherwise not a single investor would ever

take the one with a lower expected return.

The fact is that this statement is based on some very strong assumptions, as we’ll

see very soon.

Page 10: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

10And vice-versa: two investments given of the same expected return should expose

the investors to the same level of risk.

Being all of this true, investors could put all investments on a scale of risk and return

and be always able to pick the one that best fits their risk tolerance level and

expectations about returns.

In the real world this often doesn’t happen, given the asymmetries in the

availability of information, that make hard for many investors to evaluate all the

possible scenarios and to compare all the alternative investments.

There are some open problems then:

1. how can we define and measure risk?

2. how can we make expectations about return?

3. can we build models to solve this kind of issues?

4. do these models work?

A small step ahead

Page 11: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

11Looking back to the two investments in slide 8, the main problem is volatility of results

(usually measured with the standard deviation of past returns) in the two cases: in the

first there is no volatility, since the value of returns is always the same. This makes future

returns quite predictable.

Should it have been +22% the first year, +18% the second, +20% the third, things would

have only be slightly different: in fact, you could say that for the fourth year you could

expect a +20%, being prepared to face something more or less between +18% and

+22%.

In the other case it is very hard to say that you could expect a 20% for the fourth year: it

is exactly the mean of the yearly past returns, but to expect that is totally another

matter. This because volatility of returns is very high this time, and this means we have to

deal with a strong unpredictability.

And here comes a paramount statement: volatility is a synonim of unpredictability.

A small step ahead

Page 12: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

12

Why volatility is so important

We can then state a fundamental rule:

the mean of past returns can be taken as an expectation of future returns only when the

volatility (of past returns) is not too high.

Indeed, volatility is a measure of the reliability of an expected return.

Statistics applied to finance can then tell us something about the reasonable expected

return of an investment, and the probability of that return: in simple words,

volatility is a measure of risk to make a mistake in our forecasts about returns.

This probability can be determined under a model (that’s what modern financial

engineering does), or after the observation of historical data series.

Page 13: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

13

The Normal model

Should it be possible to state that returns of any financial asset follow a Normal

model, it would be very easy to measure the exact probability of any interval ofvalues, given the mean and the standard deviation of historical returns.

This way we could form a good expectation about the return of an investment

and the risk to miss that expectation, but this wouldn’t solve a major issue: indeedit would provide a measure for the (expected) risk of mistake, but not a way to

reduce it.

Volatility is crucial in the definition of the

risk of any investment, since dependingon its value the risk to make a mistakecan be significant.

But the key-issue here is that thevolatility we know in the moment wetake the investment is the past one,while the one we will have to deal with

is the future one, expected butunknown.

Page 14: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

14The higher the volatility, the higher the dispersion of returns: the shape of the

distribution gets squashed in the middle and the tails rise. In these situations it is

said that the distribution has fat tails.

When volatility increases, forecasts become very hard and unreliable, since the

field of variation of possible results gets much wider than usual, and events usually

given of very low odds to show up become much more probable.

Extreme events, the so called black swans, become more probable.

As we’ll see, by the way, the Normal model is just an approximation of reality: the

real world is much riskier than the model!

How do models deal with risk and return?

Why is the Normal important in finance?

Page 15: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

15

Portfolio theory by Harry Markovitz

The portfolio theory by Harry Markovitz states that the risk of investments can be

reduced investing in portfolios of lowly correlated assets: since stocks and other assets

tend to move in different ways most of the time we can assume that in any observed

timeframe some assets would move up, some other down, some other would stay

stable. In one word, diversification.

Return would then be the weighted average of the returns of all the assets included in

the portfolio, while global risk would be reduced thanks to the low correlation between

pairs, that would smooth the risk of each single component taken on its own.

Some issues here:

- historical returns are not a good forecast of future ones;

- historical volatility is not a good measure of future one;

- correlations between pairs are not stable in time;

- the effect of diversification is also a function of weights of the single components,

which can be optimized only on past data; and once again, future optimal weights

could be different from past ones.

Page 16: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

16

CAPM

The capital asset pricing model, by the way, states that the return of an asset or a

portfolio can be seen as a linear combination of risk free interest rates, market risk

premium and risk of the asset (or the portfolio). Basicly, the idea is that riskier assets

should always provide higher returns.

Some issues here too:

- the linear relationship between risk and return is a function of active and passive

interest rates, assumed to be equal;

- risk of an asset or a portfolio is an expectation based on past data;

- market risk premium is based on the expected return of the market portfolio, which is a

weighted average of returns expected on each component;

- risk of any asset is measured by its Beta, which is a ratio between a correlation and a

variance, both expected;

- the model implies that investors always have a full information and can therefore take

the best decisions in terms of risk and return

In three words: too many forecasts!

Page 17: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

17

A different point of view

What follows is an approach to investments completely different from the one that

comes out from models like the CAPM.

The idea to start from is that not all the investors on a market have access to the sameinformation, furthermore they do not all have the same skills, and moreover they are not

always rational. It is then possible to find investing strategies able to provide some kindof edge in respect with other inverstors. This is the so called active management.

The starting point is not the selection of stocks on the basis of past data of risk, return

and correlation, but the selection of assets to buy and sell on the basis of strategies thathave proven to be effective on past market data.

It’s a scientific approach because everything in the strategy comes out from a deep

study on historical data and the thorough research of the best parameters andindicators able to improve the effectiveness of the trading signals. It is all a matter of

odds, of course: we buy when the odds to gain are higher than average, we sell whenthe odds of a pice drop are higher than average.

The expectation is that with a proper strategy it could be possible to improve the timingof trades, so to achieve a global return higher then that of the simple buy & hold.

Page 18: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

18

The phases of an investment

For people not used to trading, to invest money on their own in the 21st century might

seem a very simple operation: you turn on your pc, log-in to your account, choose astock (or another kind of instrument) and buy it.

Actually this apparently simple process is the result of a long series of steps.

How do we get an access to the market? Do we need special authorizations?

How do we decide what to buy and sell? How can we actually buy and sell?

Once that we have bought a stock what should we do? When will we sell it? Why?

These are only some of the many questions that rational investors should ask themselves.

The investing process, indeed, is much more complicated than it might seem.

Page 19: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

19There are eight steps to take in any investment:

1. get an access to the markets

2. define the timeline of the investment3. choose what to buy and why

4. decide the capital allocation for that trade (money management)5. decide what to do if things go wrong (risk management)

6. decide what to do if things go well (profit management)7. choose the proper instrument to trade

8. send the order to the market and monitor its execution

Trading is not that simple after all…! In reverse, it demands for a highly scientificapproach

The goal is to take investments fully planned under any point of view before taking

them.

Everything is religiously planned in order to always know in advance how to deal withany possible outcome.

The phases of an investment

Page 20: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

20Steps from 3 to 6 represent the four pillars of an investment and they all concur in

the same way to success or failure in this field.

The order of apperance is not important, then: they could be inverted or mixed,

and the final result would not change anyway.

Nevertheless, moreover for unexperienced investors, step number five is the most

important: risk management.

Only a few investors learn how to deal with it before it’s too late. Overconfidence

is very common in this field and always leads to financial death.

The first lecture is that risk is the only thing that matters, since it’s the only one we

can control.

One preliminary note

Page 21: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

21

Step 1: get an access to the markets

To trade on the stock exchange there is no need of specific qualifications, or

means reserved to some category of investors; but in any case it is necessary tomake a series of choices and take a series of specific steps.

The first step is obviously to open an account.

At the same time we need to be authorized to operate on the market, filling insome specific forms.

Some markets – such as the derivatives one – require the filling in of someadditional forms.

In the several forms to be filled in at the subscription of a trading account thereare also questionnaires about the knowledge of the clients about financialmarkets and products, their expectations about returns, inclination to risk, and soon.

Page 22: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

22The access to the markets via phone and pc dates back only a few years.

Before 1996, in fact, the access to negotiation was reserved to specializedintermediaries: to invest in the markets, private investors had to go to a bank, inperson.

It was possible to make orders via phone, but within the same day the client wasrequired to go to the bank and sign in the proper forms.

Not all the banks allowed clients to transmit orders via phone, though, given therisk that the client could change his mind before signing in the forms (it oftenhappened when between the order via phone and the end of the day the price

dropped…).

Some more progressive bank started recording phone calls on tape, and the lawadapted in order to regulate the means of acquisiton and preservation of those

phone calls.

In 1996 everything changed.

Step 1: get an access to the markets

Page 23: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

23

Step 1: the trading on line revolution

The easy access via pc changed the rules of the game, giving input to the fast

growth of products and services.

Here the main changes:

• direct access to a lot of markets worldwide for anyone

• huge expansion in the supply of services (professional advice, market datavending, trading platforms, instruments for data analysis, and the like)

• strong reduction in costs of negotiation

• enormous growth in products (number) and markets (volumes, values)

• quick development of new investing techniques

• birth of high frequency trading, quant trading, systematic trading

Page 24: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

24Here the choice is between two different paths, that sometimes can be

complementary, sometimes completely opposite: shall we invest on the long termor the short term?

It’s a paramount distinction, because the most part of the whole investing process

is strictily related to the choice we take in that field, the field of time.

Indeed, depending on the path chosen we have then to act coherently to it,applying befitting techniques. Let’s see why.

Basicly the choice is between being investors or speculators.

The firsts look forward: they make investments aiming to a growth in capital inmonths and years, thanks to a growth in prices in time, defending the capital frominflation.

Tipically they invest in bonds, mutual funds, ETFs, stocks of companies they thinkthey can rely on, because they are known to provide good yearly returns in termsof dividends and some sort of stability in prices over time, even in bad generalmarket conditions.

How do they choose these companies? We will see it forward.

Step 2: choosing the approach to the market

Page 25: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

25Speculators, on the other hand, are people who invest on a short or very short

term: a few days (position traders), a few hours (intraday traders), or minutes, oreven seconds (scalpers).

Now, one of the unchanging laws on the markets is that profits take time.

Indeed it happens quite rarely to see huge price movements in short or very shortterms; this reduces critically the odds to make significant profits in each trade in ashort while.

To gain we have to let the market move in the favourable direction and enoughto produce a gain, and this might take some time.

Let’s see some numbers to prove that idea. Between January the 1st 2000 andDecember the 31st 2013 the stock ENI (listed on the italian stock market) made a0.03% average daily price variation (close vs previous close), and 70% of the time

the price moved within a daily range between -1.41% and +1.47%.

This means that, investing money on ENI, seven times out of ten we cannot expectto gain more than a 1.47% per day, and we need to be prepared to the risk to lose

up to a 1.41%.

Step 2: choosing the approach to the market

Page 26: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

26Conclusion: it is not easy to make huge profits in a short while, because the market

doesn’t help.

Investing 10,000 euros on ENI shares today, if things go well we could have 147 euros(gross, because we still have to cut commissions and taxes) more tomorrow, but we

could also have 141 less (plus commission and taxes).

The most likely event is to have 3 more euros, the 0.03% average daily profit (still gross).

What if we look one more day forward? The daily average price movement grows to0.06%, and 70% of the time prices move within a range between 2.09% and -2.00%: we

can expect a 2.09% profit, but we have to be prepared to a 2.00% loss.

A second unchangeable market rule:

The longer you stay on the market, the higher are potential profits, but losses as well

It takes time to make money, but the longer you wait to make money the more you

expose yourself to the risk of losses. Like it happens in many things in life, it is all just amatter of equilibrium: we need to find the best compromise between expected profit,

time sufficient to reach it, and risk connected to it.

Step 2: choosing the approach to the market

Page 27: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

27As additional proof, in passing from a two days to a five days horizon the average

achievable profit grows to 0.14%; 70% of time we can gain up to 3.24%, risking to lose upto 3.09%.

Nothing changes, then: the longer we stay in a trade, the higher are both the potential

profit and the potential loss.

Moreover, under a historical point of view the maximum 5-day return on the stock ENIhas been around 27%, while the maximum risk has been around 25%.

Now the most important question: on a 5-day time range can you tolerate the risk to

lose 25% of your money? It’s a very low probability event, sure (it happened only oncein fourteen years!), but what if it happens to you?

On a 5-day time range the probability to lose a 10% or more of your capital on the stock

ENI is 0.9%, while the probability to lose a 5% or more is 6.5%. Investing 10,000 euro onENI, not managing the risk in any way, in the next 5 days there’s a 6.5% probability to

lose 500 euro or more.

Step 2: choosing the approach to the market

Page 28: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

28All of this is just to prove that investments have to be managed, because things can go

well, but they can also go bad, very bad. A long term (talking about years) investmentnot managed can lead to devastating effects.

European and American stock markets are full of very good examples of these issues.

A third rule then: we need to know how to manage situations

And this can be learnt only with knowledge and experience on the field.

Atop of this we need a good stock-picking methodology: if, on one hand, the longer

we stay in a trade the higher the risk, it is also true the if we do not stay enough in atrade it will be very hard to reach a profit. It is again a matter of equilibrium.

How to get out of this situation? We need two things; first, define a strategy that makes

us get into trades given of a high probability to be profitable. What we need is

a way to identify in advance most of those situations where the odds for a tail event arehigher than average: events able to bring high profits in short time periods.

Notice that we are talking of probabilities: our trading strategy has to make us win most

of the times, not always

Step 2: choosing the approach to the market

Page 29: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

29Because the perfect strategy doesn’t exist: there is no strategy that makes you always

win; there is no market that doesn’t do the opposite of what everyone expects,sometimes; there is always some unpredictable event, on any market; there is no

internet connection that doesn’t go down the moment you need it, perhaps in themoment you are going to take the best trade of the year; there is always a firm that will

announce very bad news right after you clicked the button to buy it.

To win we do not need the perfect strategy, but just a good entry strategy, an effectiverisk management policy and a good profit management

Know what to buy and when, what to do if things go bad, and what to do if things gowell.

The second element we need for success is the leverage.

The point is that there are only two ways to gain on the financial markets: either weinvest a small money amount and catch a very profitable movement (and now we

know it requires time and it exposes us to increasing risks), or we invest a huge moneyamount and catch a small price movement (in a much shorter time, but still with high

risks and very stressfully). There are pros and cons in both choices. About the second,only a few investors can afford to invest huge money amounts on the markets, and

there comes the leverage. We will see it forward.

Step 2: choosing the approach to the market

Page 30: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

30As previously stated, depending on the timeline of the investment we have to choose

proper strategies.

If the idea is to invest on the long term on stocks that will pay good dividends and growin price over time we have to be able to select them among the whole list.

This result can be achieved with fundamental analysis.

To do fundamental analysis means to analyse the trend of the economy in general,

then the sector of our interest, and finally the balance sheet of the company of ourinterest, in order to estimate the so called fair value (that is the right price) of the firm,

which has to be compared to the price on the market, so to be able to state whetherthe company is under-valued, fairly valued, or over-valued.

What does all of this mean? Basically, it’s a matter of price Vs value.

Prices of listed stocks move up and down continuously because of the constant action

of supply and demand; these two forces are influenced by the information available onthe market at some specific moment, and the expectations of operators about the

future trend of prices.

It is all a matter of today’s expectations about future prices.

Step 3: defining the stock-picking strategy

Page 31: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

31Making it simple, who buys a stock today does so because he expects that the price is

going to increase in time; vice-versa, who sells a stock does so likely because heexpects the price is going to decrease in time. And only one of them will be right!

But who of the two will be right will be known only at the end of the period, since

everything happens in the field of probability.

Information, hypothesis, expectations, probability are then the drivers for pricemovements: who buys ENI shares today does so because he has information that lead

to hypothesis and then to expectations of growth in its price within some time range;moreover he buys ENI shares because the probability of a growth in price is higher than

the probability of a drop (at least this is what he thinks).

How can investors form these expectations about growth? Some of them likely usefundamental analysis, that in the field of the stock markets works more or less this way:

1. In the first place we have to analyze the general economic and political field, in

order to understand whether the system the firm operates in could act in favour of itsgrowth or not; in this field we have to give a look to the policies in terms of taxes, labour,

and the like;

Step 3: defining the stock-picking strategy

Page 32: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

322. Then we have to analyze the sector the company operates in: point of the lifecycle

of the products or services offered by the firm, levels of competitivity, innovation spacesin terms of products and processes, investments in research and development, barriers

to the entrance of new competitors, and so on;

3. Then we have to analyze the balance sheet of the company(ies) of our interest, inorder to determine the key-parameters (typically returns on equity, debts, expected

earnings, operative margins, and the like) for the valuation of its current and future“health state”; the balance sheet’s analysis combined to what written in points 1 and 2

has to lead to the so called fair value, that is what should be the value of the firmconsidering its actual business and the expectations about its future one; the value of

the firm divided by the number of outstanding shares provides, then, the theoreticalprice per share, or fair value;

4. finally, we can compare the theoretical price per share with the market price per

share, so to inspect the possible existance of discrepancies.

If the theoretical price is higher than the market price, then the market seems to bedevaluing the firm,

for some reason.

Step 3: defining the stock-picking strategy

Page 33: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

33Example: if the fundamental analysis leads us to a theoretical price of 25€ per share,

and today the market price is 19€ per share, then it seems that the market is devaluingthe stock, in respect to what should be its right price.

But pay attention, because there might be several reasons for that. Anyway, sometimes

it happens that the market makes mistakes in the valuation of a firm, so, if we havereasonable certainty that our analysis is correct and that the market is devaluing the

company with no reason, then it could be a good deal to buy shares of that company,under the idea to keep them in our portfolio until they reach their fair value.

Vice-versa, if the analysis states that the theoretical price of the firm should be 15€ per

share, then we can say that

the market might be over-estimating the firm,

for some reason. Again, if we have reasonable certainty that our analysis is correct andthat the market is over-estimating the firm, then we could state that it is not time to buy

those shares, and, if we have shares in our portfolio, it could be the right time to sellthem.

Step 3: defining the stock-picking strategy

Page 34: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

34What could go wrong with fundamental analysis?

Fundamental analysis is based on a perfectly logic premise: if the fair value of a

company is 10€ per share, sooner or later its market price will be 10€ per share.

There are limits, though, in this approach. First of all it is not that simple to calculate thefair value of a company, and it often happens that it is not unique, since it depens on

the point of view (sometimes interests too) of the analyst.

A first serious problem is given by the mass of data to be analyzed and interpreted: a“normal” balance sheet can be a volume of hundreds of pages. Multiply that mass of

data times the number of listed companies – 350 only on the italian market – and ittakes a lifetime to read them all. The only way to do that is to pick up a basket of stocks

to be analyzed, excluding a priori on the basis of some reasoning all the other stocks.

For instance, we could decide to focus on a specific sector, or on high capitalizationcompanies (if we are seeking for stability of returns and lower risks), or maybe the

opposite, only low capitalization companies (if we are seeking for higher potentialreturns and can stand a higher average risk).

Doing this we can significantly reduce the mass of data to analyze, even if the arbitrary

selection of stocks to analyze could cause a loss of some opportunities on the firmsexcluded.

Step 3: limits of fundamental analysis

Page 35: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

35In the field of balance sheets analysis there is also the problem of the delay in data; it

often happens, in fact, that when new data are released they refer to several monthsbefore, hence they are not a picture of the current state of the company, but of the

previous one. This can lead to a not updated picture of the firm.

Moreover, fundamental analysis is a “slow” technique, meaning that it produces returnsin months or years; it often happens that as time passes new data come into play, and

new events happen, events that could not be predicted in the first place; these newelements bring with them the need to review the whole analysis, since the picture is

changed. It happens, then, that a correct fundamental analysis needs to be in part orfully revised before the price reaches its initial target.

One of the main issues in fundamental analysis is the value of intangible assets: human

capital (think of an IT company: it could have the new Bill Gates within its employeesand not know it), new licenses that could be registered, new productive processes that

could be invented, new technologies, new products and services that could be born,and the like. How can we, for instance, estimate the expected value of a potential new

product? Think of a pharmaceutical company developing a new drug to cure cancer:how do you quantify it? You first need to determine the probability for the company to

actually develop that drug, when, and its potential business. And how to evaluate therisk that a competitor comes out with a revolutionary product within the next months or

years?

Step 3: limits of fundamental analysis

Page 36: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

36The point is that in the process we also have to account for expectations and

probability of events.

Indeed, the fair value of a company is not only the result of a mere accounting fornumbers in the balance sheet, since it can also account for the expected future value

of projects already started or ready to be started; in othe words, it happens that thecurrent market value of a stock already discounts expectations of future growth or

downturn.

A stock quoting a price lower than its fair value could be the expression of fears ofinvestors for expected future hard times for the company. Similarly, if a stock quotes a

price higher than its fair value we could state that the market is discounting in advancea future growth of the firm.

In a few words, the market price accounts for the past, the present and the future

(known, realiable, or even just probable).

In other words, prices discount (almost) everything.

Step 3: expectations and probability

Page 37: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

37Expectations are usually a function of personal opinions of analysts, both in terms of the

effects (on prices, of course) of specific events and of the quantification of thoseeffects.

The value of a new model for an automotive company, for instance, could be hard to

quantify and the valuation of expected earnings could be significantly different amonganalysts.

The birth of a new technology could represent a competitive advantage only for young

and dynamic firms, and mean earnings downturns for firms that find hard to modernizethemselves; the quantification of these issues could not be the same among different

analysts, because of their personal opinions.

But looking at these issues from another point of view we realize that if it wasn’t so, ifthere were no asymmetries in the valuation of economic matters, there would not even

exist the markets!

If, for instance, all the analysts agreed that the fair value of a stock was 19€ per share,who would ever sell it for less than 19? And who would ever buy it for more? Nobody, of

course! The market would not exist, and no trades would take place.

Different expectations and disagreements are the natural fuel for the asymmetries ininformation that make possible trades on the exchanges: trades made by sellers who

get rid of their shares for their reasons, and buyers with opposite expectations.

Step 3: expectations and probability

Page 38: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

38These asymmetries are originated basicly by two factors: different levels of access to

information, in terms of time (not all investors receive the same information in the samemoment), and capability to properly analyze and interpret that information.

Give the same balance sheet to ten different analysts and you will very likely have ten

different valuations of the fair value of the company.

Asymmetries in the availability of information often cause masses of investors to takewrong decisions, buying shares that already grew too much, and selling them when

prices dropped significantly, and a bounce is at stake.

Generally speaking, the masses do the opposite of what they should do.

Americans have many proverbs that can describe the behaviour – sometimesapparently irrational – of the markets. One of the most famous is “buy on bad news, sell

on good news”. In other words, do the opposite of what it might seem reasonable todo.

Where does the irrationality of the markets come out from?

Step 3: expectations and probability

Page 39: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

39

Step 3: about the irrationality of the markets…

Page 40: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

40When companies announce explosive earnings, it sometimes happens that their prices

drop dramatically, out of any common sense.

Investors usually buy shares in that moments, according to what seems to be logic:good news, then good perspectives, then we buy.

But that happens usually because of misleading advertising, news in red letters on

papers…

When the “smart money” (banks, mutual funds, insurance companies, and the like)needs to sell huge amounts of shares, it needs someone willing to buy them… The red

letters in papers are made to attract investors, so that the “sharks” can sell.

Why? Because they already took advantage from the news, either because they knewit long before or because they foresaw something before anyone else. Going deeper

into the matter, it often comes out that the price increased significantly weeks beforethe announcement of explosive earnings.

Who sells today bought long time ago, when prices were low because no investors

were attracted by that company. Now that everybody knows it’s time to sell, takingadvantage of the river of buyers generated by the news on papers.

To gain we need to be one step ahead all the others

Step 3: the trading edge

Page 41: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

41Maybe a little step, but always ahead. That’s the only way to win; when news are public

and can be interpreted in one way only, they are worthless, since they don’t carry anyadvantage.

Once again, what allows to make profits is the asymmetry in information.

The advantageous asymmetry can be achieved basicly in two ways: the first is to gain

early access to the information; this is the hardest way, and it is also a phelony, becauseit’s insider trading, forbidden by the laws, national and international (information should

be available for all the operators at the same time, in a perfect world…).

The second way is to be able to take advantage of new data before the others, seeing(and foreseeing) things that nobody else, or only a few people, can see. But to do that

we need skills and tools better than average.

A paramount element is the testing of the effectiveness of our trading techniques overpast data: we cannot invest money on the basis of trading rules that haven’t been

tested on historical data and proven to be effective, givin’ us a sure competitiveadvantage; read it systematic profits.

We need, then, to translate our investing techniques into sets of rules clear and well-

defined, that can be applied mechanically as specific sets of conditions show up.

Step 3: the trading edge

Page 42: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

42An example? A coded strategy based on fundamental analysis could be “buy a stock

when the board of directors announces the payment of a dividend higher than theprevious; sell one week before the payment of the dividend”.

Does it work? The only way to answer that is to take data of all the listed stocks over the

past 10 years or more and check the results that we could have achieved. The longerthe time period under analysis, the higher the number of observation, giving the analysis

a much higher statistical significance (read it reliability, a measure of the probabilitythat what happened in the past will keep happening in the future).

We have to do this, because as stated before we have to define a trading strategy that

gains most of the time (always it’s not possible); how can we know that our strategygains most of the time if we do not test it?

To test the effectiveness of a trading strategy is something very popular these days in

the trading field. You can hear people talking about quant trading, algorythmictrading, quantitative, systematic, automatic. All similar terms, even if not synonims.

Step 3: systematic trading

Page 43: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

43The common denominator to all of them is that a systematic trading strategy – which

means doing always the same things any time a specific set of conditions shows up –can be managed in two ways.

The first is manually: in the moment a trading signal shows up we manually send an

order to the market; the second is automatically: we program a computer so that whena specific set of conditions shows up it buys or sells something on its own.

The importance of the coding of trading strategies is a concept that sooner or later

becomes perfectly clear to any trader, because investing money without knowing

whether our approach is winning or losing in the long term leads us to an unbearablestress.

It usually takes just some negative trades in a row to make investors abandon anyimprovised strategy. It is mostly a problem of emotions, ranging continuously from

euphoria – when things go well – to fear – when they go wrong, passing through a wideset of intermediate states.

The only way to keep emotions on a lead is to code trading rules so to always act in

cold blood. Rules tested on past data in order to define trading strategies able toproduce consistent gains always keeping risk under full control. Operative rules can be

based on fundamental analysis or technical analysis (which we’ll see now), or even acombination of both.

Step 3: quant trading

Page 44: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

44Technical analysis was born at the end of the XIX century thanks to the studies of

Charles H. Dow, an american, founder of “The Wall Street Journal”; since then itdeveloped – and keeps developing today – thanks to the contributions of many

researchers.

The primary goal of technical analysis is analyze financial markets and recap all theavailable information in a few indicators – the price most of all – that can be

represented on a chart. The idea is to take operative decisions based only on the chart,without any concern about balance sheets, the general state of the economy, policies

about labour, taxes, import and export, and the like.

Technical analysis is based on three primary principles:

1. all the information available in the markets at some time is discounted in the currentprice;

2. history repeats itself: under the same conditions, what happened in the past willhappen again in the future, with similar effects;

3. prices do not move randomly; on the opposite, they draw trends that can be used tomake money.

In other words, prices move in patterns that tend to repeat in time; we can take

advantage of these patterns to open positions under the expectations that trend willbehave coherently to what happended in the past under the same initial conditions.

Step 3: technical analysis

Page 45: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

45Example

Suppose to observe that any time the price makes a new annual maximum it keepsmoving up the next year: we can say we found a repetitive pattern in the market, that

can be used to gain money the next time it shows up.

We are always in the field of odds, of course: technical analysis is based on theobservation of patterns that tend to repeat on a statistical basis: what happens today

should make the price move in some specific way, but nobody can give us fullguarantee that it will happen.

Any strategy based on technical analysis requires then testing on past data: we need to

code the operative rules of our strategy and apply them on historical data. If, after abacktesting, the strategy gives proof of efficiency, restituting a satisfying profit over

time, then it could be reasonable to use it on future data, assuming that what hasproven to be effective on past data will be effective on future data too.

We will see some backtesting of trading strategies forward.

Step 3: technical analysis

Page 46: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

46

46

Another very famous american proverb is “trend is your friend”. Its meaning is quite

simple: if the price of a good is increasing, this means that the market – on average –thinks that the real value of that good is higher than its current price.

The reason underneath that behaviour is not important: what matters is that the market

is the sum of all the expectations of the operators active in it; if positive expectationsare stronger than negative ones, the only reasonable conduct is to follow the current,

that is adapt to the positive view of the market.

It’s time to buy.

This reading of the market remains valid until proven otherwise: when negativeexpectations become stronger, it’s time to sell.

There is a clear, unavoidable, limit in technical analysis, then: it never anticipates the

future; it just follows the current, adapting to it. Indeed, it is never possible to state thatthe price is going up or down without watching it going up or down.

It is impossible to anticipate changes in trend directions: we can only adapt to the cleartrend in the price. It is not possible to buy on a minimum or sell on a maximum, then, but

by chance.

The basics of technical analysis: the trend

Page 47: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

47

47

Technical analysis can only tell to buy a stock that has already risen from a relative

minimum, and sell a stock only with some delay, after it has already dropped from arelative maximum.

Timing is crucial, then: the more accurate our investing strategy, the eralier it could

identify the birth of a new trend in the price, and take advantage from it.

As we’ll see, it is possible to improve investment strategies using several types ofindicators; some of them can be used to anticipate possible future changes in the price

direction, allowing investors to reduce (not eliminate) the operative delay.

Everything is based on the price charts: they are the key element to start from.

Charts are just price representations over some time period; the two variables on theaxis are then price and time.

Time can be in days (that’s the most common way, called end of day), but also in

weeks, months, quarters, or years; or even in fractions of days: 240 minutes, 120, 60,30,15, 10, and so on down to a minute (intraday charts).

On any market stocks and other instruments are quoted in time bands and according

to specific rules set by the Exchanges; on the italian stock market, for instance, stocksare quoted daily, Monday to Friday, 9am to 5.30pm.

The basics of technical analysis: the trend

Page 48: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

48

48

This is the so called continuous phase: there are no stops to negotiations in this phase,

unless particular events happen.

Before the continuous phase there is an opening auction (8 to 9 am); in it buyers andsellers show up on the market with their buy and sell proposals. Orders are collected by

IT systems that match them according to specific rules in order to reach some sort ofequilibrium price, that is taken as opening price (we will see these dynamics forward).

Then trades happen all day long, generating waves that will lead to an intraday

maximum and an intraday minimum (not necessarily in this order).

At the end of the day trades stop and a final price is recorded: the price of the lasttrade of the day. That price can be seen as some sort of equilibrium point for that day: it

is the result of all the known facts and the expectations for that stock in that moment.

Indeed at the end of the continuous phase a closing auction takes place. It lasts only afew minutes, but leads to a closing price that fulfills some special rules.

To be thorough, there are two more possible closing prices: the official and the

reference one. Without going into too much details, they are averages of the prices,weighted on the traded volumes, used to give more information to specialists. The

reference price is also used when the closing auction does not provide a closing price(it happens, sometimes).

The basics of technical analysis: the trend

Page 49: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

49

49

Summing up, for any day there are four key-prices pointing out the dynamics of supply

and demand: open, high, low, close.

Given these four values we can build several price charts; each of them carries adifferent informational power and can be read in several ways.

Here we will speak of the line chart, the bar chart and the candlestick chart. There are

other types too, but they are out of our field of interest for this course.

If we build a chart using only closing prices for any time period (usually a day), and thenwe link all the closing prices with a line, we get a so called line chart (see next slide).

The basics of technical analysis: the trend

Page 50: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

50

50

The line chart

Page 51: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

51

51

The chart on previous slide shows the FTSE Mib Index, including the 40 main stocks

(the so called blue chips) listed on the italian Stock Exchange, between the end ofMay and the beginning of September 2014.

How can we read this chart? What information can we get from it? How can we

use this information to gain money?

In order to answer these central questions we just have to understand the essenceof technical analysis, in the first place. Let’s recall three major concepts stated

before:

1. if the price of an asset grows, it’s because there are more optimists than

pessimists,more buyers than sellers;2. to profit from price movements we need to identify the trend and follow it;3. we have to be prepared to deal with some degree of operative delay, since wecannot tell that a market is growing or dropping if we do not see it growing or

dropping for a while.

A very important rule, then:

follow the market, and don’t try to anticipate it.

The line chart

Page 52: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

52

52

As we identify the trend, let’s say up, we have to buy and follow it, then wait to

see what happens. In the moment the trend changes direction we have tounderstand it and adapt our behaviour, selling to get out of the trade.

Now we have two issues to deal with: how to identify the trend, so to be able to

follow it, and how to spot the end of that trend, so to be able to get out as pricesstart to drop. As previously stated, timing is crucial: the sooner we are able to spotthe beginning of a new up trend, the lower will be the price we pay; the soonerwe will be able to spot the end of the up trend, the higher will be the price we will

sell for. Timing is all, as Americans say!

Let’s look back to the chart and let’s try to spot the trend. Where is the price

going? That might seem a trivial question, but to answer that in an unquestionableway we need to define a clear, scientific, rule.

Indeed it is not possible to give an answer to that question without introducing a

second variable in the model: time.

This because the direction of the trend is not always the same: prices move inwaves, that in each time window – on average – move upward or downward;

then, at some point, they change direction, and then prices move to the otherside. And so on.

Price and time

Page 53: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

53

53

A way to answer the question about the direction of the price is to compare the

final price with the initial one: nowhere! Indeed the final price is more or less equalto the initial one. This is said to be a sideway trend: no direction. Another waycould be to divide the chart in zones, like this:

Price and time

Page 54: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

54

54

Basicly, price waves generate maximums and minimums that can be higher,

equal or lower than the previous ones; this information can help us define thegeneral trend of the price.

Indeed we can synthetize these ideas in the first postulate of technical analysis:

If two consecutive relative minimums and maximums are growing, the trend is up;

if they are all more or less at the same level, the trend is lateral, or non-directional;if they are decreasing, the trend is down.

In zone 1 the trend is up, down in zone 2, up again in zone 3.

Now we know how to spot the trend.

Later on we will also learn how to take advantage from it, and how to identifychanges in the price direction.

Price and time

Page 55: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

55

55

Looking at a line chart it seems quite easy to spot minimums and maximums: a

minimum is a point set between higher points on both sides; a maximum is a pointset between lower points on both sides:

Minimums, maximums and trendlines

Page 56: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

56

56

They are all relative minimums and maximums; they are also called short term

minimums and maximums. Not all those points are significant, by the way: lookingcloser, some of them seem to be more important than others, since they are easierto spot:

Minimums, maximums and trendlines

Page 57: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

57

57

Under another point of view, we can state that those points are more important

because they mark significant tendencies.

Linking minimums and maximums with straight lines we can finally obtain tendencylines, or trendlines.

Let’s focus on the chart on previous slide and remember the first postulate oftechnical analysis. In the chart we have three key-points: two minimums and amaximum. The two minimums are increasing (the one on the right is higher than

the one on the left), hence we can state we are in an up trend.

Linking the two minimums with a line (see next slide) we get our first trendline.

A trendline linking two growing minimums defines an up trend, then. What is theutility of the trendline?

It delimits the direction of the price, and can tell whether the price is still moving inthe same direction or the wind is changing.

Minimums, maximums and trendlines

Page 58: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

58

58

In technical terms, the line linking growing minimums is called support. Indeed it

has the attitude to support the price, keeping it oriented to the upside.

Minimums, maximums and trendlines

Page 59: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

59

59

Now we have spotted the trendline we need to understand how we could use it to

take right investing decisions.

The idea is that if the support can keep the price moving to the upside, pushing itup each time it is tested in the future, then it could tell us when to buy.

What we have to do, then, is wait for the next test of the trendline and buy in themoment of touch.

See next slide: the points A and B are the two minimums seen before. In the pointC the price leans on the support and bounces to the upside. Buying in C hasproven to be a good choice.

Will it happen again in the future? We can only wait and see! And it happensagain in D.

Minimums, maximums and trendlines

Page 60: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

60

60

It seems that the idea could be valid: each time the price touches the support it ispushed back up; the trend is still upward, since all the new relative minimums arehigher than the previous ones and after each new minimum the price moves up

seeking for higher maximums.

Minimums, maximums and trendlines

Page 61: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

61

61

There are some problems in this approach, though.

Two, above all: what to do if the support doesn’t work (the price cuts it to thedownside), and how to manage open trades.

The first issue concerns risk management: what to do when things go wrong; webuy on the support and the support doens’t work anymore.

The second issue concerns profit management: what to do when things go well.

Indeed, any trade is made of three fundamental elements: choose what to buyand when, set the capital per trade, decide when to close the trade, either it

gains or loses money.

Sooner or later we will have to get out from a trade! We will deal with all thesematters forward.

Minimums, maximums and trendlines

Page 62: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

62

62

Now let’s see what happens when a support doesn’t work anymore: on a new test

the price cuts it to the downside instead of bouncing back up:

Weak supports

Page 63: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

63

63

In the point E the dream is broken: the price tests again the support and cuts it to

the downside. If we buy in E assuming that the price will bounce back to theupside we will have to deal with our first big problem: what should we do now?

Let’s move on to resistances before answering that question.

As it is possible to link growing minimums with trendlines and draw supports, it isalso possible to link decreasing maximums and draw other trendlines, calledresistances.

A resistance is a trendline that keeps the price oriented to the downside: eachtime the price touches the line from below it is pushed back down.

See next slide for an example: as we link the two points A and B we have theresistance; it pushes back down the price four times then, in C, D, E and F.

Resistance

Page 64: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

64

64

Remember what was stated about trends: when you spot a trend you have to go

with it, following it until it changes direction.

Resistance

Page 65: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

65

65

In the moment the support is broken we have to deal with two issues: how to

manage the risk of losses and how to read the chart from now on.

We will take care of risk management forward; let’s first discuss the second issue.

Empirical observation of the market behaviour leads us to state that:

a broken support tends to become a resistance; a broken resistance tends tobecome a support.

This is known as the state change postulate: when a trendline is broken it usuallychanges its state; what once pushed up the price now pushes it down, and vice-

versa.

Look next slide: after the breaking of the support in the point E the price drops,then bounces and tests again the ex-support from below, point F (and again soon

afterward), and this time the support pushes the price on the downside: it becamea resistance!

Resistance

Page 66: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

66

66

We can then unquestionably state that the uptrend is over.

Resistance

Page 67: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

67

67

We can then sum up all these concepts in a new postulate:

an uptrend (a downtrend) can be considered over when the support (resistance)

is broken and a next test confirms its state change.

That’s what happened in E and F on previous slide: breaking of the support, pricedrop, bounce, new test, state change confirmation.

There is not much we can do now: there are no signs of a possible new uptrend, so

we have no buy signals. All we have to do is wait for new trading opportunities.

We will then wait for a new support to be created, and for new tests afterward.

And so on.

The end of a trend

Page 68: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

68

68

The strategy to buy on a support in an uptrend can be classified as the strategy to

buy a strong stock in a moment of temporary weakness.

Recalling all the ideas seen so far, in fact, we can state that after spotting the twogrowing minimums sequence and the maximum between them, the wait for the

new test of the trendline in the point C means to wait for a moment of weaknesswithin the ongoing up trend.

This temporary weakness can be exploited to buy according to the current up

trend, assuming that the price will move up again soon.

As previously stated, prices always move in waves; the general trend depends on

which waves are wider.

Look at the chart on next slide: the waves go alternatively up and down, but thewidth of upwards – impulsive waves – is higher than that of the downwards –

corrective waves – then the trend is up.

Buy the corrections

Page 69: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

69

69

Impulsive and corrective waves

impulse

correctionimpulse

correction

Page 70: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

70

70

To buy on weakness is coherent to the logics of technical analysis, under some

point of view: it assumes that the trend will keep going up until proven otherwise,because that is the information the chart is giving us.

Under another point of view it is incoherent, though: since technical analysis

cannot anticipate the future, who can tell us in advance that the support will keeppushing up the price on a new test? No one, of course.

Indeed, assuming today we are in the point C on slide 60, nobody can tell us that

the price will bounce for sure tomorrow: nothing is certain and nothing canprevent the price to behave in C as it will behave in E later on.

The point is that it is not correct to buy in C and D, but the day after those points,when we will know for sure that the price bounced on the support and it will likelykeep bouncing.

We have to allow some delay, then, but this prevents us to lose in the point E: inthe moment the price cuts the support instead of bouncing, we do not buy.

Buy the corrections

Page 71: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

71

71

And by the way we can also take into consideration another way to do the job.

Till the price keeps moving up, the support plays a very key role: if the price keepsmoving above it, bouncing on any new test, the trend will stay up.

Now let’s reverse this statement: given a resistance, what we expect is that it willkeep the price going down until it will be broken to the upside. If, on one hand,the breaking down of a support states the change of the trend from upward to

downward, on the other hand the breaking up of a resistance states the changeof the trend from downward to upward.

This leaves room for a radically different trading strategy: to buy on strenght, not

on weakness.

Look next slide.

Another way to do that

Page 72: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

72

72

After the breakdown in E and the test of the support in F, the price draws two newdecreasing maximums, G and H. The resistance linking them is the new guideline

for the trend, that will be downward until a breakout shows up.

Buy on strenght

Page 73: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

73

73

And later on we have a breakout of the resistance trendline. This is a symptom of a

possible trend change, from down to upward. Where this breakout will lead us, wecan’t tell in advance; in this particular case it leads to a powerful growth in theprice:

Buy on strenght

Page 74: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

74

74

One very important feature in trend analysis refers to the expected duration of the

trend: it’s a paramount element, since the longer the lifetime of the trend, thehigher will be the profit achievable following it.

Emipirical observation of the markets leads to a new postulate of technical

analysis:

On a statistical basis, the duration of a trend is directly proportional to its width andinversely proportional to its slope.

The wider the waves and lower the angle of the climb, the longer will likely last thetrend; vice-versa, the steeper the angle of the climb and the narrower the price

waves, the shorter will likely be the trend.

In the chart on next slide you can see the FTSE Mib index on a quite long timewindow, about two years. In region 1 you see a strong uptrend: the price increases

significantly in a short while and the few corrective waves are very short; but thistrend lasts only two months. Another very strong trend in region 2: it lasts only threemonths, with only a few and very short corrections. In region 3, instead, we see avery long downtrend, about 15 months, with a very low average slope and wide

corrective waves (to the upside this time).

Expexctations about the lifetime of the trend

Page 75: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

75

75

Expexctations about the lifetime of the trend

Page 76: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

76

76

The approach presented in the past slides allows investors to take any chart and

read it perfectly, but in retrospect. Indeed, in applying it in real time it raises severalproblems, that make it much more complicated than it might seem:

1. which trendline to draw on a chart full of so many minimums and maximums is

not so trivial;2. depending on the time window of the chart, the interpretation can changesignificantly; this leads to the drawing of many different trendlines depending onthe duration of the trend under analysis;

3. two different analysts in front of the same chart could likely draw differenttrendlines, since the importance of specific minimums and maximums is oftensubjective;

4. if, in order to draw trendlines with a high degree of importance, we seek for linesthat get tested precisely a high number of times (assuming each new test givesthem more importance), we can very soon realize it will be a very hard job: wecan link many pairs of minimums and maximums, but to be able to align three or

more minimums or maximums is much harder…

About point 4, all the points in the charts on previous slides are not as precise asthey seem: it is evident looking closer.

Limits of the trendline based approach

Page 77: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

77

77

One of the paramount argumentations in the field of trends and trendlines based

trading is whether the price behaviour approaching to trendlines and after thebreakouts is random or not. Under some point of view, even on the chart of thebody temperature of any human being it could be possible to draw trendlines.Could we state, on such a chart, that the breakout of a resistance would likely

lead to a high temperature? Sure not!

What makes different, then, the chart of a body temperature from that of Cocoa,Telecom Italy, Gold, Oil, the Nasdaq Index or the german Bund?

The answer lies in the psychologic dynamics acting on prices: body temperaturesmove as a response to physical matters, out of our control; market prices of

financial assets and traded goods move in response to human behaviours, whichin turn are moved by news, sure facts (that can be interpreted in different ways),deceits, expectations, emotions.

When, for instance, on a chart we can draw a resistance line that can be seen bymasses of investors set all around the world, we can expect that the breakout ofthat line will trigger a powerful price movement, appealing rivers of buyers,pushed to buy under the expectation that the breakout would be just the prelude

to new highs soon to come.

Emotions play a central role in technical analysis.

Do prices follow a random walk?

Page 78: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

7878

Moreover, deep studies made by famous traders such as Larry Williams pointed

out that prices of financial assets do have memory: what happens today is theresult of today’s news and yesterday’s trend; in other words, what happenedyesterday affects what happens today.

And as a consequence, what happens today affects what will happen tomorrow.

Indeed, Williams gave proof that the odds to have a positive (negative) daytoday are higher than average if yesterday was a positive (negative) day too. This

happens because when the market has a positive or negative view it lasts morethan one day, most of the times. If prices, day after day, were independent, theodds to have a positive day after a positive day should be 50-50 (just like the

flipping coin game)!

Williams also gave proof that to buy a stock on any day of the week is not thesame: some days are most likely positive than others… The same happens, in

different days, for bonds!

Some months of the years tend to be statistically more positive or negative thanothers (see the January effect, “sell in may and go away”); years that end with 5

are statistically very positive for stock indexes. The list of these curious “random”phenomena is very long…And the conclusion is only one: patterns do exist.

Do prices follow a random walk?

Page 79: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

79

79

Only a couple more things before moving on:

1. it sometimes happens the trend is non-directional, or lateral; this happens whenpairs of minimums and maximums are more or less at the same hight; they arecalled double minimums and maximums. In such situations trendlines are

horizontal and both the support and the resistance have the same importance:the first that is broken will likely point out the next trend;

2. breakouts of trendlines not alway lead to trend reversals; it often happens,

indeed, to testify so called false breakouts: the price breaks a line and soonafterward it comes back in, denying the idea of a new directional trend oppositeto the previous one. It is part of the game, though: as previously stated, there is no

strategy always right; what matters is that a strategy is valid on a statistical basis…

Final considerations

Page 80: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

80

80

As previously stated, timing is one of the key-factors for succesful trading.

Now we need to take a step forward and inspect if there is any chance toimprove timing.

In other words, what we are going to look for now is – if it exists – a way to beatother market participants being able to spot a trend change before most of othertraders.

In this field several indicators have been created over the years.

Some of them are very popular among traders: moving averages, stochastic

oscillator, relative strenght index, moving average conversion/diversion (MACD),and some others.

All indicators have one thing in common: they dipend on some numeric

parameter , that can be optimized on past data. Here the need for personalcomputers shows up, and the full understanding of how to perform a backtest andmoreover how to evaluate the results of a backtest become mandatory.

This is then our mission from now on. Let’s start from moving averages.

How to improve timing

Page 81: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

81

81

To calculate the average of some number X of daily closing prices we sum all the X

terms and we divide the result by X. If on any new day we start over and we calculate anew average, cutting off the oldest term and replacing it with the new one, we get a

moving average.

Consider a three days moving average, for instance: we first need three days tocalculate it. As we have the third closing price we calculate the first mean. Then, the

next day we remove from the data series the closing price of day 1 and substitute itwith the closing price of day 4. On day 3, in other words, the mean is the average of

days 1-2-3, while on day 4 the mean is the average of days 2-3-4. And so on. Every daythe moving average moves, but it is always based on the same number of data.

Moving averages are clear trend indicators. Despite their simplicity, in fact, they are

widely spread among professional investors; their best merit is they smooth the noise ofthe price waves, pointing out the only relevant information: the direction of the price.

When the waves are rough, moving averages make things much more linear.

An example will make things clear. The chart on next slide shows the stock A2A (theelectric company of Milan), listed on the italian market, in the period between February

and June 2014. Aside the price line – the dark continuous line – there is also a movingaverage, the dotted line. It’s the 20-days simple moving average, or SMA20.

The number of days is the so called pace of the average. The 20-days SMA is very

common in the field of trading, since it’s more or less the duration of a working month.

Moving averages

Page 82: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

82

82

The choice of the pace of the average is not random. Later on we will discuss the

crucial – and very delicate – matter of the choice of the best pace for the movingaverage.

Moving averages

Page 83: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

83

83

Notice how the moving average moves in the same direction of the price, most of

the time, but in a much more linear way: it smoothes the noise of the marketkeeping its direction.

Here a crucial fact: when the trend is up, the moving average lies below the price;

when the trend is down, the moving average is above the price.

Focus on the relative maximum right on the left of the point B: the moving average20 days calculated in that moment is the average of the closing price of that day

and the previous 19, all lower than that; as a consequence, the average is lowerthan the current price. In the same way, if we focus on the relative minimum righton the left of the point C, we can see that the moving average 20 days is the

mean of the closing price of that day and the previous 19, all higher than that: themean is higher, then.

Summing up, in downtrend the moving average is higher than the price, in

uptrend it is lower. These dynamics are perfectly clear on the chart: on the left sidewe have an uptrend and the average is below the price; in the central part thetrend is negative and the average is above the price; on the right side the pricerises again, and the average is below it.

Moving averages

Page 84: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

84

84

And finally a paramount result: when the trend changes direction, the moving

average cuts the price: sometimes from below to above, sometimes above tobelow. And recalling the relationship between price and moving averages, theconclusion is that when we see a cross between the price and the movingaverage a trend change is very likely going on.

There are two possible cuts: when the price cuts the moving average from belowto above, points A and C on the chart, the trend changes direction from negative

to positive; it is called golden cross: it’s time to buy!

Vice-versa, when the price cuts the average from above to below, points B and Don the chart, trend changes from positive to negative; this is a devil cross: time to

sell!

Notice how the average tells the investor to buy in A, right before a powerfuluptrend, and then to sell in B, just before a deep drop; then to buy in C, where a

new uptrend is at stake, and finally to sell in D, when the trend is getting weak.

Notice also how the average acts sometimes as resistance, some days before thepoint C, or support, just a few days before the point D.

Moving averages

Page 85: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

85

85

Finally, to use a moving average requires the acceptance of some degree of

delay. Indeed it never tells you to buy on a minimum or to sell on a maximum: itprovides buy and sell signals with a remarkable degree of realiability, but alwayslate, never on key reversal price points. It’s part of the intrinsic nature of technicalanalysis: ther is no way to predict maximums and minimums.

So far we used the 20-days moving average. What would have happened usingan 8-days or an 80-days? The chart on next slide shows again the stock A2A, andthree moving averages: the 20, the 8 and the 80-days.

What changes with the pace is clearly the position of the moving average inrespect with the price: the higher the pace, the higher the distance between

them.

Moreover, what changes together with the pace is the reactivity of the movingaverage to price changes.

This can lead to advantages and disadvantages.

The right pace for the average

Page 86: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

86

86

8-days moving average

20-days moving average

80-days moving average

The right pace for the average

Page 87: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

87

87

As we can see, the 8-days moving average provides more promptness to

operative decisions: the first buy signal, point A using the 20-days MA, comes afew days earlier. The price paid is lower, then.

At the same time, though, the 8-days MA gives the exit signal too early in respect

with the 20-days MA, since a devil cross shows up mid May; and soon afterwardthere is a new golden cross that makes us buy again, to sell on a new devil cross afew days later (a bit on the left of the point B). Here we have the indication of anew possible downtrend a few days earlier than if we were using the 20-days MA.

Between late April and early May, the 8-days MA produces a series of uselesstrades: in and out more or less at the same prices all the time. A new good trade

happens late May: the 8-days MA provides a buy signal a couple of days earlierthan the 20-days MA, hence for a better purchasing price; the sell signal comesaround June 10, for a price more or less equal to that comes out using the 20-daysMA, but ten days in advance.

The right pace for the average

Page 88: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

88

88

Summing up, the shorter the pace of the moving average, the prompter are the

buy and sell signals, and the more convenient are purchasing and selling prices.This approach has also a drawback, though: it sometimes produces false signals,wrong trades, that cause operative costs and no gains (sometimes losses too).

Now look at the 80-days moving average. It delays too much the trades,penalizing the trader. Look, for instance, at the first part of the chart: the goldencross shows a few days later than in the other cases, making the trader buy for aworse price. The devil cross – the signal to get out – then comes too late, telling the

trader to take profit when the price has already fallen dramatically from therelative high. In the rest of the period there are poor buy and sell signals. Acomplete disaster.

Given the fact the 80-days MA is not a good choice, which should we takebetween the 8-days and the 20-days? It is hard to give an answer without astatistical test: we need a computer to get that answer. Indeed, nothing can tell us

that the 10-days is not even better than both the 8 and the 20! And what aboutthe 12, the 14, and so on?

The right pace for the average

Page 89: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

89

89

Here we see how important the backtest of a strategy can be. Only a computer

can test all the possible paces for the moving average for each listed stock, bond,currency, stock index, commodity, mutual fund, and the like, and tell us which setof values would have provided the best result – the maximum reward on risk ratio– on historical data.

There are several softwares available these days for this purpose, such asMulticharts, Metastock, Tradestation, Visual Trader, or Pro Real Time; with a bit ofVisual Basic it is also possible to test strategies in Excel.

On next slide we can see a study on the stock A2A between July 1998 and August2015. The purpose of the study was to find the best pace for the moving average.

In order to do that, the software Metastock has been used; the idea was to buy ona golden cross and sell on a devil cross.

Metastock has been used to test all the paces between 4 and 30 days, with a step

of 2 days per test. Given an initial capital of 10k euro, and using all the availablemoney for each trade (here we are taking a step in the field of moneymanagement, which we’ll see soon).

The right pace for the average

Page 90: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

90

90

For now let’s just focus on columns “% gain” and “OPT1”: the former reports thegross percent profit for each pace, the latter reports the pace for the movingaverage that produced that percent profit. It’s clear how the best choice on the

stock A2A is the 8-days (results are sorted top to bottom). Indeed it would haveproduced a gross total 69% gain, while the 20-days, for instance, would haveproduced a 5.4%, and the 30-days a -8.2%.

The correct evaluation of trading strategies, indeed, is a very complicated matter,since the parameters to be considered are several; we will speak again of theseissues later on.

The right pace for the average

Page 91: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

91

91

What matters now is to properly understand the meaning of what we just did: we

used a personal computer to tell us on historical data and on a statistical basiswhat is the best way to invest our money. The result is a simulation of what couldhave been gained in the past trading in some specific way or another.

To trade in the future in the same way means to assume that history will repeatitself, and what worked in the past will keep working in the future, similarly.

Indeed, this is one of the three principals of technical analysis (see slide 44).

Is it possible to do this strategy optimization according to some criteria that couldprovide the trader a good confidence that what happened in the past will likely

happen again in the future with similar results?

The answer is positive, as we’ll see. We are entering the world of systematictrading.

The right pace for the average

Page 92: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

92

92

Previously it has been stated that a trading day starts with an opening auction and

an opening price, then there is a continuous phase that leads to an intradayminimum and maximum, and finally there is a closing auction to determine aclosing price.

A line chart shows the dynamics in the closing price only, losing all the otherinformation. Indeed, the only closing price is an incomplete picture of a tradingsession: how can we now how the price moved during the day looking only at itslast value? Was it a quiet session or a lively one? In case it was a lively day, who

took the lead of it? Bulls (the buyers) or bears (the sellers)? Is the maximum far fromthe minimum, or are they quite close? Is the close higher or lower than the open?How far are open and close?

All these information can be very important in the trend analysis and in thedecision taking process, since the inner dynamics of a trading session can provideuseful tools for the interpretation of the current trend.

How can we go beyond the line chart, then? The answer comes from the barchart (see next slide).

The bar chart

Page 93: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

93

93

The bar chart

Page 94: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

94

94

For each trading session we no longer have just a point, but a figure, made of a

vertical bar and two small horizontal scores, one pointing to the left, the other tothe right.

The horizontal score pointing left reveals the opening price, the one to the right

the closing price; the two extremes of the vertical bar point out the maximum(top) and the minimum (bottom).

For each trading session we no longer have just one information, then, but seven:

open, high, low, close, distance between open and close, position of the close inrespect with the opening, distance between maximum and minimum.

The distance between open and close shows how much the market’s judgmentabout the fair price of the asset is changed during the day: if, for instance, theopening price of the stock ABC for some day is 8€ and the closing price is 7.2€ (-10%), this means the valuation of the company ABC in the minds of investors is

changed dramatically, for some reason.

The bar chart

Page 95: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

95

95

The position of open vs close tells if the day has been positve or negative; the

distance between minimum and maximum, alias the daily range, is a measure ofvolatility of the asset, that is a measure of risk and opportunity.

Volatility of the prices of a financial asset is a key parameter for the evaluation of

the price dynamics over some time frame. We will speak again of this central issuelater on. Bars can be daily, weekly, monthly, quarterly or yearly; but also intraday:4 hours, 2 hours, 60, 30, 15, 10, 5, and even down to 1 minute.

Before discussing interpretation rules for bar charts we move on to the japanesecandlestick chart, that is just a variant of the first.

It is said that the candlestick chart dates back even to the 17th century; in the USAand Europe, though, it became popular only in 1994 thanks to Steve Nison, afamous american trader.

The idea is to represent a trading day with a figure, on the basis of the four key-prices open, high, low and close. In order to immediately point out the direction ofthe day, candles can be of two different colours: white (or green) for positivesessions, black (or red) for negative sessions.

The bar chart

Page 96: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

96

96

Instead of a bar, this time a rectangle is used, combined with two vertical lines.

The former is called body, the latters are called shadows. The body is white orgreen when the close is higher than the open, black or red in the opposite case.Once again, seven inputs in just one sight, then.

Moreover, the specific shape of a candle, and its position within the overall shortterm trend bring with them much more information power, as we’ll see in the nextslides.

Candles can be interpreted on their own, in pairs, in groups of three or more.

Candlestick charts

High

Close

Open

Low

High

Open

Close

Low

Page 97: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

97

97

The width of the body and its colour point out the tenacity of the price in a specific

direction along the trading session: a wide white body, for instance, means thatdemand was stronger than supply all day long, pushing relentlessly the price up.

A long white candle means strenght, then, while a long black candle means

weakness (see next slide).

Short bodied candles reveal indecision: it seems the market doesn’t know what todo.

Here the shadows can be crucial. Long shadows, indeed, tell us that demand orsupply pushed the price up or down, but at some point the other side of the

market took the lead.

Long shadows on both sides unveil a fierce fight between buyers and sellers tookplace, ending in nothing (see slide 99).

Long bilateral shadows and short bodies, like in the circled candles in the chart onslide 99, mean the price is substantially in equilibrium, since any attempt to move itin a specific direction has been promptly neutralized.

Candlestick charts

Page 98: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

98

98

Candlestick charts

Long white or long black candles

Page 99: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

99

99

Candlestick charts

Long bilateral shadowswith short bodies; these

candles are referred toas spinning tops

Page 100: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

100

100

The equilibrium of a short bodied / long shadowed candle is very unstable,

though: a strong directional movement is probably soon to come.

When short bodies come together with short shadows on both sides theinterpretation is very different: they reveal a total lack of interest in that asset by

the operators. Until new information come into play we can expect that asset willnot move significantly.

Short bodied candles with only one long shadow are completely another matter: ifthe long shadow is the upper one, for instance, it means demand was strong for agood part of the day, then at some point supply became much stronger, pushingback down the price (see slide 101). Such candles are called exhaustion signals

(they belong to the family of the so called reversal patterns): demand is out ofpower, and supply is much stronger. If a candle like this shows up on top of anuptrend it is a warning signal: a strong drop could be soon to come.

We added a new ingredient to the “market reading recipe”: the specific positionof the candle within the trend.

Candlestick charts

Page 101: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

101

101

Candlestick charts

Long upper shadow, short body; on topof an up trend it is quite a dangerous

signal; indeed, such candles arereferred to as hanging men

Page 102: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

102

102

Exhaustion candles can show up also in the opposite way, see slide 103, where a

circled candle shows how a strong supply pushed down the price for some timeduritng the day, till demand became much stronger, and pushed back up theprice. When candles like this show up on the bottom of a downtrend they mean anew uptrend could be at stake.

The reading of the candlestick chart, indeed, is much more complex than it mightappear from this few slides, since the interpretation of each candle and group ofcandles depends also on the picture of the market they belong to.

The fact is that candlestick on their own are often meaningless and they do notallow to take investing decisions given of a high reliability: we need to integrate

them with other indicators.

In any case we have always to remember that our trading technique needs to beeffective in probability: being succesful 60-65% of the time is already a very good

result.

Candlestick charts

Page 103: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

103

103

Candlestick charts

Long lower shadow, short body;on the bottom of a downtrend it

means it is likely the time to buy.Such candles, no matter if black

or white, are called hammers

Page 104: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

104

104

One of the key factors in technical analysis is the degree of market participation

to some relevant event, such as the generation of important price tops orbottoms.

In the field of odds, patterns that come with a huge market participation should

be much more significant than those who come with a poor interest from investors:indeed, the wider the masses of investors attracted by an event, the morepowerful the effect of their behaviours.

A good measure of the market interest for an asset is the number of shares (orcontracts, in the derivatives field) traded at some time in respect with the total numberof outstanding shares (or the average number of traded contracts).

Key reversal patterns, such as a hammer or a hanging man, a price top or bottom, the

golden or devil crossing of a long term average, coming with a traded volume equal tosome percent point of the total market capitalization of that stock, or with a number of

traded shares much higher than the daily average, are all facts to be kept in very highconsideration.

Generally speaking, the higher the traded value (number of shares or contracts

times their price), the stronger the power of a buy or a sell signal.

Traded volumes and values

Page 105: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

105

105

Pros and cons of technical analysis and quant trading

Price charts allow traders to seek for repetitive patterns. They provide investors that

trading edge he needs to find in order to achieve systematic profits. It is perfectlyclear, though, that this result can be achieved only with a scientific approach,computer based. Knowledge of financial markets and products is the first rule, ofcourse.

The inventory of trading strategies is so wide that a whole lifetime would not besufficient to manually test them all. Indeed, systematic strategies can be based onjust prices, prices combined with price indicators, prices combined with non-price

indicators, time parameters only. A basic examples for each type:

• price based: buy on any new 20-days maximum, sell on any new 5-days

minimum;• price combined with some price indicator: buy on any golden cross betweenprice and 5-days moving average, sell on devil crosses;• price combined with some non-price indicator: buy any time the number of

stocks that closed in the green the previous day is higher than the number ofstocks that closed in the red; sell on the opposite signal;• time based: buy every Monday morning, sell every Wednesday evening.

Page 106: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

106

106

All the available indicators are included in trading platforms offered by banks and

brokers, and in any backtesting software. Historical data are sold by banks andother companies. They can also be downloaded for free (the upload to thesoftware for backtesting is manual, though); even open source spreadheets, suchas OpenOffice, can be used for the analysis.

There is no trading strategy that cannot be tested on historical data.

What we need is to know how to do the job: what to look for and how.

A very spread – wrong – idea among quant trading’s detractors is that quanttrading cannot work, because thanks to modern information technologies it is

possible to inspect so many indicators, parameters and tools that sooner or lateranyone can find something that works for sure; hence the trading edge cannotexist, since it could be available for anyone.

Their opinion is that results ahieved with a computer work only with paper money,not in the real world; this because the optimization of the parameters of theindicators leads to combinations so exasperated that they can work only in thepaper world.

Pros and cons of technical analysis and quant trading

Page 107: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

107

107

Indeed, in their reasoning there are two severe conceptual mistakes. The first is that the

number of indicators and tools available is so high that even with a super computer awhole lifetime would be not sufficient to test all the possible combinations; this means

you cannot shoot in the dark hoping to catch something. The second, even worse, isthat to use a computer in order to test all the possible combinations till we find a good

one is not quant trading.

Quant trading is not a quest for the holy grail. It is not the lunatic seek for the perfect

strategy. It is not about finding something that works at any cost, even if it is completelydetouched from the real world.

To do quant trading means to take a good idea coming out from market observation,experience and hard work, test it on historical data in order to give it statistical

consistency, and only in the end use the computer to better it, if it’s possible, tryingdifferent values of the parameters and filters on entries, to try and find the way to

discard in advance the worst ones.

This process goes under the name of optimization, and the trader needs to be verycareful about that. The risk of optimization is indeed to abuse of the computer in the

spasmodic search for the perfect strategy for any market.

Pros and cons of technical analysis and quant trading

Page 108: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

108

The correct optimization of parameters

A typical mistake many traders make is to look only at the net total profit of a strategy:

they set the values of the parameter(s) so to maximize the expected profit. What usuallyhappens is that maximum profits show up on isolated peaks.

Maximum profits often show up with values of the parameters that make huge profits,

but they are surrounded by other settings that produce much lower profits, or evenlosses:

Page 109: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

109

When a profitable range is surrounded by losing – or poorly gaining – ranges, then the

strategy is very dangerous: a minimum change in the market structure is enough tocrumble the sandy castle; the ideal situation is like the one on next picture:

With such a system we can just choose the value of the parameter(s) that lie in themiddle of the most profitable range: even if the market changes its structure the profit

doesn’t change significantly.

The correct optimization of parameters

Page 110: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

110

110

As Robert Pardo, the father of quant trading, teaches us, quant trading – when properly

pursued – provides five major advantages in respect to discretional trading: verification,quantification, consistency, objectivity, extensibility.

Verification: a coded trading strategy can be tested to prove its ability to gain over

time; what we first want to know is the profitability of the strategy in respect with the riskit exposes to. It is very hard to keep investing with a strategy without knowing whether it

really works or not; we also want to know on which markets the strategy can performbetter, in which market phases (it’s better to stay away from strategies that work only in

bull markets, for instance) and in which time periods (it’s also better to stay away fromstrategies that perform well only over a few time periods, and bad in all the others, even

if the overall result is positive).

Quantification: the judgement about the validity of a trading strategy goes through thevaluation of several parameters; risk-weighted return above all, but not just it. A trading

system that gains a lot of money exposing the investor to an unbearable risk is not agood trading system. Moreover, the risk-weighted return is the only yardstick for the

comparison between different trading strategies and vehicles. Average trade, numberof profitable trades Vs losing ones, average gain on positive trades Vs average loss on

negative ones, profit factor (total gains divided by absolute value of total losses),highest number of positive and negative trades in a row, worst historical loss, are only

some of the key-parameters for the correct evaluation of a trading strategy. How muchmoney we need to have on the account to be able to follow the strategy, even after a

very bad moment (this is about money management, see forward).

Pros and cons of technical analysis and quant trading

Page 111: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

111

111

Consistency: the basis of quant trading is the application of the same trading rules any

time a specific set of conditions shows up. Signals to buy and sell, position sizing, riskmanaging, profit managing: everything has to follow a preconditioned logic

Objectivity: a coded trading rule is not influenced by human emotions. Fear and greed,

lack of confidence, hope, delusion. An automated strategy just follows rules.

Extensibility: a human trader cannot follow too many markets and timeframes. A set ofautomated trading systems can follow all the markets in the world, 24/7. The only limit is

in the computational power of the computer.

Pros and cons of technical analysis and quant trading

Page 112: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

112

112

How to read a system report (a short outline)

Previously we commented two parameters on the following system report: % gain

and optimized pace of the average.

There are three other key parameters in that report for the evaluation of theeffectiveness of a strategy: the number of historical trades (4th column), the numberof profitable and losing trades (5th) and the ratio between the average win andthe average loss (6th).

Page 113: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

113

113

Net profit and net percent profit: are the two parameters unexperienced investors

usually look for at first. Indeed they point out how much they can gain. Keeping just thisinformation and discarding all the other can be a serious mistake; the first issue is that

together with a profit it always comes a risk. Not knowing how much that risk is can leadto several problems. As it does not knowing how long negative series (losing trades in a

row) can be, how much the strategy could lose before drawing a new equitymaximum, and so on.

As we’ll see forward, in the evaluations of a trading strategy it is not just a matter of the

first and the last point of the equity line (how much money I have in the beginning, howmuch money I could have after a while): what mostly matters is what’s in between. That

is what tells us whether we will be able to keep following the strategy even through thehardest times or not; in other words, that line informs us how much “pain” we have to be

prepared to stand to have the opportunity to reach some final expected result.

Number of trades: this is one of the most important parameters. Since, in fact, in the fieldof systematic trading it is all just a matter of odds, the higher the number of historical

trades, the higher the significance of the results, and the likelyhood of expected futuregains. Looking back to the system report we can state that to use the 8-days moving

average provides the best cumulated gain, with 46 recurrencies, while the 6-days MAprovides an expected lower return (still good) with 71 recurrencies: much more

significant. The likelihood to achieve in the future results in line with those achieved inthe past is greater in the second case. Some author suggest not to trust trading

strategies having less than 200 recurrencies on past data…

How to read a system report (a short outline)

Page 114: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

114

114

Number of winning Vs losing trades: what we’ve seen so far still is not enough to take a

decision, since, as we can see in the next column, the 8-days moving average provides20 winning trades, out of 46 in total, and 26 losing, while the 6-days MA provides 28

winners and 43 losers. Do you think you can easily invest money knowing you are goingto lose almost six times out of ten? If you can’t stand a strategy that loses 60% of the

time, then discard the 6-days MA, no matter its higher statistical significance! And, bythe way, how can such a strategy be profitable in the end? The answer comes from the

next column.

Average win on average loss: even a strategy that wins only 40% of the time can beprofitable in the long term, since it all depends on how well it performs when it gains in

respect with how bad it performs when it loses. Specificly, with the 8-days movingaverage the strategy gains only 43.5% of the time, but, when it does, it gains 3.15 times –

on average – what it loses when it loses. This makes the strategy profitable in the longterm. The 6-days MA performs a little worse, but still very good.

There are other parameters that come into play, of course, and to decide whether a

strategy can be tradable for us is a long and complex process. Two other keyparameters are the shape of the equity line (see forward, in the section about money

management) and the worst historical dip in the equity line itself, alias maximumhistorical drawdown; these two variables can give answer to one of the main concerns

we previously spoke about: what’s in between the first and last point of the equity line?

How to read a system report (a short outline)

Page 115: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

115

Step 3: modern trading techniques

Thomas De Mark, TDLines and TDPoints

In the middle of the ’80 of the last century, the famous american trader Thomas De

Mark made deep studies about trendlines.

In his famous book “The new science of technical analysis” he tells that at some point inhis career he was studying trendlines day and night with his business partner. Every day,

after work, he used to print charts on paper, bring them home and draw trendlines onthem using a ruler and a pencil. His partner did the same on his own.

The morning after they confronted the charts and they figured out that they had drawn

different trendlines on the same charts: they did not agree in the reading of the samecharts!

De Mark was really frustrated by this situation and decided to try and find a way to

codify trendlines in a unique way. What he found out is that if we look at a chart left toright there are several trendlines that can be drawn, because it all depends on the

starting point and the points the observer considers significant.

But the truth is that the latest information should be more important than the oldest one,and this means we have to read charts right to left!

Doing that, starting from the present day and going back, sooner or later we will find a

relative minimum and a relative maximum. Then, depending on the trend we can find asecond minimum or a second maximum, that joined with the first one generate a

trendline.

Page 116: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

116

Step 3: modern trading techniques

Thomas De Mark, TDLines and TDPoints

And that trendline is unique: it’s the only one that can be drawn on the chart in that

specific moment. That is the only trendline that matters.

But in order to achieve that result we first need to specify how we can find the points tobe linked with the TDLine.

In the interpretation of De Mark, a maximum is of some importance only when it is

surrounded by two lower maximums, one to the left, one to the right (we need threebars, then to identify it); similarly, a minimum is of some importance only when it is

surrounded by two higher minimums, one to the left, one to the right. De Mark callsthese points TDPoints.

TDPoints can be of several magnitudes: a magnitude 3 maximum, for instance, is a

maximum surrounded by six lower maximums: three to the left, three to the right. Thehigher the magnitude, the higher the importance of maximums and minimums.

The next step to take in order to find the correct trendlines is to understand what we

have to look for in any specific situation.

Let’s look at the chart on next slide, referred to the stock A2A, weekly bars, summer2014.

Page 117: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

117

Step 3: modern trading techniques

Thomas De Mark, TDLines and TDPoints

Page 118: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

118

Step 3: modern trading techniques

Thomas De Mark, TDLines and TDPoints

As we can see on the chart, the stock is in a negative trend. Remember what previously

stated? When the trend is going down the only trendline that matters is the resistance.

In order to find a trendline we need two maximums, and the one to the left has to behigher than the one to the right, so that the resistance is descending.

Starting from the last bar to the right and moving left we find a maximum first: the

circled one to the right.

Going left a few bars we then find a minimum (circled as well), that will help in definingthe target of the trade (see forward). Going left again we reach a new maximum,

higher than the first one. We found the resistance we were looking for!

That is the only trendline that matters in this trend phase. Now the question is: what dowe make of this trendline?

De Mark says that when the price breaks out the resistance line (there are specific rules

for intraday and end of day breakouts, but they are not important here) the priceshould change its direction, and it shoud also reach a specific target price (see

forward).

In order to define the target of the new up trend we need some more information. First,we need to determine the exact slope of the trendline, which serves two different

objectives.

Page 119: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

119

Step 3: modern trading techniques

Thomas De Mark, TDLines and TDPoints

This is quite easy: we take the distance between the two maximums and we divide it by

the number of bars between them (it’s the logic of the equation of the line linking twopoints).

This leads us to the average drop between the two maximums day after day: the slope

of the line.

And it also allows us to precisely determine the value of the trendline every single dayafter the second maximum; this means that no matter the day of the breakout we can

calculate the exact value of the breakout, which is the second important element forthe calculation of the target price of the new up trend.

De Mark defines then three possible targets for the trends originated by a breakout:

1. we take the vertical distance between the lower low underneath the TDLine (the

circled one on the chart) and the TDLine and we add that distance to the point ofbreakout;

2. we take the vertical distance between the close of the day of the lower lowunderneath the TDLine (the close of the day of the circled minimum) and the TDLine

and we add that distance to the point of breakout;3. we take the vertical distance between the lower close underneath the TDLine (the

day after the lower low in the chart considered) and the TDLine and we add it to thepoint of breakout.

Let’s look at some charts and try to apply this technique to them.

Page 120: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

120

Step 3: trend indicators; the stochastic oscillator

The stochastic oscillator is an indicator that can be used to point out the strenght of a

trend; it compares the distance between the closing price and the minimum of anumber n of days to the range (the distance between minimum and maximum) of the

same number n of days, on a percentual basis:

Stochastic = 100 * [(Close - MINn) / (MAXn - MINn)]

MINn and MAXn are the lowest minimum and the highest maximum of the n days. Thevalue of this indicator moves then between 0 and 100.

The premise is that in strong uptrends the daily close price is expected to be close to the

daily maximum, then the stochastic is expected to be high; vice-versa in strongdowntrends.

When the stochastic reaches specific thresholds, usually 20 on the downside and 80 on

the upside, then we can say that the stock we are looking at is oversold (very weak) oroverbought (very strong).

A first point of attention, then is when the oscillator reaches the bands of overbought or

oversold and then gets out (back down or back up respectively): it means that theexcess is ceasing.

The stochastic is often combined with its moving average to improve the effectiveness

of the trading signals.

Page 121: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

121

Step 3: trend indicators; the stochastic oscillator

Usually investors use these situations to buy or sell, but they make a mistake because

they are misinterpreting the indicator: the stochastic is a signal of strenght; when itsvalues are very high and at some point they reduce it doesn’t mean the trend is

changing: it just means it is taking a break, that could be only a short pause before anew explosion.

A very good use of the stochastic oscillator can be found in the book “Vivere di

mercati” by Paola Gentili, one of the very few italian very successful women in thisbusiness.

According to Paola’s studies, the return of the stochastic out of the excess bands is not

sufficient to open positions; Paola puts on her charts a stochastic oscillator and threeexponential moving averages. The parameters are always the same, no matter the

stock or the timeframe.

What Paola found out is that given the three following conditions:

1. the stochastic gets out of an overbought situation (it crosses 20 from below toabove);

2. the three moving averages are sorted coherently with their paces;3. the price crosses the first moving average;

Then the price usually moves right away to the second moving average; and if it crosses

the second moving average it moves to the third.

Page 122: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

122

Step 3: the relative strenght

One of the most interesting use of charts is to compare different assets in pairs so to

inspect which of the two is stronger in terms of its trend. For example we can make theratio between the prices of two assets at some ideal starting point, and then keep

calculating the ratio day after day, so to determine which of the two assets is strongerthan the other one.

Moreover it is possible to compare the performance of a stock to that of the index it

belongs to, so to see whether that stock is performing like the market, over the marketor under the market.

At the same time we can compare qualitatively indexes of several countries in the

world, to underline the differences in terms of strenght and expectations about thefuture development.

It’s interesting, for example, to examine the different relative strenghts between the

main european and the main american indexes; it is also interesting to look at thedifferences, in terms of performances, between the italian market and the french, or

the german one.

What comes out of this kind of comparison is that there are countries that are alreadyvirtually out of the crisis, and other countries still embroiled in it.

One important note, though: not all the indexes are calculated in the same way, so

comparisons between different markets require some kind of attention to the specificcalculation methods.

Page 123: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

123

Step 3: the wolfe wave

The wolfe wave is a pattern that shows up not very frequently on the markets, but when

it does it offers very interesting investing opportunities.

Let’s see how it works. First, it is a pattern that usually takes several bars to becompleted, since it is made of four key-points: two maximums and two minimums. Three

of them (points 2, 3 and 4) are very important maximums and minimums. Let’s see thetypical shape of the wolfe wave and then we’ll comment it:

Page 124: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

124

Step 3: the wolfe wave

First, the wolfe wave is a pattern that must show up as a secondary trend in a primary

trend; in simple words, the master treend has to be in a clear direction, and the wolfewave has to show up in a correction phase (down in un uptrend, up in a downtrend).

In this case the master trend is up and the WW shows up in a downtrend of a lower

magnitude.

The first point we need is number 2, then 3 and 4. Then we link 2 and 4 with a line, thenwe seek for a minimum 1 so that the lines 1-3 and 2-4 come together at some point in

the future.

Then the market has to make a false breakdown of the line1-3, point 5 on the chart,followed by a bounce that leads the price to cross the maximum of the bar that

marked point number 5. There we buy.

Target price? The line 1-4! The longer it takes… the better it is!

Page 125: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

125

Step 3: Bollinger Bands

Invented by the famous american trader John Bollinger, the Bollinger Bands are a price

channel used to provide a visual measure of the volatility of an asset.

Starting from the moving average of the closing price over some number of days(usually 20), subtracting and adding to it the standard deviation of daily returns over the

same number of days of the moving average, multiplied by a factor (usually 2), a pricechannel is obtained.

The width of the bands is a function of the historical volatility of returns. Assuming that

the expected future volatility will be in line with the past one, the Bollinger Bandsprovide an expected range for the next price movement.

Some use the BB to spot extreme price movements: when the price touches one of the

bands it means a strong movement took place and a correction should come soon.This theory is based on the assumption that the price should be mean reverting, which is

not.

Drawbacks: the Bollinger Bands are based on two parameters that can be optimized(the pace of the calculation and the multiplier). Changes in one or both can make the

bands change significantly, giving a completely different reading of the pricemovement. Moreover, the forecasting power of the bands is very limited, since they

can change both in terms of the average and the volatility. Still, all the days concurringto the calculation are equally weighted: a shock happened 20 days ago is weighted as

it happened yesterday. And finally, as we’ll see, risk is not symmetrical in the financialmarkets as the BB assume it to be.

Page 126: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

126

Step 3: Bollinger Bands

Bollinger Bands 20-2

Page 127: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

127

Step 3: ADX oscillator

Some of the oscillator available in the trading platforms are designed to provide a

measure of the strenght of the price of an asset.

The ADX is designed to split this information into two components: strenght andpredominant direction.

On a specific time basis (usually 14 days), indeed, it is made of three lines; one points

out a value between 0 and 100 pointing out the strenght of the price movement; andtwo others pointing out which direction of the price is prevailing.

The calculation of this oscillator is quite long, since it requires a lot of components to be

combined all together in a logic sequence. By the way, it is more important to see itapplied to a chart in order to understand its use.

The chart on next slide is referred to the stock Eni. The ADX is also plotted, on a 14-days

basis. The black line is the ADX, the green line is the positive directional index, the redline is the negative directional index.

Readings of 30 or more of the ADX point out a very strong price movement. The two

directional components then point out the prevailing direction.

Page 128: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

128

Step 3: ADX oscillator

Page 129: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

129

Step 4: risk management

Once we got access to the market, defined our approach to the market and chosen

the way to analyze data and charts we still have many choices to take in order toinvest money correctly.

Now let’s assume our set of rules is telling us to buy the stock ABC; now we have three

main problems that have to be solved all together (we can’t solve one withoutconsidering also the other two at the same time): how much money to invest, how

much we can tolerate to lose if things go wrong, where it should be reasonable to getout.

Here we start from risk management, but nothing prevents us to start from any of the

other two.

Risk management in a few words: do you have a plan B? what will you do if it turns out

you’re wrong?

Believe it or not, in cold blood it’s very easy to tell what you should do when things go

wrong, but when you are looking at the chart of a stock you bought and the price isfalling it is much more complicated; on one side we are aware that the price could

drop even more, but on the other side our brain is programmed to be optimistic, hencethe signals it sends us are to keep positions waiting for a bounce. The problem is that the

bounce could be late, or never come.

Page 130: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

130

Step 4: risk management

The problem is mainly psychological, but also mathematical: it originates from the

incapability of many people to account for the rule of the financial ruin: the path to

recover a loss is much longer than the path to make it.

Indeed, to recover a 10% loss it takes a 11.1% gain! To recover a -20% it takes a +25%...

To recover a -50% it takes a +100%. To recover a -99% it takes a +9900%!!!

The higher the loss, the harder the recovery process.

Always keep in mind the relationship between profits and time: for a 100% gain youneed a long time, and a long time exposes yourself to the risk of huge losses; it might

happen, then, that in the meantime you wait to recover a loss you get a higher loss.

A very good trader usually can gain a 2-3% a month (as the algebric sum of profits andlosses) on his whole available capital.

To let a single trade lose a 50% means to erase in one single shot the good job of weeks,

or event months.

The bottom line is that losses have to be managed.

Page 131: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

131We cannot deal with the risk of an investment without any plan B, because it is

statistically impossible for trades to be always profitable.

There is only one way to manage losses: set a threshold (defined by us, in advance, andon the basis of some criterion statistically efficient) we are not willing to overpass; and if

the price reaches it, then we get out.

Losses have two faces: the first is monetary, the second is psychological; lossesdemoralize us, take away our confidence in ourselves and in our strategies. The higher

the loss, the worse the effect.

In the exact moment we open a trade we need to have clear in mind the plan B. It iscalled stop loss, because it is made to limit losses when things do not go as we

expected.

We can re-emerge from a 10% loss; if it’s just a 5% it is even better. But we cannot re-emerge from a 99% loss.

Many of the main experts in the world suggest not to put at risk more than a 2% of our

capital per trade…

Step 4: risk management

Page 132: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

132Americans have a famous proverb: “if it’s not broken, don’t fix it”. In finance this doesn’t

apply: sooner or later we have to get out from a trade, and once again, when and whyis a decision that cannot be left to chances.

It might sound odd, but it often happens that to properly manage profits is even harder

than to properly manage losses.

And again, the problem is psychological: most of the time we tend to settle for a profitthat seems to be sufficient, just to be sure to have something in our pocket; if tomorrow

the price keeps moving up it doesn’t matter.

The idea is that it is better an egg today than a chicken tomorrow, because the eggtoday is sure, the chicken tomorrow is not.

The common denominator for investors who settle for the egg today is “what if

tomorrow the price drops?”

Actually the problem is usually of a different nature: they have no idea about theeffectiveness of their strategies.

Step 5: profit management

Page 133: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

133Without a test of a strategy it is not possible to form expectations in terms of its potential

profits. How can we tell it’s better to get out of a trade after a 5% profit or a 10% profit, ifwe do not test the two alternatives? These information can come only from a backtest

of the strategy, made on a data series long enough to give the system a statisticalconsistence and significance.

It is all a matter of coding a strategy so to be able to simulate its behaviour on past

data, combining it with an exit strategy of some sort.

For instance, buy when the price crosses from below to above its 5-days movingaverage, sell when the price reaches a new 20-days maximum.

How much money can be made with this strategy? How much risk does it expose us to?

Only a backtest can give answer to this question.

One of the most popular proverbs in the field of trading is “cut losses and let profits run”.When do we have to cut losses (plan B)? Till when do we have to let profits run? Only a

backtest can answer these questions.

Step 5: profit management

Page 134: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

134Money management is by far the most important issue in the management of an

investment, and still one of the most ignored by private investors.

The problem here is to try and find the best allocation of capital among all theavailable investment vehicles. Here another famous american proverb can help: “do

not put all your eggs in the same basket”. Because if the basket falls down, all the eggsbreak at the same time.

Talking about investments, the invitation is to not put all your money on a single

instrument, but to split it into several.

If we have a million to invest, instead of buying one million euro of a single stock maybeit would be better to buy a quarter of a million of government bonds, a quarter of a

million of corporate bonds, and invest the remainder half a million in shares. And aboutthe last half a million, maybe a hundred thousand in the stock 1, another hundred in the

stock 2, and so on.

Doing this we create a portfolio of instruments given of some degree of expected riskand some expectation in terms of return. It’s the process known as diversification.

Step 6: money management

Page 135: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

135 The idea is that a single company could go bankrupt: it’s a matter of specific risk, that

is, the risk that a specific company fails; if all my money is invested in that company…disaster!

Generally speaking, the probability of bankruptcy of a listed company is very low, but

the probability of the simultaneous bankruptcy of twenty listed companies is zero; that isthe reason why it is better to diversify: because the probability of a combination of

multiple unfavourable events all at the same time is not conceivable. The bestdiversification (under passive management, to be stringent) is given by the whole

market: it can be proven mathematically that the risk of the whole market – systematicrisk – is the least risk we can reach thanks to diversification.

Apart from the worst case scenario (bankruptcy), the probability for a single company

to see a dramatic drop in price is much higher than the probability for that to happenon ten stocks at the same time, unless something very bad happens on the whole

market (think of the twin tower attacks in the year 2001, or the bankruptcy of LehmanBrothers in 2008).

Let’s look back to the idea of the diversification seen on previous slide. An investor with

a low inclination to risk could object that a half of the capital on stocks is too risky, andthat it would be much better to invest half a million in government bonds, 300k in

corporate bonds, and only 200k in stocks. The point is that there is not a better choiceno matter what, because it all depends on the personal inclination to risk of the investor.

Remember what previously stated: it is all just about risk and return.

Step 6: money management

Page 136: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

136Let’s go back to the nature of the problem: the best allocation of capital. When the

investor has decided how much capital has to be allocated to the stock market, thereis still a problem to face: how much capital on each stock?

Let’s consider a simple case: we have one hundred thousand euro to invest in stocks;

suppose we have a systematic trading strategy that tells us every day what to buy andsell. Today the strategy tells us to buy Eni, Telecom Italia, Fiat and Unicredit. How much

money do we invest in each?

Here we have basicly two issues: theoretically speaking, in the moment we open thetrades all of them have the same risk, since nobody can tell us today which of them will

return a gain and which a loss.

As a consequence, at least theoretically we should invest the same money amount oneach. This is a fixed capital money management: same money in any trade.

The second issue is: what money amount in each trade? 25000?

It sounds reasonable, at a first sight, but what if tomorrow the system tells us to buy

Banca Intesa? We do not have money!

What if all the first four trades are loosers and Banca Intesa was the only one profitable?

Step 6: money management

Page 137: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

137To get out of this problem we need to know the maximum number of simultaneaous

trades the system would have taken in the past, and assume that history could repeatitself in the future.

Now suppose, that our system opened at most ten trades simultaneously in the past.

Can we then invest ten thousand euro per trade? Unfortunately it could not be thecorrect value. First objection: what if from now on one day the system tells us to buy

eleven stocks? The future should be similar to the past, not identical!

Second problem: imagine that today the system tells us to open ten trades; the wholecapital is invested.

Imagine, then, that tomorrow all trades are closed, with a net global negative result

(the algebric sum of profits and losses), let’s say -10000 euro.

Now the available equity is 90000. Tomorrow the system tells us again to buy ten stocks:we cannot invest 10000 each anymore, because we don’t have enough money. So we

have to invest at most 9000 each. A system born as fixed capital became fixedfractional: in each new trade we invest the same fraction (a 10% here) of the available

equity.

Step 6: money management

Page 138: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

138This may not be a problem: sometimes the fixed fractional method produces better

results than the fixed amount one. But that is not the point.

The point is that depending on the choices we take in terms of money managementchange the results of our trading, since to gain or lose a specific percentage on 90000

euro is not the same than to gain or lose the same percentage on 100000 euro.

Unfortunately, things are much more complicated than that, and it’s time tounderstand why money management, risk management and profit management are

so linked together.

How much we gain or lose in a single trade depends not only on the entry strategy

(what to buy and why), but also on the management of losses and profits.

This explains why to invest money is not as simple as many peope think. Because the

scientific test of the effectiveness of a strategy is strictly related to all the faces of theproblem, hence it depends on the entry strategy, but also on the stop loss and the take

profit policies and even on how we allocate capital among all the products.

Step 6: money management

Page 139: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

139Think of this: if any time you buy you set a 1% stop loss from the entry price, you know

that in any trade you put at risk a low money amount, but you can expect to bestopped out many times, because the stop loss level is too close to the entry point; vice-

versa, if you put a stop loss at a -10% from your entry point, then you can expect thatyou will be stopped quite rarely, but any time you get stopped you will lose a lot of

money.

Which one is the best? No one can tell without a test, because it depends on too manyvariables.

Now think of profits: if you set a 1% target profit, you will very likely gain most of the time,

but only a 1%; if you set a 10% target profit, you will gain rarely, but much more eachtime. Again, only a test can tell you which one is the best choice.

Step 6: money management

Page 140: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

140In order to make things clearer in terms of the impact of the management policy on the

financial result of a trading strategy, now I will show you the results of the application offour different techniques to the same strategy.

The strategy is the most simple one: crossings between the close price and a 20-days

moving average. The stock is Azimut, listed on Milan stock exchange. No stop loss nortake profit policies are applied: the system buys on a golden cross and sells on a devil

cross.

If we record all the trades that could have been made between January 2000 and theend of September 2013 in a table sorting them chronologically, reporting the profit or

loss of each and calculating the cumulated results, we can get to the equity line of thestrategy, that is, starting from the initial capital, what happens all the way long, till the

last day.

Since, in this case, entry, stop loss and profit management rules are always the same,the only thing that can change the results of the strategy is the way we use money.

About that, suppose to have an initial capital equal to 20k euro.

We’ll now see what happens applying the following different money managementpolicies: fixed capital, martingale, anti-martingale, fixed fractional.

Step 6: money management applied to stocks

Page 141: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

141Here how the four techniques work:

1. Fixed capital: for any new trading signal we invest always the same money amount,

10000 euro. Just a half of the available money because we need to keep a reserve ofmoney in case the first trades were negative. Here the equity line chart:

Step 6: money management applied to stocks

Page 142: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

1422. Martingale: on the first trade we invest 10000 euro; if the first trade is winning, on the

next one we invest a fixed percentage less (5% less in this case); vice-versa, if the firsttrade is losing, then on the next trade we invest a fixed percentage more (5% again).

And so on. The martingale comes from the field of gamblers, typically black jack

players. Equity line:

Step 6: money management applied to stocks

Page 143: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

1433. Anti-martingale: on the first trade we invest 10000 euro; if the first trade is losing, on

the next one we invest a fixed percentage less (5% less in this case); vice-versa, if thefirst trade is winning, then on the next rade we invest a fixed percentage more (5%

again). And so on. The anti-martingale comes from the idea that in trading each tradeis independent from the previous, and that usually positive and negative trades show

up in sequences. Equity line:

Step 6: money management applied to stocks

Page 144: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

1444. Fixed fractional: on any trade we invest always the same fraction of the available

money (20000 euro), the 50% in this case. On the first trade we then invest 10000. Thenbeing the first trade winning, the capital will increase. Assume to gain 1000 euro on the

first trade: the capital is now 21000, and it means that on the next trade we invest 10500(always a 50% of the available money); vice-versa if the first trade is losing. This policy

resembles an anti-martingale, and is just a capitalization of a half of previous profits orlosses. Equity line:

Step 6: money management applied to stocks

Page 145: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

145

Step 6: a full view on the four MM techniques

Fixed capital Martingale

Anti-martingale Fixed fractional

Page 146: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

146

Step 6: what equity lines are for

The equity line provides several key-parameters for the valuation of a trading strategy.

First, the maximum historical loss between two consecutive growing peaks of profit. Thatis the so calledmaximum drawdown, and is a first measure of risk of a strategy.

A paramount concept in trading is that it not only matters where you go, but moreover

how you get there. A strategy that brings exceptional profits exposing the trader tounbearable risks is not a good trading strategy.

In looking at an equity line chart, unexperienced investors usually just look at two points:

the first and the last. What’s in the middle is not their concern. And they make a hugemistake, because what happens in between is a measure of the capability of an

investor to stay still in front of events without intervening on the strategy even when itloses money.

Look back to the fixed fractional chart (previous slide, bottom right): it gains about

36000 euro (because from the final value, 56000, we have to cut the initial equity,20000), much more than any other money management policy. But it exposes the

trader to a risk to lose around 11000 euro, much more than any other trading strategy.How can we decide which technique is better? We have to compare them under the

same meter: the so called profit factor.

The profit factor is the fraction between the sum of all the gains of positive trades andthe sum of all the absolute values of the losses of negative trades. A value over 1.3-1.4

points out to a good trading strategy. The higher, the better, of course.

Page 147: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

147

Step 6: what equity lines are for

Moreover, the maximum drawdown gives not just a measure of the pain the investor

has to suffer to reach the final profit: it also tells him something about how long can hardtimes last.

Look back to the chart of the fixed fractional method. The maximum drawdown lasts

from the trade number 28 to the trade number 55, and till the trade 58 there are no newgains. Some investors cannot stand 30 trades in a row not bringing new cash on their

accounts. The equity line can then tell them whether the strategy might suit them or not.

And yet there is another issue to face: one of the main problems in the maximumdrawdown is that it makes many investors abandon their trading because they can’t

stand losses on the long term. Many money management experts suggest that inpassing from a simulated trading to a real time trading it would be better to allocate a

money amount equal to two times the maximum historical drawdown, so that globallosses do not incide too much on the investor’s capital and his capability to keep

investing with the strategy. This is also valid considering that the worst past case is notnecessarily worse than the future worst case: the future could bring losses higher than

the historical ones.

The problem is that the more money we allocate to the strategy, to feel morecomfortable, the lower is the return on the initial equity… It is again a problem of

equilibrium: we need to start with a capital sufficient to be not afraid of temporarylosses and to be able to keep trading after a hard time, but if we allocate to the

strategy too much money the return can be not sufficient to justify its use.

Page 148: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

148

Step 7: the choice of the instrument

Here a mere list of the instruments we can buy and sell either on our own or with the

help of a dealer:

• stocks• corporate bonds, convertible bonds, warrants

• government bonds• mutual investment funds, hedge funds

• ETFs, ETCs, ETNs (generally speaking, ETPs)• futures contracts

• option contracts• covered warrants

• certificates• binary options

• turbo contracts• contracts for difference (CFD)

• foreign currencies (Forex)

Whichever the strategy that we choose, knowing each asset class can lead tomaximize our gains, minimizing our risk. Knowledge of the available instruments is very

important.

Page 149: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

149

Step 7: the choice of the instrument

Let’s now assume we have a buy signal on the stock ABC. How do we follow it?

This might seem a trivial question, but it’s not. Indeed, till about 15 years ago we would

have had no other choice but to buy shares of ABC, paying their entire value onpurchase.

Today the world is different; first because to buy the stock ABC we can have several

different instruments (shares, certificates, CFDs, futures, options), each given of aspecific risk-reward profile, which we have to fully understand in order to take the best

decision; second, even if we decide to buy shares we don’t always have to pay theirwhole value, since the trade could be opened using only a fraction of its value.

The choice to take, then, is on two different levels: what instrument to use and whether

to use a financial leverage or not.

Page 150: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

150

Step 7: the leverage

The leverage is an artifice that provides interesting opportunities for many investors,

especially those given of a very small money amount to invest.

The idea is quite simple: given a 10000 euro capital and a 10:1 (ten to one) leverage,we can open positions for up to 100000 euro, ten times our money.

Think of a trade that restitutes a 10% profit on ten times the money we have: we double

our real money!

The problem is if things go the other way: a -10% on a capital 10 times bigger than myreal money… no more money! Unfortunately, the leverage works in both directions.

Many investors think that thanks to the leverage they can become traders with a small

money amount on their accounts. Unfortunately it is not possibile, and to prove that wejust need to look back to one of the equity lines seen on slide 145. Let’s focus on the

fixed amount: 10000 euro per trade.

Here somone could say: “i have a 10:1 leverage, so i dont’ need 10000 euro on theaccount, since 1000 are enough”. This is wrong, because the leverage can reduce the

need for capital per trade, but it doesn’t change the maximum drawdown of thestrategy, that is always 5000 euro and something. We cannot stand a 5000 euro loss with

only 1000 euro on our account!

Page 151: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

151

Step 7: the leverage

Moreover, many of the greatest experts in the world in the field of money management

suggest to put at risk not more than a 1-2% of our capital per trade.

Looking back to the equity lines on slide 145 we can make a rough estimate of theworst single loss ever seen: trade number 31 (fixed amount chart) loses about 1000 euro.

If the loss per trade has to be at most a 2% of the available money… then the money

available has to be 50000 euro! And it rises to 100000 if we put at risk only a 1% pertrade.

Given a 10:1 leverage we still need something between 5000 and 10000 euro to be

able to follow the strategy even in the bad times. If we double the maximumdrawdown as the esperts suggest, we need to double the available money as well.

Page 152: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

152

Step 7: costs of the leverage

Most of all, the leverage is not for free.

If we have 10000 euro on our account and we ask the bank to give us a 10:1 leverage

we are implicitly borrowing 90000 euro.

On the money lended the bank wants to be paid interests, which usually account forthe yearly market interest rate (very close to 0 today) plus 6-8 percentage points.

Let’s do some quick accounts: we buy 5000 shares of a stock quoting 20 euro per share,

for a total value of 100000 euro, using a 10:1 leverage; this means that 10000 euro areours, the rest is borrowed. On this 90000 euro borrowed the bank applies an average

yearly rate of interest equal to 7%. On a daily basis we then pay 90000*7%*1/365=17.26euro.

Keeping the trade opened three months we pay more than 1550 euro in interests!

Page 153: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

153

Step 7: short selling

Short selling (or just short), vendita allo scoperto in italian, is another artifice of the

modern financial creativity and is a way to “bet” on the downside, on a drop in theprice of an asset. It’s the opposite of the so called long trading (to buy under the

expectation of a growth).

Why could it be reasonable to invest on the downside? Another famous americanproverb states that the markets go up with stairs and down with the elevator: the

average speed of up moves is generally lower than the average speed of downmoves.

This comes from the market psychology: in downtrends investors tend to runaway

because they are afraid of remaining stuck in a losing trade, sometimes generating theso called panic selling; investors sell anything for any price just to be sure to get out,

often out of any logic.

An example above all: between march 2003 and may 2007 the italian stock index FTSEMib lived one of its best periods, raising from 20,324 to 44,363 points; about 24,000 points

in about 50 months. Then, from May 2007 to March 2009, because of the global crisistriggered by the sub-prime mortgages it dropped down to 12,332 points, about 32,000

less in 22 months. Less than a half time to lose much more in terms of value.

This is panic selling: stocks are sold for prices always lower, often way under their realvalue, just to convert a position in shares into a liquid account. “Cash is king!” say the

americans. No money, no good deals; better lose money today to have the money togain tomorrow.

Page 154: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

154

Step 7: short selling (of stocks)

The idea of the short selling is then to sell something at some price trying to buy it back

for a lower price after a while. But how does it work?

To sell short means to sell something we do not have. If the long buyer has to be afraidof price moves on the downside and gains from price moves on the upside, for the short

seller it’s the opposite: he has to be afraid of an up movement, and gains from a drop.

How can we sell something we do not have? Of course we have to borrow it: weborrow a stock, we sell it for a price, let’s say 10, so we get paid 10 per share. After a

while the price drops to 9, so we buy back the stock (buy to cover), pay 9, and werestitute it to its owner. The gain is 1 per share.

How is all of this possible? The market needs to define a set of rules to follow and to find

the way to manage all the process. This means that short selling is possible, but it costs.Indeed, usually banks ask for a fixed cost for the procedure (about 10 euro); then they

ask for an interest on the value of the position. This for a clear reason: in the moment wesell something that doesn’t belong to us we get paid money we don’t own. We could

take that money and use it for other investments, for example to buy a risk freegovernment bond. This would allow us to gain on money that doesn’t even belong to

us! The interest we pay on short selling are the same we pay on the leverage.

An important note: the costs of short selling apply only to stock or other assets that needto be borrowed to be sold short. For other assets – derivatives, for instance – short selling

is much easier.

Page 155: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

155

Step 7: short selling (of stocks)

Summing up, there are 4 different types of trades:

• to open a long: to buy something assuming its price will increase;• to sell: to sell to close a long;

• to sell short: to borrow and sell something assuming its price will drop;• to buy to cover: to buy to close a short.

A buyer can then be someone who buys out of the blue, opening a position that will

profit if the price increases, or someone who is closing a short position, to end it; a sellercan be someone who closes a long position to end it, or someone who is opening a

short position, to gain from a price drop.

In some peculiar situations short selling can be inhibited by the market authorities inorder to prevent too speculative behaviours in front of serious situations on the markets

(terroristic attacks, strong natural phenomena, shocks of some sort).

Blocks to short selling are justified when panic selling shows up, because in thesesituations short selling could seriuosly worsen the drop in the prices.

One last note: it might sound strange, but to short sell we need to have money on our

account as a proof that we will be able to pay in case of losses. This money is calledmargin and it is generally equal to a half of the value of the position. Moreover, the

money we collect from short selling cannot be used for other investments, since it isstuck in the so calledmargin account.

Page 156: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

156

Step 8: how to physically buy and sell

Now suppose that we have a full working trading system, which now is telling us to buy

the stock ABC only if the price crosses a specific threshold; the order has to beconsidered valid till today’s close, and if it is not executed at that time has to be

cancelled.

How can we do all of this?

We open our trading platform, look for the stock ABC, open its negotiation book (or justbook) and place the order.

What is the book? How can we put in place an order? Which parameters can be set?

Can we decide how long (in terms of time) make it be valid? Can we cancel it if wechange our mind? Modify it? Do we have to pay when we modify it? How can we

know if our order has been filled?

Basicly, then, we now have two issues to deal with: how to send orders to the marketsand what kind of orders we can send.

As previously stated, a trading day starts with an opening auction, then there is a

continuous phase and finally a closing auction.

The element in common in all the phases is the book. It’s an electronic table that showsall the buy and sell proposals sent to the markets from operators at some time. All the

proposals are collected by the systems of the stock exchange, grouped and sortedaccording to some rules, which we’ll see.

Page 157: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

157

Step 8: how to physically buy and sell

There are two important differences in the dynamics of the auctions and those of the

continuous phase; first, during the auction there are no trades until its end, while in thecontinuous there are very frequent trades (generally); this doesn’t mean there are no

movements in the auctions; to the contrary, proposals are sent, modified andcancelled continuously, as during the continuous phase, but nothing is traded till the

end of the auction. This means that in the auction phase operators can also send to themarkets orders to buy or sell for prices out of any logic, since there is no risk to be

executed.

Second, the prices of the orders sent during the auctions are not necessarily the pricesoperators are seriously willing to buy or sell, since the peculiar feature of the auctions is

that, at their end, anything can be traded is traded at the final price of the auction; thismeans that a buy order, if filled, is filled at the auction price, not at the price offered by

the buyer. At the same time, a sell order, if filled, will not be filled at the price asked bythe seller, but at the auction price. The key element here is that the auction price

cannot be detrimental in respect with the prices offered: who is executed is executedat a price equal or better than the one offered.

Puzzling? Don’t worry, everything will be clear soon!

Page 158: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

158

PART 2

HOW STOCKS ARE TRADED:

Negotiation book, opening and closing

auctions, orders, liquidity, risks, opportunities.

Page 159: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

159

The opening auction

The opening auction phase on the italian stock market lasts from 8 to 9 am and is

divided in three phases: pre-auction, validation, open.

A curious element is that the end of the acution is not set at a specific moment: ithappens randomly in any second of the minute from 9 to 9:00:59 am. This so called

random minute has been introduced to reduce the risk of market manipulationsoriented to conditionate the opening price. In order to understand this issue we first

need to see many other elements, most of all the books, and how they can be used tomanipulate the price (committing a phelony, by the way!).

Let’s go back to the pre-auction phase. Here the IT systems of the stock exchange

collect all the orders coming from the operators, group and sort them according tosome rules: all orders to buy or sell for the same price are grouped so to show a single

total quantity to buy or sell. Still, the system keeps a trace of the exact time of eachorder (we’ll see why very soon).

The system, then, shows a synthetic data in the book, but is always perfectly aware of

the maximum detail: for each order it keeps trace of the operator who sent it to themarket, the quantity offered or asked, and the precise time of appearance.

Page 160: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

160

Opening auction

If we open the auction book of any stock at any moment of the pre-auction phase and

we take a picture of it, it will be more or less like this:

As we can see, the book is a symmetrical table. On the left there is the bid, denaro in

italian, the buyers; on the right there is the ask, lettera in italian, the sellers.

Every level shows the cumulated quantity willing to be bought or sold for a specificprice. But, as previously stated, the system keeps a trace of all the exact moments the

single orders have been sent to the market (see the right side of the picture for anexample of a splitted level). This because as we’ll see the time priority here is

fundamental.

Buyers are sorted top to bottom in respect with the prices offered to buy: doing so, inthe first row there are the best buyers from the point of view of the sellers.

2000 8:01:34 a.m.

1000 8:02:15 a.m.

1000 8:05:52 a.m.

Page 161: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

161

Opening auction

Indeed, if you are willing to sell something (anything) in a market where all the buyers

are clearly visible and offer public prices, then you will sell to who is willing to pay more!

Here the best buyers are willing to pay 7.65 euro per share; but as previously stated thisis not necessarily the real price they are willing to pay: to the contrary, it happens that

they could offered such a high price (much higher than any other price in the book) just

to be reasonably sure to be in the first line of the book.

Why do they do so? Because the logic of the execution of orders at the end of the

acution, just like in the continuous phase and the closing auction, is first in, first out: who

comes first and offers a higher price has the right to be executed first.

Looking back to the book on previous slide, if after a while some new buyers come into

play offering 7.70 euro per share they become the new best buyers, overpassing theprevious ones and making all the lines in the bid side of the book to shift down one

position.

The only way to be sure not to be overpassed by anyone is to send an order to buy withno limits in price, that is, a so called market order, ordine al meglio in italian. To be

stringent, the definition of market order applies to the continuous phase; in the auctionsthis kind of order is called at auction price: the buyer will buy at the final price of the

auction, the seller will sell at the final price of the auction. These orders are always in thefirst line and in the price field there is a score. We will spend a lot of words on order types

forward.

Page 162: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

162

Opening auction

The difference between sending an order to buy at auction price or sending a buy

order for a high price, high enough to be in the first line of the book, is that in thesecond case we face the risk to be executed at most for the price we offered, in the

first we face the rislk to pay a price way higher then what we intended to do. It alldepends on how the auction ends.

Let’s take a step back. On the right hand side of the book there are the sellers, sorted

bottom to top in respect with the prices; doing so, in the first line there are the bestsellers from the point of view of the buyers: imagine to be at a public fair where all the

merchants sell the same good, cleraly showing their prices; you will go buy from themerchant asking for the lowest price!

On the first line of the book we have then the best buyers and the best sellers, then in

the second line there are the second best buyers and the second best sellers, and soon. The standard book shows five lines, but today books with a deeper view on the

markets are available (up to 20 levels).

Time to see how the auction works.

Buy and sell proposals are sent, modified and cancelled all the time, and the system updates in real time the price that would be the opening price if the auction closed in

that exact moment: that is the so called theoretical opening price.

Page 163: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

163

Opening auction

Here we may begin to understand how the auction book can be used to manipulate

the opening price if there were no market procedures to try and prevent it: each new,modified or cancelled order impacts on the real time theoretical opening price.

But at some time – in the random minute (see previous slides) - orders become

definitive: who’s in is in, who’s out is out. No more apportunities to change or cancelorders or to send new ones. And if we cannot tell when the auction will end it can be

very risky to try and manipulate the market with fake orders, because a fake order senta fraction of a second before the closing of the auction becomes a real order!

We will see a fully detailed attempt of market manipulation forward.

At any time during the auction the systems calculate the theoretical opening price

applying four basic rules sequentially:

1. the opening price is the price that maximizes the tradable quantity;2. if two or more prices maximize the tradable quantity, then the opening price is the

price that minimizes the so called imbalance: what is left out;3. if two or more prices maximize the tradable quantity and minimize the imbalance,

then the opening price is the one closest to the previous day’s close, here calledcontrol price;

4. if two (here there cannot be more than two) different prices maximize the tradablequantity, minimize the imbalance and are at the same distance from the previous day’s

close, then the theoretical opening autcion price is the highest of the two.

Page 164: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

164

Opening auction

The four rules are sequential, meaning that each one after the first has to be applied

only if the previous one couldn’t lead to a single opening price. With the fourth rule it ismathematically impossibile not to come to an opening price.

And still it is a theoretical opening autcion price, since to become the opening price it

has to pass a final test: the validation (see forward).

How does the system determine the theoretical opening price according to all theproposals in the book? To answer that we need to look at the book from a different

perspective, rearranging data in a different way. First we build a new table, made offive columns.

In the first column we place all the prices that appear in the book – only the visible ones

– sorted bottom to top.

In the second column we place the quantity that can be filled for each of the prices incolumn one on the side of the buyers; in the third column we do the same on the side

of the sellers; then we compare the quantities that can be filled on both sides (fourthcolumn).

The fifth column is for the imbalance, that is needed if we have to procede to the

second tule to find the theoretical opening price. We can leave it blank, for now. Lookat the picture on next slide.

Page 165: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

165

Opening auction

Where do the quantities in the picture above come from? Any buyer that comes into

play usually has a clear idea about the limit price he his willing to pay; this limit, though,applies only on the upside: it’s a lower or at most equal condition; “i don’t want to

spend more than X”. But if we can have what we want paying for it a price lower thanthe one we thought… much better!

Since the most conservative buyers here are offering 7.37 per share, any price equal orlower than 7.37 will suit them, like anyone else who initially offered any other price

higher than that; in other words, each price equal or lower than 7.37 suits all the buyersthat appear in the book, hence the quantity that can be bought is the sum of all the

quantities on the bid side of the book, 16,000 shares in total.

Page 166: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

166

Opening auction

If the price increases to 7.38 all the quantities asked for any price equal or higher than

that can still be filled, but who was willing to pay 7.37 will be cut out: that’s why only11,000 shares can be filled this time.

If the price moves up to 7,40 the buyers offering 7.38 are cut out, and the quantity that

can be traded drops to 8,500 shares; and so on, goinig up with the prices till the highestone, 7.65, for which only 1,000 shares can be traded.

Now let’s reverse the reasoning, and see what happens on the sellers’ side.

Who’s willing to sell for 7.24 euro per share will never sell for any price lower than that,

but could be very glad to sell for any higher price, if possible; that’s the reason why onthe ask side the tradable quantities increase together with the prices: for 7.24 can be

sold 4,000 shares, for 7.32 we catch also the second best sellers and the quantity raisesto 6,800, for 7.42 it’s 8,000, and so on, up to 17,500 shares for any price equal or higher

than 7.46.

Now let’s move by rows. For the price 7.24 there are buyers willing to buy up to 16,000shares and sellers willing to sell at most 4,000: that is the maximum tradable quantity for

that price. Generally speaking, the tradable quantity in each row is the minimumbetween the two quantities on the bid and ask sides.

For 7.32, then, we still have 16,000 shares on the bid side, 6,800 on the ask side, then the

tradabel quantity is 6,800. And so on. The result is shown in slide 169.

Page 167: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

167

Opening auction

Now the system is able to check whether the first rule is enough for the determination of

a theoretical opening auction price. Unfortunately there are four different prices thatsatisfy the first rule: 7.32, 7.37, 7.38, 7.40.

We need to try the second rule, then: among only those four prices we look for a unique

price – if it exists – that minimizes the untradable one, the imbalance.

The imbalance is simply the absolute value of the difference between the bid and theask quantities: that is, indeed, what remains out after the tradable quantity has been

traded. The following picture shows the imbalances for the four prices that came outfrom the first rule.

Page 168: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

168

Opening auction

As we can see in the picture on previous slide, 7.40 maximizes the tradable quantity and

minimizes the imbalance at the same time: that is the theoretical opening price here.

This is how it works on any listed stock: each stock has its own book and its own openingauction, that works this way. Once the theoretical opening price is calculated there is a

final test that has to be passed: validation. The opening price has to be within a plus orminus 10% (5% in some cases) from the previous day’s close; if it’s out of that range

another auction takes place (see forward).

Now let’s see another example, that requires to go on till the fourth rule. Suppose thebook at the end of the auction is the following:

Page 169: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

169

Opening auction

Neither the best buyers, nor the best sellers specified a price, and that’s why in the first

line there are two scores. Let’s see what happens applying rules number one and two:

Both 8.40 and 8.42 maximize the tradable quantity and minimize the imbalance, hence

we have to move on to rule number three: the opening price is the one closest toprevious day’s close. Imagine that price is 8.41. The two prices are at the same distance

from it, then we need to move on to the fourth rule: the opening price is the highest ofthe two, 8.42.

This price passes also the validation phase, since it is set just a cent from the control

price.

In case the price didn’t pass the validation phase, a so called volatility auction wouldtake place. It follows the same rules of the standard auction, but lasts less; it is also

repeated until the market comes to a price inside the range set by the stock exchange.

Page 170: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

170

Opening auction

In limit situations the stock exchange can decide to enlarge the range for the

validation. This happens when extreme price movement during the auctions do notcome out from speculative pressures but from specific market events. Look, for

instance, at the chart of Saipem during the year 2013!

Page 171: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

171

Opening auction

Immediately after the end of the opening auction the continuous phase takes place,

and the book moves onto the next phase showing what remained out at the end of theauction. Indeed, at the end of the auction all the trades that can be made are made,

all at the same price: the opening price.

Let’s go back to the example on slides 169-170. The opening price is 8.42 and it makespossible to trade 3,000 shares.

In order to understand how the book remains after the auction we have to go back to

the original one and cancel one by one all the trades that can be made, starting fromthe first line and going down till we reach 3,000 shares. On the bid side, then, we take

away the 400 shares for the opening auction price, then the 600 for 8.64, then the 800for 8.43, and finally the 1,200 for 8.42. All these shares are traded for 8.42 euro each. The

last ones are then those who are paid exactly the price offered; in all other cases thefinal price is better than the one initially offered.

What is left out is only the 1,200 shares for 8.40 euro each, that are transferred entirely to

the continuous phase as they are.

On the sellers’ side we take away the first 400 shares for the opening auction price, thenthe 600 for 8.24 and the 1,200 for 8.40; and again all these shares are sold for 8.42. Look

what is left out: the 1,200 shares for 8.42, the exact opening auction price. How odd!Indeed it happens… And it happens because those buyers come after those willing to

sell for something less. The last line of the ask side is then transferred to the continuousphase as it is.

Page 172: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

172

Exercises on opening auctionsGiven the following opening auction book

Find the opening auction price and draw the resulting book after the auction.

Given the following opening auction book

Find the opening auction price and draw the resulting book after the auction.

BID Q BID P ASK P ASK Q

1000 - 9.50 200

500 9.70 9.60 400

700 9.60 9.80 600

1300 9.50

BID Q BID P ASK P ASK Q

1000 8.45 - 450

200 8.44 8.43 750

700 8.43 8.44 600

1000 8.42 8.45 200

Page 173: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

173

Exercises on opening auctionsGiven the following opening auction book

Find the opening auction price, given a previous day’s reference price of 6.735. Then draw

the resulting book after the auction.

Given the following opening auction book

Find the opening auction price and draw the resulting book after the auction.

BID Q BID P ASK P ASK Q

3000 - - 1000

2000 6.75 6.70 1000

4000 6.72 6.71 1000

1000 6.71 6.73 7000

12000 6.70 6.75 7000

BID Q BID P ASK P ASK Q

1000 - - 200

500 10.00 9.70 400

700 9.90 9.80 600

1300 9.80 9.90 800

2000 9.70 10.00 1000

Page 174: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

174

Exercises on opening auctionsGiven the following opening auction book

Find the opening auction price and draw the resulting book after the auction.

Given the following opening auction book

Find the opening auction price and draw the resulting book after the auction.

BID Q BID P ASK P ASK Q

3500 - - 6800

1700 17.0 16.4 1400

5000 16.9 16.5 1200

3200 16.7 16.8 9600

3800 16.6 16.9 6000

BID Q BID P ASK P ASK Q

1500 - - 2250

3750 15.77 15.74 1400

3150 15.76 15.75 4750

2500 15.75 15.76 2250

3000 15.73 15.78 3000

Page 175: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

175

Random minute and market manipulation

As previously stated, the randm minute has been introduced in order to prevent market

manipulations attempting to change the opening price. It often happens, indeed, thatmany proposals to buy and sell are sent with prices set up to condition the opening

price. If the exact ending time of the auction was known, then it would be possible tomanipulate the opening price till a second before the closing of the auction, and then

cancel the fake orders so to be not executed, obtaining a manipulated price in anycase.

Why should people try to manipulate the opening price? To understand that we have

to remember that prices move up and down according to expectations, andexpectations are influenced by the news and parameters that can be observed on the

markets. When a stock moves up it attracts buyers. It’s a psychological factor: manyinvestors are afraid of being cut out from a good deal or to remain stuck in bad deals,

and that’s why when prices raise many investors are mentally pushed to buy and whenprices fall many investors runaway from stocks selling for any price just to get out.

Speculators usually monitor the best an the worse stocks every day, because generally

they are the stocks to trade to make good gains over short time periods; then imitatorsusually do not wait to come into play and give more fuel to price movements.

If we have an open trade on a stock and we wish to push up the price, then, we can try

to manipulate the opening price: a good start will attract new buyers, that will pushupper the price.

Page 176: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

176

Random minute and market manipulation

Now i’ll show how it could be easy to manipulate the opening price if we knew the

exact ending moment of the auction. This time we need a deeper look into the auctionbook. Suppose, then, that what the systems have received till now is this:

If the auction ended right now, the theoretical opening price whould be 8.34 (it’s theonly price that maximizes the tradable quantity, 3900 shares, see next slide).

Page 177: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

177

Random minute and market manipulation

Now we want to manipulate the opening price, for any reason, pushing it higher; to do

that we place an order to buy 3000 shares for the auction price (at best). The bookchanges, and becomes like on next slide.

Page 178: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

178

Random minute and market manipulation

And the theoretical opening price

becomes 8.41 or 8.42. Calculatingthe imbalance, then we get to the

final theoretical opening price, 8.41.

Page 179: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

179

Random minute and market manipulation

If we looked at the book after the auction after the manipulation (read it “what if the

auction ended right now?”) we would notice that the fake order for 3000 shares with noprice limits has two effects: the first is to increase the opening auction price, the second

is that all the buyers offering less than 8.41 euro would be excluded from the trades. Thegold rush begins!

Indeed, all the investors who were willing to buy for 8.40, or 8.37, or any other price

down to 8.34 are now out of the game. And if they are really willing to buy they willhave no choice but to increase the price!

Knowing that the theoretical opening price is now 8.41 they know they have to send

new orders to buy for at least 8.41, better something more. Supposte, then, that all thebuyers cut out from the trades by the fake order (they don’t know it’s fake, of course!)

decide to modify their orders and to offer 8.43, for the same quantities requestedbefore, 2500 shares, that are added to the 600 already there at the price 8.43.

Now suppose that one second before the end of the auction the fake order to buy

3000 shares with no price limites is cancelled. On next slide you can see what the booklooks like then, and the final theoretical opening price, assuming that yesterday’s

control price was 8.30 (because we have to apply the third rule to get to the openingprice).

Page 180: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

180

Random minute and market manipulation

As we can see, the final theoretical

opening price is 8.38, not 8.34.We were able to push up the price

without buying anything!

Page 181: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

181

The continuous phase

The continuous phase follows logics similar to those of the auction phase, but with some

important differences. First of all, this is a very dynamic phase: any order that can beexecuted is executed istantaneously; if a buyer and a seller come into play offering and

asking the same price they are immediately matched, for the quantity that suits themboth; if the two quantities are different they will trade the common part, and one of

them will have a partial execution.

In the continuous phase it is not possible to see at some time a buyer offering 10 and aseller asking 9.99, because in the continuous phase book the best buyer is always lower

than the best seller, otherwise they immediately match and their orders do not appearin the book. Think, for instance, that the two proposals to buy for 10 and sell for 9.99 are

sent when the best buyer in that moment offers 9.99 and the best seller asks for 10: inthe exact moment the two orders are sent to the market (and they will never arrive in

the exact moment) they get immediate execution, but not one with the other: thebuyer hits the best seller in the book, buying for 10, the seller hits the best buyer and sells

for 9.99, not necessarily in this order: it all depends on who comes first.

The logic, indeed, is still the same: “first in, first out”. And according to this mechanism itis not possible that a mistake in sending an order to the market can move the price

significantly far from the previous level. Suppose, for instance, that in front of a bestseller asking 10 euro per share a buyer willing to pay that amount makes a mistake and

sends an order to buy for 100. That order, sent to the market, will hit the first seller in thebook, since he has the right to be filled first. The price of the trade will then be 10 euro!

Page 182: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

182

The continuous phase

An important aspect of the continuous phase book is that when buyers and sellers

agree on the price of a trade they get an immediate execution, that is, they do notappear in the book!

This because the book here shows buyers offering decreasing prices and sellers asking

for increasing prices, and not a single order in the book can be filled if no one takes astep toward the opposite side. Here a typical continuous phase book:

Here the book can then be seen as a picture of the battle field, where buyers and

sellers face each other waiting for their opponents to resign and go into their direction.Notice that here we also have the number of proposals: it can help in forming an idea

about the average dimension of the operators; this can be a very importantinformation, since the presence of a big operator in a book can generate pressures on

the price in a specific direction (we will speak again about this when we’ll see themarket manipulation in the continuous phase).

Page 183: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

183

The continuous phase

Let’s look back to the book on previous slide. The best buyer offers 4.55 euro for 1000

shares, the best seller asks 4.56 for 700 shares. Until new actors come into play withdifferent proposals or one of the two opponents decide to change his mind, no trades

take place.

Now imagine that after a while the seller decides to ask for a little lower price: he decides to please the best buyer; to do that he changes his order, sending it for 4.55

euro and for 700 shares. Istantaneously the system matches the two proposals: the seller sells 700 shares to the first buyer in the book. The seller is completely satisfied, the buyer

just bought 700 shares: he got a partial execution. He is still in the first line of the book, willing to buy 300 shares for 4.55 euro each.

Can the buyer put a condition to his order and buy only the full amount he is willing to

buy? Yes, he can, using a specific condition, which we’ll see forward.

Let’s go back to an important matter: in the continuous book we do not see the trades that take place, because in the book there are only the proposals that cannot be

satisfied immediately. How can we know, then, which trades really take place? Some trading platforms show aside of their books an area called time and sales.

It is still a table, reporting only three fields: time, price, quantity. In it are reported all real

trades, with the time of execution, the price and the number of shares traded.

Page 184: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

184

The continuous phase

A continuous book is full of useful information. First, if we look at the first level, the

distance between the best bid and the best ask price is called bid-ask spread.

The spread is a measure of the liquidity of a stock; liquidity is a measure of risk, becauseit states the ease or the complexity to buy or sell a significant amount of shares in a

specific moment, without conditioning the price’s behaviour.

An example to make things clearer. Look back to the book on slide 182 and imagine tohave the need to sell quickly (for any reason) 10000 shares. There are no buyers for an

amount like that, so we have two ways to sell: the first is to put a sell order for 10000shares for 4.55 euro, selling immediately the first 1000 and waiting for the other 9000 to

be filled as soon as possible (here we face two risks, the first is to have to wait for a longtime, the second to be overpassed by other sellers willing to sell for lower prices, cutting

us out). Or, we could hit the buyers that appear in the book, selling 1000 shares for 4.55,then 3400 for 4.54, then 1800 for 4.53 and the last 3800 for 4.52,

Doing that the weighted average price would be 4.5316 euro. Imagine to have the

need to sell a million shares and the problem should be perfectly clear!

Page 185: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

185

The continuous phase

The liquidity of a stock is not pointed out only by the bid-ask spread; indeed it can be

judged also from eventual jumps in the prices among different levels in the book. Thefollowing book is referred to a very thin stock, Alerion Cleanpower:

The bid-ask spread is about a 3%, very high. And between different consecutive levels in

the book there are significant jumps in the prices.

Suppose to be willing to buy 5000 shares: to be sure to be filled we would need to hitthe first three levels on the ask side, paying a weighted average price very high; and to

sell 5000 shares it would be even worse.

Pay attention: we are talking about orders valued about 15000 euro… nothing! If totrade such a small money amount we have to burn several levels in the book, then the

stock is very illiquid, that is, risky.

Page 186: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

186

The continuous phase

A final information that comes out from the book is the status of the pressure on one of

the two sides of the market.

Look back once again to the book on slide 182: the total amount of shares on the bidside of the book is about 45000. The total amount on the ask side is about 80000.

It seems that in this moment there is a much higher pressure on the sell side, and this

means that supply is stronger than demand.

Theoretically speaking, this could be a signal that the stock is weak and is very likelygoing to drop; but the truth is that the book is just a picture of a specific instant in time in

a trading day and the pressures on one side or the other can change significantly in afraction of a second.

Page 187: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

187

The closing auction phase

At the end of the continuous phase there is another auction, wose goal is to define the

closing price of the day.

The mechanism at the basis of the closing auction is the same of the opening auction,with just two differences.

First, the closing auction lasts only 5 minutes: if at the end no price is found, then the

systems calculate the reference price, equal to the weighted average of the last 10% ofthe daily trade volume, excluding the cross orders.

Second, if to get to a closing auction price we need to use the third rule, than the

reference price is not the previous days closing price, but the current day’s openingprice.

Also in the closing auction there’s the random minute: from 17:30 to 17:35:59.

Page 188: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

188

A closer look to the book

Let’s now consider a real book to make things clear. Here there’s a ‘stamp’ of the book

of the stock Fiat (source: IW Bank), shot on January the 21st 2013, 5 pm, 8 minutes and41seconds.

Page 189: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

189

The book “exploded”

Page 190: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

190

The areas of the book in details

Zone 1 shows some information about the performance of the instrument in a specific

moment, and the profit or loss of opened positions (if there are any).

On the first row, in fact, we have the current price of the instrument (Pzo), 4.7 euros inthis case, the percent change in respect with the previous day’s close, +3.39% here, the

quantity traded in the last trade, 5442 shares this time.

The buttons “op” and “cw” set on the right part of zone 1 are fast links to the chains ofoptions and covered warrants written on the stock Fiat. Let’s ignore them.

On the second row there are the average charge price of the stock (Pmc), that is, the

average price we paid to buy it, if applicable).

We talk about average price because if, let’s say, we purchased 1k shares at 5.0 euroseach and 1k shares at 4.8 euros each, then here we would see 4.9, the weighted

average of the two prices, using quantities as weights.

Then we find the total amount of shares (Q), or contracts, depending on the nature ofthe asset, in our portfolio (if applicable), and finally the profit or loss (PL) of the position in

that moment (if applicable only, once again).

Page 191: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

191Zone 2 reports some useful information about the trend of the stock that day.

There we can indeed read the reference price of the previous day (Rif) and the

theoretical closing auction price of the current day (ThAs), that is, the price that wouldbe the closing price if the day was ending in that moment. We will take care of auction

prices forward.

Then we can read the total traded volume till that moment in that day (Vol), that is, thetotal number of shares traded since the beginning of that day’s negotiations, the

percent change between the theoretical closing auction price and the reference priceof the previous day (Th%), the intraday maximum (Max) and the intraday minimum

(Min).

The areas of the book in details

Page 192: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

192Zone 3 is the real book.

Notice first that it is a symmetrical table: the three left columns are mirrored in respect

with the three right ones.

The left side of the book is a picture of the buyers active on the market in that specificmoment.

This side of the book is called demand, or bid; denaro in italian.

On every row we then have the total number of buyers (N), the total number of shares

they all together are willing to buy (QTA), and the price – identical – anyone of them iswilling to pay to buy that stock in that moment (PZO).

On the first row then we have 4 buyers, willing to buy a total amount of 7838 shares

(how many for each of them is not known), all willing to pay 4.7 euros for each share.

On the second row there are 12 buyers, for a total amount of 81040 shares, offering abit less: 4.698 euros. And so on, row after row.

The buyers are sorted top to bottom, then.

The areas of the book in details

Page 193: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

193By doing this, on the first row there always are the best buyers from the point of view of

the sellers.

Think about that: if you want to sell something on a public market you will try to find thebuyer who is willing to pay more than all the others!

On the first line then we have the best buyers. The price they offer is called best bid.

Then we find the second best, the third best, and so on.

The right side of the book is the side of sellers; it is called supply, or ask; lettera in italian.

Here the sellers are sorted bottom to top: by doing this, on the first row there are the

best sellers from the point of view of the buyers.

In other words, the sellers willing to sell at a lower price. That price is called best ask.

In this case the best sellers are 13, for a total amount of 30893 shares, willing to sell at4.702 euros per share.

The areas of the book in details

Page 194: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

194The book offers an immediate sight into the market in a specific moment, then.

In the book there are some implied informations. One is related to the pressure on the

bid and on the ask side on that asset.

Summing up all the quantities on the left and on the right side, in fact, we can seewhether there is more strenght on the bid (the price could rise) or on the ask (the price

could drop) side.

Indeed this information is included in the book: it is synthesized in a little bar with a cursor(a small square) left free to move on it: when the pressure is higher on the right side, the

cursor moves to the left, and vice-versa.

We will cover this topic again when we’ll see the iceberg orders.

Other information implied in the book refer to the minimum price variation allowed forthat asset and the degree of liquidity of that asset.

Pay particular attention to the second: it’s a clear measure of risk, since the higher the

liquidity of the asset we need to buy or sell, the best execution we will be able to get.

The areas of the book in details

Page 195: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

195Now a question could arise: if the best buyer is willing to pay 4.7 euros and the best

seller is asking for 4.702, how can ever take place a trade?

That’s a logical question: until either the buyers or the sellers decide to settle for a littleworse price, a little higher for the firsts, a little lower for the seconds, there will not be any

trade!

The only way to have a trade is that someone decides to move towards his opponent.

How can we know anything about the real trades, then? What about the prices ofthose trades? What about the traded quantities?

These information come with zne 4, called times and sales.

Here indeed we find the details of all the real trades that take place, sorted bottom to

top (on the top of the table we can see the most recent trades); when a new tradetakes place, it shows up on the first line of the times and sales, pushing down all the

previous trades.

The areas of the book in details

Page 196: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

196Referring to the example, 5442 shares (notice that it’s the same value that shows up in

zone 1, since it’s the last trade) have been traded at 5 hours, 8 minutes, 41 seconds, for4.7 euros per share.

Eleven seconds earlier 4072 shares were traded, for the same price.

Two more seconds earlier other 872 shares, again for the same price. And so on.

The times and sales is fundamental, because it tells us something about the real

pressures acting on an asset at some specific moment, and in which direction.

This concept will become clearer in a while, when we’ll talk about the iceberg orders.

Another natural question: who sells (or buys) first?

The book is managed by a computer that collects all the proposals and aggregatethem on the same price levels, respecting the crhonological order of appearance.

The general rule is that who comes first has the right to be executed first: first in, first out.

The areas of the book in details

Page 197: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

197There’s an exception to the rule “first in, first out”, though.

This exception shows up when operators make proposals given of specific limits in terms

of quantity (we will take care of this issue later).

A problem that can show up in the trading activity is that the quantity asked or offered

get satisfied only partially with a single trade.

Such issues are referred to as partial executions.

Think, for example, to be the first of the buyers in the best bid position, and to be tryingto buy 1000 shares.

If a seller decides to settle for our price and hits us, but he is willing to sell only 750 shares

he has the right to be executed, because he comes first. He will sell 750 shares, then,and we will remain on the first line of the bid side of the book with the residual 250

shares, until a second seller shows up.

What if no one else is willing to sell at our price (that is, the price doesn’t go down anyfurther)? We may remain with a partial execution.

The areas of the book in details

Page 198: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

198Zone number 5 is where we can place orders to buy or sell.

On the first row there comes the simbol of the asset (named ticker): each single asset

has its own label, so that it can be identified without any doubt. Then we have the fieldof the quantity we are willing to buy or sell, the price asked, and the type of the price.

The type is set by default on the option price limit (Limite Pzo). We will take care of this

parameter very soon.

Right under we have button for the cancellation of all the pending (revoca), that is, notyet executed, orders (if there are any), the button for buying (acquista) and the button

for selling (vendi). Finally we have the button chiudi posizione al meglio, CaM, thatcloses immediately all the opened positions (if there are any) and the button chiudi

posizione a limite di prezzo, CaP, that sends to the system an order to close all theopened positions (if there are any) at a specific price. We will take care of this issue too,

very soon.

The simbol “+” set on the bottom right of the book opens more options. Let’s move onfor now.

It’s time to take a step into the magic world of operative orders!

The areas of the book in details

Page 199: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

199

Order types

Orders can be of several types: at market (or best), limit price, conditional price (also

called stop orders).

They can also be enriched with parameters about the quantity: all or nothing, visiblequantity.

And given of a specific time validity as well: good till cancel, or valid till date.

The most common order type is the one so called at best.

To buy or sell at best means to hit the best seller or the best buyer that appear in the

book in that specific moment. It is said to buy or sell at best because it means to hit thebest bid or the best ask.

To do that we just need to write down the number of shares in the proper field, leave

empty the filed of the price, and then click on the button buy or sell.

We will get an instant execution (it really takes just a few milliseconds), that will behiglighted by a sound of some sort in the trading platform. Our order will not even for a

second appear in the book: it will immediately appear in the times and sales.

Immediately after, in zone 1 of the book we will see: the number of shares purchased,the price paid, and the real time performance of the position.

Page 200: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

200

Step 8: Market orders

To be fussy, actually, in the definition “at best” there is a contraddiction in terms.

An exchange is indeed some sort of fish market, where buyers and sellers meet and

fight to get the best price ever for them.

To buy or sell at best means to give up to the opportunity to try and get somethingbetter.

But to be honest, if no one ever decided to settle for something a bit worse, there would

not be any trade: the market would not even exist!

The advantage of a market order is that we can have the immediate confirmationabout the execution of that order.

Looking back at the case of Fiat, to buy at best would mean to buy shares at 4.702

euros each; to sell at best would mean to sell shares at 4.7 euros each.

Page 201: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

201

Step 8: Price limit orders

An alternative consists in the choice of a so called price limit order.

Suppose for example to be willing to buy 1k Fiat shares at 4.692 euors each instead of

4.702. In order to do that we have to write 4.692 in the price field before clicking on thebuy button.

Once we have clicked on the order confirmation we will appear on the left side of the

book, fifth row (assuming that the book is still the one seen previously, of course): thenumber of buyers will be increased by 1 and the quantity will be increased by 1k.

There are an advantage and a disadvantage in this choice. The advantage is that if

our order is executed we will buy at a price lower than the one asked by the best sellersin this moment. The disadvantage is that there is no certainty to be executed: if the

price doesn’t decrease down to 4.692 we will never buy!

Until we get executed the order is pending. If an order remains pending till the marketsclose it is automatically cancelled, unless in the moment it was sent to the market it was

given of a different specific in terms of time validity (see next slide).

Page 202: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

202

Step 8: Time validity of orders

Apart from specific indications, all the orders placed on the market in some day remain

valid till the market close; then, if they have not been executed yet, they areautomatically canceled.

Such orders are called good till cancel (GTC), because as a matter of fact who place

them on the market can also decide to cancel them at any time, without the need towait for the market close.

If the idea is to keep an order valid after the market close, for one or more days, we

can use an order valid till date: before sending the order to the market we can tell thesystem the last date of validity writing it down in a specific field.

At the market close, every day, the system automatically cancels the orders not yet

executed, and the next day, as the market opens, the system automatically sendsagain the order to the market.

Page 203: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

203

Step 8: Conditional orders

A conditional order, often referred to as stop order, can be used for several purposes.

The result is to exponentially increase the number of options available for the trader.

Let’s see an example to make things clear.

Suppose a stock has an important resistance at the price 10.72 euros. If that important

price level gets crossed by an upward move it is very likely that the strenght of themove will increase, since the breakout will probably attract many investors.

Until that threshold keeps pushing down the price, there are no interesting signals,

hence we need to monitor the price waiting for that level to be crossed, ready to buywhen this event shows up.

But this means we have to stay hours or days in front of the sceen waiting for the

breakout. We need to find another way.

The solution comes from stop orders (see next slide).

Page 204: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

204

Step 8: Conditional orders

What we want to put in place now is an order of this sort: “if last price is higher than

10.72 then send to the market an order to buy 1k shares at best”.

In order to do that we need to write 1000 in the quantity field, leave empty the pricefield, set, if we want to, a time validity for the order (the condition to buy will not

probably be satisfied today), and finally set the condition that, if satisfied, makes theorder valid. The condition is made of two components: the type of the condition and

the trigger (the conditioned price).

The type of condition in this case is “last price > than”, or, maybe “last price >= than” (itdepends on the trading platform).

The trigger, 10.72 in this case (10.73 if the condition is >=, since it’s on the breakout of the

price 10.72 that we want to buy, not at that same level), has to be set in the properfiled.

Page 205: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

205

Step 8: Multi-conditional orders

In the moment we click on the “buy” button and we confirm the order, the order will

not be sent to the market: it will remain hidden on the bank’s servers, waiting for thetrigger to be hit.

If we gave the order a time validity, the order will remain inactive, but ready to go, until

either the trigger or the expiration of the order is reached.

If the trigger has never been reached before the maturity of the order, at that time theorder will automatically be canceled, together with the condition.

An extremely interesting variant of conditional orders is given by the opportunity to set

not just an order to buy conditioned to the occurrence of a specific condition, but alsotwo more orders, dependent from the first, for the automatic stop loss, if things go bad,

or take profit, if things go well.

Let’s make an example. Suppose then to be willing to buy shares of the stock XYZ if theprice crosses the 10.72 resistance within 10 days, and that in case of execution we

would like to take profit if the price reaches 11.50, or to cut losses if the price dropsunder 10.45.

This is a complete strategy: entry price with a specific time validity, stop loss and take

profit. Entry strategy, timeline, risk management, profit management, all in one.

Page 206: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

206

Step 8: A full trade via book

In order to do that we just need to write 10.45 in the field “stop loss”, and 11.50 in the

field “take profit”.

Once orders have been confirmed one single order (the so called father order) will beready to get executed: the entry order. The bank’s systems will start monitoring the

trigger price; in the moment it gets crossed the market order to buy will beautomatically sent to the market.

Until this happens the other two orders (called sons orders) are hidden and inactive.

In the moment the father order is executed the system automatically starts monitoring

the two new triggers: the stop loss and the take profit.

IN the moment one of them is reached the system automatically sends thecorrespondent market order, and cancels the other one.

The two sons orders are indeed self-excludent: in the moment one of them is executed,

the other one is automatically canceled. They are called OCO (one cancels other).

Page 207: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

207

Step 8: All or nothing orders (tutto o niente in italian)

Previously we stated that the first in first out rule can have some exceptions.

One of these exceptions is given by the all or nothing orders (ToN), with which we can

tell the market that we will not accept to be satisfied only partially on our order: if, forexample, we are willing to buy 10k shares and the best seller offers only 2k shares he will

not sell his shares to us but to the buyer immediately after us.

In this way the best seller will apply his right to be executed for first; on the other handwe will slip in second position until we will find a seller that matches at least the number

of shares we are willing to buy.

Our order is always ideally in the first place in terms od priority, but it will be executedonly whwn it could be fully executed in one single shot.

Until that happens we will be climbed over by the second best buyers.

Page 208: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

208

Step 8: Iceberg orders

Let’s look back at the book of Fiat and make some quick sums. The total amount asked

by all the buyers is 211833 shares. The total amount offered by the sellers is 301640shares.

Now think you are the manager of a huge investment fund, willing to buy 1 million Fiat

shares, for any reason.

Imagine to place a limit price order for 1M shares, let’s say for 4.694 euros each. Whatyou think will happen?

A clue: the book is the expression of the balance between supply and demand acting

on the market in a specific moment: at any time in front of the book there may bemillions of investors set in every part of the world.

To figure out what it would happen we have to identify ourselves with any investor who

is looking at the book in that moment: he can see few thousands of shares traded pertrade (that’s what the times and sales tells him), but suddenly… a single buyer for 1M

shares…

Page 209: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

209

Step 8: Iceberg orders

The most obvious consequence is that the price goes up like a rocket, because the

whole market understands that there’s a huge investor interested in that stock: usuallyno one invests millions of euros without a good reason…

We can be pretty sure that the stock is going to go up sharply.

The result? The price will rais so fastly that who wanted to buy 1M shares will not get any!

This issue can be solved in two ways. The first consists in placing manually several smaller

orders, let’s say 10k shares a time, one at a time: when the first is executer we place asecond one, then a third, and so on, until we get executed for 1M shares.

The alternative, much better, is to tell the system to do that on its own.

In order to do that we need to take advantage of the function QtaVis (visible quantity),

that can be activeated by an appropriate field in the book.

The fields to be filled are two: the total number of shares to buy (or sell) and the visiblequantity.

Page 210: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

210

Step 8: Iceberg orders

Once we have clicked on the confirm button, the system will send to the market an

order to buy or sell 10k shares; once executed it will send a second order, and so on, tillthe total amount of shares has been bought (or sold).

Such orders are called iceberg (asteriscati in italian), because what appears in the

book is just the summit of a much bigger order, hidden, just to say, under the surface ofthe sea.

Of course after a while the market can realize that there is an iceberg order, since

every time 10k shares are traded at 4.694 euros each a new order for 10k shares showsup.

The problem (from the point of view of other operators) is that even if they realize there

is an iceberg order they cannot know what is the total amount underneath it, that is,they cannot form an idea about th size of the buyer.

Page 211: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

211

Step 8: stock manipulation in the continuous phase

The book can be used for illicit purposes too.

In order to explain this issue let’s make an example.

Suppose again to be the managers of an investment fund, willing to buy 1M Fiat shares

(the same applies on the other side, mutatis mutandis). We do not want the price to goup like a rocket before we buy.

A way to do that is using an iceberg order, of course. But there could be some

problems: iceberg orders not always are fulfilled, since after a while the market realizesthat something is going on and no one buys or sells anymore before they understand

what’s happening.

There is also another way, forbidden by the law, but nonetheless very popular: themarket manipulation.

Page 212: Quantitative Trading Lab - PerCorso Opzioni QuantOptions · 2020. 5. 13. · 1 QUANTITATIVE TRADING LABORATORY DOTT. DOMENICO DALL’OLIO MAIL: domenico.dallolio@unive.it Skype: prof_ddo

212If i want to have a chance to buy 1M shares without pushing up the price i need to

make the market believe there is someone else willing to sell an equal – or even higher –amount on the other side.

This is how it works: we place an order to sell 1M – or more – shares visible on the book,

but in a safe position, let’s say row 4 or 5.

The idea is that in the moment the sell order shows up in the book the price will drop,because all the operators will sell at best just to be sure to get out and leave before the

others.

We will not sell a share, so, but we do not want to!

Our real purpose is to push down the price, so to have a reasonable certainty that wewill be able to buy a huge amount of shares at tre price we decide to buy.

It is, remember, a forbidden behaviour. Nonetheless it always happens, probably

because (some say) it is quite hard to prove the intention to manipulate the price.

Step 8: stock manipulation in the continuous phase