Jim Simons Trading Secrets 1.1 MARKOV Process

QuantProgram
5 May 202320:12

Summary

TLDRCe script vidéo explore les stratégies de trading quant de Jim Simons et son fonds Medallion, qui a réalisé un rendement de 39% net des frais sur trois décennies. Il introduit le processus de Markov et son application dans la modélisation des marchés financiers, en se concentrant sur la prédiction de la probabilité des états futurs en se basant sur l'état actuel. Le script propose également une démonstration pratique de la façon de coder et d'appliquer ces concepts dans la stratégie de trading, en utilisant des exemples concrets et des analyses de données historiques pour établir des probabilités de performance sur le marché.

Takeaways

  • 🧠 Jim Simons et son fonds Medallion sont considérés comme l'un des plus grands succès de la trading quantitatif, montrant que la stratégie basée sur les quants peut être extrêmement lucrative.
  • 💡 La stratégie de trading de Simons est secrète, mais certaines idées peuvent être déduites à travers la lecture et l'analyse de livres pertinents.
  • 📚 Le livre mentionné dans le script a été une source d'inspiration pour les stratégies de trading personnelles et les cours enseignés.
  • 🔢 L'importance de la chaîne de Markov est soulignée, où les modèles stochastiques basés sur cette chaîne peuvent prédire l'avenir avec une certaine précision.
  • 🔄 La stratégie de inversion de la moyenne, basée sur l'idée que les prix ont tendance à revenir à la moyenne après un mouvement initial, est un élément clé des stratégies enseignées.
  • 📉 Les performances exceptionnelles du fonds de Simons, en particulier pendant les périodes de récession, montrent l'efficacité des stratégies de trading quantitatifs en environnements de forte volatilité.
  • 🤖 Le script mentionne l'utilisation de modèles de machine learning pour améliorer la prédiction des marchés, une méthode qui a été employée par les traders de haut niveau.
  • 📈 L'analyse des performances de la stratégie de inversion de la moyenne sur le SPY démontre son efficacité, en particulier pendant les périodes de récession et de volatilité.
  • 📝 L'importance de la matrice de transition dans le cadre du processus de Markov est expliquée, servant à calculer les probabilités de changement d'état du marché.
  • 💻 Un exemple concret d'application du processus de Markov à la trading est présenté, en utilisant des données historiques pour établir des probabilités de performance future.
  • 🌐 L'idée finale est que les outils et les compétences pour traiter les données, comme le processus de Markov, sont essentiels pour créer des stratégies de trading performantes.

Q & A

  • Quel est le rendement net des frais du fonds Medallion de Jim Simons sur trois décennies ?

    -Le fonds Medallion de Jim Simons a réalisé un rendement net de 39% sur trois décennies.

  • Quel est le rôle d'Ax en tant que membre du fonds Medallion ?

    -Ax était un employé du fonds Medallion, faisant partie de l'équipe de Jim Simons, et était reconnu pour être un génie mathématicien ayant écrit de nombreux articles académiques impressionnants.

  • Quelle est la signification d'un processus de Markov dans le contexte du trading quantitatif ?

    -Un processus de Markov est une séquence aléatoire d'événements où les probabilités futures dépendent de l'état actuel, pas de l'état précédent, ce qui est utilisé pour prédire avec une certaine précision les mouvements du marché à partir d'un modèle capable.

  • Quel est le lien entre le processus de Markov et les stratégies de trading de Jim Simons ?

    -Bien que le processus de Markov soit utilisé dans de nombreux domaines, il est impliqué dans les stratégies de trading du fonds Medallion de Jim Simons, bien que les détails spécifiques de son utilisation soient extrêmement secrets.

  • Quel est le concept de stratégie de réversion à la moyenne mentionné dans le script ?

    -La stratégie de réversion à la moyenne est basée sur l'idée que les prix ont tendance à revenir vers une moyenne après un mouvement initial vers le haut ou le bas. Cette stratégie consiste à acheter après une baisse anormalement faible ou à vendre après une hausse.

  • Quels sont les avantages d'une stratégie de réversion à la moyenne pendant une période de récession ?

    -Pendant une période de récession, où la volatilité est extrêmement élevée, les stratégies de réversion à la moyenne ont tendance à bien se comporter, comme le démontre les performances exceptionnelles du fonds Medallion en 2007 et 2008.

  • Quelle est la différence entre une stratégie basée sur le processus de Markov et une stratégie de réversion à la moyenne ?

    -Une stratégie basée sur le processus de Markov utilise des modèles stochastiques pour prédire les mouvements futurs du marché en se basant sur l'état actuel, tandis qu'une stratégie de réversion à la moyenne s'appuie sur l'idée que les prix reviennent vers une moyenne après un mouvement significatif.

  • Comment les stratégies de trading basées sur les modèles de Markov peuvent-elles être codées et testées ?

    -On peut coder et tester des stratégies basées sur les modèles de Markov en utilisant des langages de programmation comme Python, en calculant des matrices de transition et en utilisant ces matrices pour prédire les probabilités de performance du marché à court terme.

  • Quels sont les outils et les bibliothèques Python nécessaires pour implémenter un modèle de Markov dans le trading ?

    -Pour implémenter un modèle de Markov, on peut utiliser des bibliothèques Python telles que YFinance pour télécharger des données de marché, Pandas et Numpy pour manipuler et analyser les données, et Pine Editor pour tester des stratégies de trading.

  • Comment les modèles de Markov peuvent-ils être améliorés avec l'apprentissage automatique ?

    -Les modèles de Markov peuvent être améliorés en utilisant des techniques d'apprentissage automatique pour ajuster les paramètres du modèle et prédire les probabilités de transition plus efficacement, en s'appuyant sur de grandes quantités de données historiques.

Outlines

00:00

😎 Explication du fonds Medallion de Jim Simons et de la stratégie basée sur les quants

Ce paragraphe aborde la performance exceptionnelle du fonds Medallion de Jim Simons, qui a généré un rendement de 39% nets des frais sur trois décennies. Il souligne l'intelligence et la richesse de Simons, reconnu comme l'un des meilleurs traders de tous les temps, dépassant même des légendes comme Warren Buffett ou Charlie Munger. La stratégie du fonds est secrète, mais on peut tirer des idées de son approche quantitative à travers un livre consulté par le narrateur. Ce livre inspire également les stratégies personnelles du narrateur. L'objectif de la vidéo est d'explorer certaines de ces idées, notamment la chaîne de Markov et la stratégie de réversion à la moyenne, et de les coder pour analyser les résultats.

05:01

📚 Introduction à la chaîne de Markov et à la stratégie de réversion à la moyenne

Le narrateur explique le concept de chaîne de Markov, où les événements futurs sont prévisibles avec une certaine précision en se basant sur l'état actuel plutôt que le passé. Il cite Ax, un ancien employé de Jim Simons et génie des mathématiques, qui a utilisé cette théorie pour créer des équations stochastiques. Ensuite, il mentionne le travail d'un autre mathématicien, Lo, qui a développé une stratégie de réversion à la moyenne, profitant de la tendance des prix à revenir à leur niveau moyen après un mouvement initial. Le narrateur observe également la performance de cette stratégie pendant les périodes de récession, en particulier en 2007 et 2008, où elle a généré des rendements élevés malgré la hausse de la volatilité.

10:04

🔢 Application de la chaîne de Markov et de la réversion à la moyenne dans les stratégies de trading

Le narrateur entreprend de calculer les probabilités de performance du marché à l'aide de la chaîne de Markov, en utilisant des exemples simples pour illustrer comment les probabilités sont basées sur l'état actuel plutôt que sur les événements précédents. Il présente ensuite une matrice de transition, qui est un outil pour modéliser les probabilités de changement d'état du marché. Cette matrice est utilisée pour prédire les mouvements du marché en se basant sur des données historiques, et le narrateur propose également de recourir à des modèles de machine learning pour améliorer ces prédictions.

15:06

📉 Exemple concret avec les données historiques du S&P 500 (SPY)

Le narrateur passe à une démonstration实务的, en utilisant les données historiques du S&P 500 (SPY) pour calculer les probabilités de performance à l'aide de la chaîne de Markov. Il explique comment télécharger et manipuler les données avec Python, en utilisant des bibliothèques comme Pandas et Numpy. Il calcule les retours quotidiens et les états du marché (haut ou bas), puis crée une matrice de transition pour déterminer les probabilités de continuation ou de changement des tendances. Il met en évidence les performances de la stratégie de réversion à la moyenne après une séquence de jours à la baisse.

20:08

🚀 Optimisation de la stratégie de trading avec le processus de Markov

Le narrateur propose d'optimiser la stratégie de trading en utilisant le processus de Markov pour déterminer les conditions d'entrée et de sortie plus efficaces. Il illustre cela avec un exemple de stratégie basée sur une séquence de six jours à la baisse, qui a une probabilité élevée de suivre un jour à la hausse. Il backteste cette hypothèse et montre que, même avec une condition simple, la stratégie peut être performante. Il encourage les téléspectateurs à explorer davantage en combinant plusieurs conditions et en appliquant la stratégie à de multiples actions, ce qui peut conduire à une réduction significative des baisses de portefeuille.

👋 Conclusion de la vidéo et invitation à la discussion

Le narrateur conclut la vidéo en remerciant les téléspectateurs et en les invitant à poser des questions ou à demander des éclaircissements dans les commentaires. Il exprime son désir de les aider dans leur parcours de trading quantitatif et espère qu'ils ont apprécié la vidéo. Il souhaite une bonne journée à tous et prend congé.

Mindmap

Keywords

💡Quants

Les 'Quants' sont des professionnels de la finance qui utilisent des méthodes quantitatives et des modèles mathématiques pour analyser les marchés financiers et développer des stratégies d'investissement. Dans la vidéo, ils sont associés à Jim Simons et sa fund Medallion, démontrant leur succès exceptionnel sur plusieurs décennies.

💡Markov chain

Une 'chaîne de Markov' est un modèle mathématique qui représente une séquence d'événements aléatoires où la probabilité de l'état futur dépend uniquement de l'état actuel et non des états précédents. Dans le script, cette notion est utilisée pour prédire la tendance du marché et développer des stratégies de trading.

💡Stratégie de réversion à la moyenne

La 'stratégie de réversion à la moyenne' est une approche de trading qui假定 que les prix ont tendance à revenir vers une valeur moyenne après un mouvement significatif. Dans le script, cette stratégie est mentionnée comme étant particulièrement efficace pendant les périodes de récession, où la volatilité est élevée.

💡Volatilité

La 'volatilité' fait référ à la mesure de la variabilité des prix sur un marché financier. Elle est un élément clé dans la vidéo, car elle est liée à la performance des stratégies de réversion à la moyenne, en particulier pendant les périodes de récession.

💡Jim Simons

Jim Simons est un mathématicien et un investisseur américain, célèbre pour être le fondateur de Renaissance Technologies et pour ses réalisations exceptionnelles dans le domaine de la finance quantitative. Dans le script, il est considéré comme l'un des meilleurs traders de tous les temps.

💡Récessions

Les 'récessions' sont des périodes de déclin économique prolongé. Dans le script, elles sont mentionnées comme des périodes où les stratégies de réversion à la moyenne ont tendance à bien se comporter en raison de la hausse de la volatilité.

💡Modèle stochastique

Un 'modèle stochastique' est un type de modèle qui incorpore des éléments aléatoires pour décrire ou simuler un phénomène. Dans le script, il est utilisé pour créer une équation basée sur la chaîne de Markov, servant à prédire les mouvements du marché.

💡Transition Matrix

La 'matrice de transition' est une représentation tabulaire des probabilités de passage d'un état à un autre dans une chaîne de Markov. Dans le script, elle est utilisée pour calculer les probabilités de performance du marché en fonction des états précédents.

💡Anaconda Notebook

Un 'Anaconda Notebook' est un environnement interactif de développement pour Python qui permet de combiner du code, des résultats de calcul et du texte narratif. Dans le script, il est utilisé pour illustrer comment coder et tester des stratégies de trading basées sur la chaîne de Markov.

💡Y Finance

Y Finance est une bibliothèque Python qui permet de récupérer des données financières à partir de Yahoo Finance. Dans le script, elle est utilisée pour télécharger les données historiques du marché nécessaires à l'analyse et au développement de stratégies de trading.

💡Pine Editor

Le 'Pine Editor' est un éditeur de stratégies de trading sur TradingView, qui permet aux traders de coder des stratégies en utilisant un langage de programmation spécifique. Dans le script, il est mentionné comme outil pour tester des stratégies basées sur la chaîne de Markov.

Highlights

Jim Simons' Medallion fund has achieved a 39% net return over three decades, demonstrating the effectiveness of a quant-based strategy.

Simons is considered one of the greatest traders, surpassing even Warren Buffett or Charlie Munger in performance.

The secretive nature of Simons' fund operations has inspired the exploration of quant strategies inspired by his approach.

Ax, a former employee of Jim Simons and a mathematical genius, focused on Markov chains for predicting market movements.

Markov chains are used to create stochastic equations for trading strategies based on the predictability of future steps from the current state.

Lo, another employee, implemented mean-reverting strategies, capitalizing on the tendency of prices to revert after significant moves.

During the 2007-2008 recession, Simons' fund achieved exceptionally high returns, highlighting the effectiveness of diverging strategies in volatile markets.

Mean-reverting strategies taught in the course have shown significant performance during recessions and the past two years.

The video will demonstrate coding and applying Markov processes to create trading strategies, inspired by Simons' success.

A Markov process is defined as a sequence of events where future probabilities depend only on the current state, not the past.

The Markov process is applicable in various fields, including weather forecasting and quantitative trading.

A simple example of a Markov process is given using the daily activities of a human and a Markov chain model.

Transition matrices are used to calculate the probabilities of market movements based on Markov processes.

Historical data and machine learning models can be utilized to determine the probabilities within the Markov model.

The video includes a practical example of calculating Markov process probabilities using Python, pandas, and numpy.

The calculated probabilities can be used to create entry and exit conditions for trading strategies, enhancing performance.

The Q5 strategy from the course, inspired by Markov models, has shown excellent performance even during market downturns.

The video concludes by emphasizing the importance of using data and tools like the Markov process to create effective trading strategies.

Transcripts

play00:00

what do you think of quants Jim Simon's

play00:02

Medallion fund has done 39 net of fees

play00:05

for three decades which proves that it

play00:07

works they were very very smart yes they

play00:09

got very rich very very smart very smart

play00:11

and very rich yeah and and very high

play00:13

grade by the way yeah Jim Simons Jim

play00:16

cement is considered to be one of the

play00:18

greatest traders of all time who has

play00:20

Beats and the likes of Warren Buffett or

play00:22

Charlie Munger and his strategy as being

play00:24

purely a quan based strategy

play00:27

um what he does in his fund is extremely

play00:30

secretive but there are certain ideas

play00:33

and there are certain concept that we

play00:35

could get from what he does through this

play00:37

book that I've been reading and most of

play00:39

my uh strategies that I've come across

play00:42

which I do in my personal life has also

play00:45

been inspired from this book so what

play00:47

we're going to do today is we're going

play00:48

to take some of the information that we

play00:50

can find in this book and start coding

play00:52

and trying to see the results and try to

play00:55

figure out what Jim cement has been

play00:57

doing in this fund so one of the pages

play00:59

is in the book here it's about ax ax

play01:03

used to work for Jim Simmons he was part

play01:05

of the fund and he's also some kind of a

play01:08

mathematical genius I think he's got

play01:10

like amazing Papers written by him and

play01:13

if you can see in this paragraph he

play01:15

focuses on a thing called Markov chain

play01:17

so in a Markov chain each step along the

play01:19

way is impossible to predict with

play01:20

certainty but future steps can be

play01:22

predicted with some degree of accuracy

play01:24

if one relies on a capable model and

play01:28

they go on to create a stochastic

play01:29

equation based on this Markov chain

play01:32

another important thing which is just a

play01:34

few pages prior to this was this one

play01:37

loafer again another mathematical genius

play01:40

working for Siemens and they did more of

play01:43

a mean inverting strategy so here the

play01:45

strategies were often based on the idea

play01:47

that prices tend to revert after an

play01:49

initial move higher or lower and they

play01:51

would buy if you just gone right if they

play01:53

opened at unusually low prices so that

play01:55

is a typical example of a mean reverting

play01:57

strategies so at the end of the book one

play02:00

of the things that I noticed was his uh

play02:03

trading result and if you can see in

play02:05

2008 2007 which was basically the

play02:08

recessionary time frame uh he went on to

play02:11

make 152 return 136 return that's

play02:14

substantially higher than any of those

play02:17

years and you've got to understand that

play02:19

during recessionary periods the

play02:21

volatility is extremely high and being

play02:23

diverting strategies perform extremely

play02:25

well so even the strategies that we do

play02:27

in our course especially Q3 and Q5

play02:30

worked tremendously well during the

play02:32

2008-2007 recession and also the past

play02:35

two years so this is one of the

play02:38

strategies that we teach in the course

play02:40

Q5 and it's performed very well the past

play02:44

two years and also in the 2008 recession

play02:45

this is a mean inverting strategy so if

play02:47

I can zoom into some of the strategies I

play02:49

can hear short hair close position there

play02:52

long here closer position the next day

play02:55

uh long hair closer position there so

play02:57

you're we're always going to see lots of

play02:59

good trades session environment in the

play03:01

past two years has been really good for

play03:02

a main reverting strategy so this is the

play03:04

trading result of that mean inverting

play03:06

strategy on the spy and if I can look

play03:08

into that Buy and Hold equity line this

play03:10

period you see here that was the 2008

play03:13

recession you can literally see the blue

play03:16

line which is the S P 500 Buy and Hold

play03:18

has crashed almost 50 percent but the

play03:21

main reverse strategy performed

play03:22

extremely well now if you can go back to

play03:24

the 2001-2002 period it's literally an X

play03:27

the Blue Line went down considerably

play03:29

while our strategy performed extremely

play03:31

well same thing can be seen the past two

play03:34

years because 2001 to 2000 2021 2022 and

play03:38

including now the market still hasn't

play03:40

recovered you can see from the peak it's

play03:41

been going down and still isn't like a

play03:43

consolidation doesn't recover at the

play03:45

highs but the strategy is performed

play03:47

extremely well and the reason why is

play03:49

because of the recessionary environment

play03:50

recession your volatility based High

play03:52

wealthily based environment gives great

play03:54

results for mean inverting strategies so

play03:57

what we're going to do so if you guys

play03:58

want to check out this course us feel

play04:00

free to visit our website at one program

play04:03

and this strategy comes in the corn

play04:06

program Prometheus which includes 10

play04:08

strategies and it also includes many

play04:10

other important strategies along with

play04:13

Trend following and momentum based and

play04:15

also Monte Carlo simulation portfolio

play04:17

optimization forward testing and all the

play04:20

other important Quant trading tools

play04:22

necessary so what we're going to do in

play04:25

this video is good we're going to

play04:26

discuss what the Markov process is

play04:27

because Marco process is what's what we

play04:31

saw from the book and what is a markup

play04:33

process and how we can create trading

play04:35

strategies from the Marco process

play04:38

so to start off with a markup process is

play04:41

basically a random sequence of events

play04:43

where the probabilities of the future is

play04:46

based on the current state

play04:48

okay it's not based on the past so

play04:51

tomorrow's probabilities depends upon

play04:54

today it's not dependent on yesterday so

play04:57

for instance if I have to predict the

play04:59

weather

play05:00

the weather prediction for tomorrow is

play05:03

based on today and not yesterday so

play05:06

Marco process used in many different

play05:08

fields just not in the quantitative

play05:10

trading field it's also used in weather

play05:11

forecasting and many other fields so I

play05:14

hope you guys understood the definition

play05:15

of markup process now I'm going to the

play05:17

example of it so you guys get an idea in

play05:20

simple terms so let's take two scenarios

play05:22

so one is a markup guy and the other is

play05:25

a human being

play05:26

so let's take the case of a human being

play05:28

let's take myself as a condition so I

play05:31

wake up in the morning I wake up at home

play05:34

and then I go to the shop to buy some

play05:36

stuff and I buy the stuff and then I go

play05:38

to work so when I reach the shop I know

play05:42

I came from home so there's no reason

play05:44

for me to go back to home so I can go

play05:47

straight to work so Marco on the other

play05:49

hand he goes from home and goes straight

play05:52

to the shop and now he's in the current

play05:53

state right so in the current state

play05:57

he can go either home or to work because

play05:59

he doesn't know what happened the

play06:01

previous instance as compared to human

play06:03

being

play06:04

so the whole Mark of probabilities is

play06:06

based on this

play06:08

um

play06:09

this current state and future State

play06:11

because the shop is where the corner

play06:13

state is and once Markov is in that

play06:15

currency of the shop he can go either to

play06:17

home or to work but when Markov is at

play06:20

work he has nowhere else to go so he

play06:22

goes straight to shop same thing goes

play06:24

when he's at home he has nowhere else to

play06:25

go and then he goes straight to the shop

play06:27

so if you're calculating the

play06:29

probabilities of the Markov that's when

play06:31

things get slightly not complicated but

play06:34

the numbers start to come into play so

play06:36

when he is at home there's only one

play06:37

place for him to go and that is to the

play06:39

shop so there's a hundred percent

play06:41

probability that he will go to the shop

play06:43

so then we write one now on the other

play06:47

scenario when he's at the shop

play06:49

as I said before he doesn't know where

play06:51

they where he came back from so he can

play06:54

go either to home or to work so now

play06:57

there's a 50 chance for him to go either

play06:59

home or work

play07:01

now once Marco reaches work again he has

play07:04

nowhere else to go so he's got 100

play07:05

probability that he will go to the shop

play07:08

so

play07:10

this is how simple the marker

play07:11

probability is now if you are putting

play07:14

this into trading perspective so let's

play07:16

let's take a trading example into

play07:18

consideration so forget the thing that's

play07:20

going on here let's just focus on this

play07:22

one here so these numbers are

play07:24

hypothetical numbers so I'm going to

play07:25

explain to you what it's all about so

play07:27

you see this positive percentage and

play07:29

negative percentage so whenever you see

play07:31

the news you always see the market when

play07:32

that five percent of the market went

play07:34

down two percent and things like that so

play07:35

that's a percentage move for the

play07:37

specific day so in this percentage

play07:39

positive percentage move the 0.7 depicts

play07:43

the probability of the next day being a

play07:46

positive percentage so if today is a

play07:48

positive percentage close if today is an

play07:50

up day

play07:51

uh then the next days probability is 0.7

play07:55

now the 0.7 is just a hypothetical

play07:57

number so don't don't go deep into it as

play07:59

of now

play08:01

um so this positive percentage for the

play08:03

next day to be positive percentage is

play08:04

0.7 so what will be a negative

play08:06

percentage it's pretty simple it's 1

play08:07

minus 0.7 that is 0.3 so you can see the

play08:10

arrow here that's minus percentage so

play08:13

similarly when it's today is negative

play08:16

percentage what is the probability that

play08:18

the next day will be negative well here

play08:20

I put in 0.2 so what's the probability

play08:23

that it will be a positive it's 1 minus

play08:25

0.2 which is 0.8 now how did I come

play08:28

across all these numbers well you can

play08:31

calculate in many ways you can calculate

play08:32

just based on historical data you can we

play08:35

can calculate the number of updates the

play08:37

number of down days and divided by the

play08:39

uh update and the total number of down

play08:41

days and we'll get the probability of

play08:42

the up days and down days and then there

play08:44

are machine learning models as well so

play08:46

if you can go through that book one of

play08:48

the things that they have done is even

play08:49

off before many years you're talking 30

play08:52

years or so they've been using machine

play08:54

learning models but now these days you

play08:57

can use machine learning models with

play08:58

just a few lines of code so I hope you

play09:00

guys understood the whole idea of this

play09:02

thing of this markup probabilities these

play09:04

numbers are just hypothetical but now

play09:06

you can put this into a matrix right

play09:09

this is called transition Matrix so

play09:11

you've got the positive percentage

play09:13

you've got the negative percentage

play09:14

you've got the positive percentage

play09:15

you've got the negative percentage here

play09:16

as well in the columns so a positive

play09:18

percentage and the next day is a

play09:20

positive percentage is 0.7 as you saw

play09:22

here

play09:23

similarly a positive percentage and the

play09:26

next day is a negative percentage is 0.3

play09:29

again negative percentage day and the

play09:32

next day is a positive percentage day is

play09:34

0.8 as you can see here and a negative

play09:36

percentage

play09:38

followed by the next day a negative

play09:39

percentage is 0.2 so if you can observe

play09:43

something 0.7 plus 0.3 is 1 and 0.8 plus

play09:48

0.2 is again one so this is basically a

play09:51

transition Matrix so here we have just

play09:53

taken two days in a row so we can

play09:55

actually have more rows and more columns

play09:57

where you can have uh plus plus minus

play10:00

minus a plus plus minus minus minus you

play10:03

can have many kinds of permutations and

play10:05

combinations in this but these is

play10:07

basically a mark of trading and this is

play10:09

how we calculate the trading property so

play10:11

now what we're going to do is we're

play10:13

going to go to a real world example on

play10:15

spy and we're going to calculate the

play10:18

probabilities of the Spy getting a

play10:21

positive percentage on the next day

play10:23

following the previous day being the

play10:25

positive percentage and similarly

play10:27

negative and negative and negative and

play10:29

positive so this is the Anaconda

play10:31

notebook where we'll be calculating the

play10:33

Marco process and transition

play10:35

probabilities

play10:37

um and if you don't know anything about

play10:40

python

play10:42

then I would suggest you to go to our

play10:44

video in our Channel algorithmic trading

play10:47

in Python so you get the basics of how

play10:49

to do python so it'll be really

play10:51

beneficial for you in your Quant trading

play10:53

Journey you can also do the trading

play10:54

Viewpoint script if you fancy as well so

play10:56

now going to the Anaconda notebook so

play10:59

first thing we do is basically we

play11:00

download the Y Finance library and the

play11:02

pandas in the numpy which is necessary

play11:04

for us to calculate many things then we

play11:07

download the data so we download the

play11:08

data for spy from 2010 to 2022 you can

play11:11

download more data or you can keep the

play11:14

data smaller so you can access different

play11:16

time periods so for example if you want

play11:17

to just assess a recessionary time

play11:19

period you can just do the 2008 or the

play11:21

2001.com Bob request so you get the

play11:24

recessionary environment data as well so

play11:25

it's up to you really so I've just

play11:27

randomly chosen 2010 to 2022. and then

play11:32

we've actually downloaded the data

play11:35

um and basically you can see the Open

play11:37

high low close and the just close and

play11:38

the volume so we need to get up on the

play11:40

daily return so we're going to take the

play11:41

adjuster close and Dot percentage change

play11:43

function and that will give us the

play11:45

percentage difference between yesterday

play11:47

and today and also the states so

play11:50

basically state is where the daily

play11:52

return is greater or equal to zero we

play11:54

have got up so we've got the num uh

play11:57

numpy pandas numpy SNP so that's why we

play12:00

use NB here so daily routine is greater

play12:03

than is equal to zero then it's an

play12:04

update else it's a down day and then

play12:06

we've stored it in data of state so then

play12:10

here is the data frame of the data and

play12:12

you can see the daily return here and

play12:14

whether it's an up percentage closed or

play12:15

a down percentage close so

play12:17

you can see whenever there's a positive

play12:19

one it's up and whenever there's a

play12:21

negative one it's down negative here

play12:23

again it's down uh negative here it's

play12:26

again down as well so basically uh we're

play12:28

using uh just pure map to find out the

play12:31

probabilities as compared to using

play12:33

machine learning models however uh in

play12:36

the book they've talked about machine

play12:38

learning models and that was years ago

play12:39

so now you can do a machine learning

play12:41

models just with a few lines of code so

play12:43

if you guys are stoked about doing this

play12:45

making this more efficient then go ahead

play12:47

with the machine learning model as well

play12:49

but as of now we're just going to make

play12:50

it simple so you guys can understand the

play12:52

process so we've got the up counts and

play12:54

the down counts so up counts is

play12:56

basically you take the length of the

play12:58

data of the state where it's up so how

play13:02

many days has there been up and then

play13:03

similarly down counts give you the

play13:05

length of how many days it's been down

play13:07

so if you can get that information then

play13:09

we can calculate the probabilities we're

play13:10

not going to use these two lines of

play13:11

codes anyway but it's just created to

play13:13

give you an understanding on how to

play13:15

calculate the probabilities

play13:17

so up to up is like two consecutive

play13:19

positive percentage close uh down to up

play13:22

the negative day followed by a positive

play13:25

day and up to down similarly and down to

play13:27

down two consecutive uh down days

play13:30

so we calculate the length of the how

play13:32

many times the days has been like

play13:34

consecutive updates and then we divided

play13:36

by the update and that will give us the

play13:38

probability of a two consecutive updates

play13:40

similarly uh down to up up to down and

play13:43

down to down and then we'll do a

play13:45

transition Matrix where we've got like a

play13:47

pandas data frame and we're going to put

play13:48

all these results into like a matrix

play13:50

kind of a fancy kind of a way and then

play13:53

we'll print the transition Matrix and

play13:55

we've got the information so you can see

play13:57

up to up is 54 percent

play14:00

up to down is 45 percent

play14:02

down to up is 57 and down to down is 42.

play14:06

so the best performing is an update

play14:09

after a down day so that is 57 so if I'm

play14:12

going to take any bet in all these four

play14:14

conditions my bet will be to go uh for

play14:17

an update after a down day because

play14:19

there's a 50 57 chance for that to work

play14:21

out uh now down to down is significantly

play14:25

lower so it's just 42 so there is

play14:27

nothing significant for us to uh you

play14:30

know make a trade in so in all these

play14:31

numbers these numbers are not that

play14:33

significant it's on the 50 40 area so I

play14:36

want something more effective

play14:37

so let's do another one let's do what's

play14:40

the probability of update if there is

play14:43

five consecutive down days so down day

play14:46

down day down day down day down day and

play14:49

then we divide it by the length

play14:52

tier again length of the uh five or six

play14:56

down days and what is the probability of

play14:57

that so that probability is 66 percent

play15:00

now that is a pretty good probability

play15:03

six to six percent is something that I

play15:05

can work with so what I'm going to do is

play15:07

I'm going to take this information that

play15:09

I've got like five to six days of down

play15:11

days and the probability of the next day

play15:13

being an update is pretty good so I'm

play15:15

going to take this information and I'm

play15:16

going to back test it so nine times out

play15:18

of ten I would back test in Army broker

play15:20

but now just to make things simple I'm

play15:22

just going to go into Pine editor and

play15:24

I'm going to do a condition where close

play15:26

is less than one close to one is less

play15:28

than close with two so basically

play15:29

yesterday's close is lower than the

play15:30

prior day so we've got that condition

play15:32

for five to six days

play15:34

and that is our entry if that condition

play15:36

is met and then we are going to close

play15:39

our position

play15:41

if the next day close is higher than uh

play15:45

today's scores so it's pretty simple and

play15:48

you can create a markup model for the

play15:50

exit condition as well so what is the

play15:52

probability of us having a greater

play15:54

return if the close is tomorrow or two

play15:57

days later so then we can calculate a

play15:59

better probability and create even

play16:00

better strategy so when you run this

play16:03

strategy you would see the result as 46

play16:05

with a drawdown of just five percent so

play16:07

this is not at all significant when you

play16:10

look at simple terms but when you look

play16:12

in the overall perspective it's pretty

play16:14

good because you can see there's only 20

play16:16

trays placed if that's from 1994. and

play16:19

it's only based on one condition so

play16:21

imagine if you create multiple

play16:22

conditions or Marco models so here we

play16:24

did six days of consecutive close below

play16:27

so what about five days what about four

play16:29

days what about a combination like up

play16:32

down up followed by an update or down

play16:35

down up followed by an updates then you

play16:37

can add up more and more conditions uh

play16:39

if the probability is suiting you will

play16:41

like 60 up and then your net profit

play16:44

starts clamping up and up and up again

play16:46

and because you've got more conditions

play16:48

the drawdowns start to uh be better as

play16:51

well because if you're basing it on just

play16:53

one strategy then the drawdowns won't be

play16:55

that significant so you need to have

play16:57

more strategy so we did the video uh

play16:59

just the prior video the gpt4 where we

play17:01

did a strategy wherein we had a strategy

play17:04

applied to 25 stocks and also 90 stocks

play17:07

and how we were able to reduce the

play17:08

drawdown considerably just by doing the

play17:12

strategy in multiple stocks similarly if

play17:14

you can add more conditions to this this

play17:16

will be spectacular so the whole idea of

play17:19

this video is for you guys to understand

play17:21

what a Markov process is to code it in

play17:24

Python and then apply it in your trading

play17:27

goal so for example the Q5 strategy that

play17:31

we did in our course if you can look at

play17:33

it

play17:35

um because it's a mean inverting

play17:36

strategy and also the fact that it's

play17:39

kind of inspired from the markovia model

play17:40

you can see how amazingly it performs so

play17:43

this is the 2001 dot combo where the

play17:45

market is crashed considerably well and

play17:46

you can see it's literally a diagonal uh

play17:49

you know literally across uh similarly

play17:51

here again 2008 crash where it went down

play17:53

54 and look at the results of that

play17:55

strategy again recently past two years

play17:58

uh the market went down and this

play18:00

strategy has outperformed the market and

play18:01

the drawdown is quite minimal as well so

play18:03

this is the advantage of Mercury model

play18:05

so in this strategy I took the markovi

play18:07

model and I effectively did I don't want

play18:10

to give out much information about it

play18:12

but the people who know the course uh

play18:14

know how I combine two different things

play18:15

I've chosen the days similar to what we

play18:18

saw here

play18:21

uh the close is less than one kind of

play18:22

thing but then I use the exit condition

play18:25

to be slightly tweaked

play18:27

um so these are some of the things that

play18:28

you can efficiently do in creating good

play18:31

strategies great strategies based on

play18:32

good probabilities so in this case we've

play18:34

got a 66 probability and that why it

play18:36

kind of worked so even if I go to the

play18:39

ETF of QQQ again you will see a 21

play18:41

return and Microsoft and one button and

play18:44

the list just goes on so you will

play18:46

basically see just start bit just based

play18:47

on one condition right so imagine having

play18:49

multiple conditions and applying this to

play18:51

multiple stocks and this is pretty much

play18:52

what Jim Smith is doing and we don't

play18:55

know exactly what he's doing but all we

play18:57

can do is to get information from the

play18:59

book information from any kind of

play19:01

interviews he does you know combined

play19:02

together and kind of improve but

play19:05

regardless when you're in a Quant

play19:06

trading Journey you're trying to get the

play19:08

probabilities in your favor so any tool

play19:10

including the markovian process and

play19:13

calculate the transition properties is

play19:14

highly efficient so in this case we

play19:16

actually

play19:18

did you know just based on historical

play19:20

data probabilities now you can actually

play19:23

tweak that to use a machine learning

play19:25

model to calculate the probabilities of

play19:26

these you can go a step further create a

play19:29

for Loop and change these down datas and

play19:32

you know down and up to different

play19:35

combinations and calculate more

play19:36

properties create a massive Matrix not

play19:38

just up up down like you know like 10 10

play19:41

rows here 10 10 columns there and then

play19:44

uh you can tweak the data points you

play19:47

know instead of this you can actually do

play19:48

the recession environment so you can

play19:50

create a recessionary based environment

play19:51

strategy or Trend following strategy so

play19:54

the sky is the limit when you have data

play19:56

and when you have the tools and the

play19:58

skills to process it so I hope you guys

play19:59

like this video if you have any queries

play20:01

any uh any doubts or clarifications feel

play20:05

free to leave a comment and I'll be more

play20:07

than happy to help you guys out so hope

play20:09

you guys enjoy this video have a great

play20:11

great day bye-bye

Rate This

5.0 / 5 (0 votes)

Étiquettes Connexes
Trading QuantitatifChaînes de MarkovRéversion à la MoyenneStratégies de TradingJim SimonsModèle PrédictifVolatilité MarchéRécessionsOptimisation de PortefeuilleAnalyse de DonnéesModèles de Machine Learning