Stock Market Predictions with Markov Chains and Python

  Рет қаралды 53,949

AI Tourist - Tech Meanderings

AI Tourist - Tech Meanderings

Күн бұрын

Пікірлер: 64
@pier-oliviermarquis3006
@pier-oliviermarquis3006 2 жыл бұрын
There are forward biases in two different places in your algorithm. First, you are taking the mean of 'Outcome_Next_Day_Direction' as your label and assigning all features within the sequence ID to that label. The label contains future information. Second, you are using the patterns[id+1] to calculate your log prob. Basically, you need knowledge of the next day's transition to know what is the appropriate log prob... What your algorithm should do is not use the mean, keep each day's label as it is, and then use the patterns[id+2] after a transition from patterns[id] to patterns[id+1] has been observed.
@BlackJesus8463
@BlackJesus8463 11 ай бұрын
nerd
@andrewna9362
@andrewna9362 5 ай бұрын
Rest. Does it work ? ;)
@elismith2491
@elismith2491 3 жыл бұрын
Great video! That’s a very elegant model. One mistake though, in your transition matrix, you never actually calculate the probability of volume going up/down given that a sequence appears. You instead calculate the probability that the sequence appears, given that the volume goes up/down. Due to bayes rule, the two probabilities are not equal.
@69erthx1138
@69erthx1138 3 жыл бұрын
You can't exchange integration (prob density) with summation (time-based chain of ups/downs) abitrarily for a stochastic function, only one that's montonic (deterministic), is this close to what you're pointing out? I remember that Bayes has to do the CLT.
@joshuamenter4243
@joshuamenter4243 2 жыл бұрын
I'm extremely late but currently trying to work through a project involving a markov chain model to predict stock action. Is there any easy way to find the probability value of stock action going up or down?
@AC-hc5lc
@AC-hc5lc 8 ай бұрын
Hi, amazing work. Is there any chance of implementing a fractal in your system ? Many thanks 🙏
@Krath1988
@Krath1988 Жыл бұрын
Why do you use a set of random-walks instead of taking the actual probability of the events in the set and computing the long-run probability by raising the transition matrix to a power?
@dennisvacaru2777
@dennisvacaru2777 8 ай бұрын
Hi!! Really interesting.. so right now I'm working really hard to find an equation with extensions and just one fractal using Markov's method .. also there is a range of market cap and a range of liquidity.. any ideas? Could you help me?
@fiaz2421
@fiaz2421 2 жыл бұрын
11:08 where is the date from 2010 gone. It started for 2015
@seannguyen3260
@seannguyen3260 4 жыл бұрын
Thank you for your video, and how can we estimate probability element in the Markov Matrix? Could you give me any hints? Thank you!
@elismith2491
@elismith2491 3 жыл бұрын
The transition probabilities between two states equals the number of sequences from the data set containing the from/to states, divided by the number of sequences in the dataset. I think. Be careful though, the probabilities do not represent the probability that volume goes up/down given that the sequence appears. They instead represent the probability that the sequence appears given that the volume goes up/down. Due to bayes rule, these values are not equivalent.
@zzador
@zzador 3 жыл бұрын
The probability for state transition A -> B is the number of transitions A -> B divided by the total number of transitions A -> X where X is every possible state [A, B, ... Z]. In a practical implementation just just count every transition and calculate the probabilities from the counts in an after-pass.
@sourdurian2839
@sourdurian2839 4 жыл бұрын
just started learning Markov chains. complex yet intriguing. Excellent video Manuel!
@snivesz32
@snivesz32 4 жыл бұрын
It’s an interesting topic Manual. One bias you are introducing (at line 735) is filtering out all the events which result in small volumes. You say this confuses the model, but perhaps another way of saying it is that including it reveals that the method actually doesn’t have a high predictive power. Suppose we have a series of markov chains and assign a stochastic random variable as the target and filter those chains out which have a target value less than some threshold. We would see fewer chains and must be biased to higher target values. This would appear to improve the model, but it’s actually a bias. I’d like to hear your thoughts on that.
@viralml
@viralml 4 жыл бұрын
Abs. correct, snivesz32. That's why boosted classifiers like xgboost and catboost work so well, they break down features into groups and will train weaker ones more than stronger ones. Many ways of slicing and dicing this but your thinking this way will help you improve your models. Best! www.viralml.com
@Daniel88santos
@Daniel88santos 5 жыл бұрын
Hi Manuel, nice job ... thank you for sharing. Can I ask you what you think about Particle Filters for market prediction? Would be interesting if you do a video on it, since doesn't exist any material on KZbin about it. Best regards, Daniel.
@viralml
@viralml 5 жыл бұрын
Thanks Daniel for the kind words and the suggestion - I'll keep that in mind though I am not familiar with this approach. Do you have any links?
@jasonpeloquin9950
@jasonpeloquin9950 3 жыл бұрын
Awesome video! I did have a question as I wrap my head around this code in terms of the predicted value for the next day. Is there a specific variable that gives the predicted binary outcome for the next day? I see how its contrasted against actual data in the training vs test set but I would like to be able to isolate the next days prediction value by itself as a forward looking indicator.
@miguelbayona157
@miguelbayona157 4 жыл бұрын
Manuel, I have a question. As I make an attempt to write the code in Mathematica, I am wondering a couple of things: In your example, you end up with two matrices of dimension 5 x 26. Why is that so? I know there are 3^3 = 27 ways to generate different patterns of "L", "M" and "H", allowing repetitions of course, but why do you have only the five rows "HHH", "HHM", "HLH", "HLL" and "HLM"? Are these just the options that begin with H? What happened to "HML"? I guess I still do not understand completely how to generate the Markov matrix...
@sergi3d
@sergi3d 4 жыл бұрын
@Miguel Bayona : I just went through the code and the matrices are actually 26x26 (or 24x24 with the data that Manuel had back when he posted this video). I think your confusion comes from the fact that, in the code, Manuel just prints the .head() of the matrices that, by default only shows the first 5 rows of the dataframe... @Manuel Amunategui : Thanks for this and many other ineteresting videos you post!!
@binmadibinmadi5434
@binmadibinmadi5434 3 жыл бұрын
can any provide with python code link in github
@rickygrossi7660
@rickygrossi7660 3 жыл бұрын
cant get the code to work? Does anyone have any suggestions?
@miguelbayona157
@miguelbayona157 4 жыл бұрын
Manuel, what a great video to show the Markov Chain in action. I would love to run the Python code on my machine. I am also very tempted to do this in Mathematica. Where can I get your Python code? I am also going to check out your book "Monetizing Machine Learning"...
@viralml
@viralml 4 жыл бұрын
Code links are always in the description section - and definitely, go to town with this stuff! That's what I did when I took a stab at it :-)
@miguelbayona157
@miguelbayona157 4 жыл бұрын
Manuel, I have a question. As I make an attempt to write the code in Mathematica, I am wondering a couple of things: In your example, you end up with two matrices of dimension 5 x 26. Why is that so? I know there are 3^3 = 27 ways to generate different patterns of "L", "M" and "H", allowing repetitions of course, but why do you have only the five rows "HHH", "HHM", "HLH", "HLL" and "HLM"? Are these just the options that begin with H? What happened to "HML"? I guess I still do not understand completely how to generate the Markov matrix...
@viralml
@viralml 4 жыл бұрын
@@miguelbayona157 Hey Miguel, check out Pranab Gosh document, it's in the notes hopefully it can answer your questions. This is just my interpretation and its been a while so I don't recall the details. Best! www.viralml.com
@sergi3d
@sergi3d 4 жыл бұрын
@Miguel Bayona : I just went through the code and the matrices are actually 26x26 (or 24x24 with the data that Manuel had back when he posted this video). I think your confusion comes from the fact that, in the code, Manuel just prints the .head() of the matrices that, by default only shows the first 5 rows of the dataframe... @Manuel Amunategui : Thanks for this and many other ineteresting videos you post!!
@obsoletepowercorrupts
@obsoletepowercorrupts Жыл бұрын
8:30 You mention it is slow. You've made a nice learning experience code sample there. Well done. It can be sped up (although this is a basic concept, not optimised), instead of using that For Loop. So, you have an Object Oriented Programming language there. You could create a dynamically linked list of objects, differentiating between pass by address and pass by reference. You could also break the OOP rules for better performance in terms of the private attributes so that they are not hidden from the complier by virtual environments. Array indexing in R programming but considering the nature of the data you're interrogating, I'd anticipate Index matrices are what you'd be after. By then though, for handling Discrete Markov Chains, you'll want to at least consider the R (cran) Markovchain package. You'd even be able to spread the matrices over multiple processor cores and sockets. My comment has no hate in it and I do no harm. I am not appalled or afraid, boasting or envying or complaining... Just saying. Psalms23: Giving thanks and praise to the Lord and peace and love. Also, I'd say Matthew6.
@Hitasssss
@Hitasssss 3 жыл бұрын
I do this thing in Excel :D
@samuelcooper9880
@samuelcooper9880 2 жыл бұрын
Nice !
@whatwonderfulworld
@whatwonderfulworld 4 жыл бұрын
Can you optimize this model and increase the accuracy above 70 or 80? I have tried this method using DJI and SPY stocks. The accuracy didn't cross 70. Can you post another video on the same topic but using better datasets and optimized code if possible?
@viralml
@viralml 4 жыл бұрын
Hi, glad you tried, that's the whole point is to teach you how to do it. And if you want to dig more into these topics - check out: www.viralml.com/learn Thanks!
@whatwonderfulworld
@whatwonderfulworld 4 жыл бұрын
@@viralml can you make a video on option pricing using different models like monte Carlo, binomial, black scholes
@viralml
@viralml 4 жыл бұрын
@@whatwonderfulworld Thanks for the tips, Kaushik - I'll add it to the list.
@MrErolyucel
@MrErolyucel 3 жыл бұрын
Very neat. Thank you
@mosherchtman
@mosherchtman 3 жыл бұрын
What is the time frame for this model? I thought it was just daily data, but then it does not get along with the following combinations: kzbin.info/www/bejne/qZXTZWysicahic0
@ReasonToKeepGoing
@ReasonToKeepGoing 5 жыл бұрын
Thank you for this awesome video with detailed explanations. I just learned about Markov Chains this week and this video really helped graps the concepts a bit better.
@viralml
@viralml 5 жыл бұрын
Glad it helped!!
@8a1ad61b
@8a1ad61b 4 жыл бұрын
54.43% is not good. Flipping a coin is 50%. Why don't we simply flip a coin to decide whether to buy a stock?
@viralml
@viralml 4 жыл бұрын
Most do
@Diego0wnz
@Diego0wnz 4 жыл бұрын
Manuel Amunategui really? :o
@videopunk_project3737
@videopunk_project3737 3 жыл бұрын
Ever heard of the compound interest?
@AJohnson0325
@AJohnson0325 Ай бұрын
If your winners are 1% bigger than your losers and you have a win rate of 55%, then you can make a ton of money as long as you don’t have big drawdowns. You just need to make a lot of trades. Some strategies don’t do well under certain circumstances like sideways markets, crashes, and some short strategies would have blown up when the meme stocks were going to the moon.
@stephenhobbs948
@stephenhobbs948 4 жыл бұрын
Really interesting video. I am going to do the code w/your tutorial and I got the book. Looking forward to more videos as soon as you can.
@1mfikri
@1mfikri 3 жыл бұрын
Þþţ
@Anon_life
@Anon_life 3 жыл бұрын
I love this. HMM?
@Krath1988
@Krath1988 2 жыл бұрын
Best value on the internet. Thank you for the workbook! Btw you can plug your random walk loop into a function and use multiprocessor for a huge speed-up.
@Theshitshow666
@Theshitshow666 Жыл бұрын
That sounds super interesting. Have you tried coding that?
@user-or7ji5hv8y
@user-or7ji5hv8y 3 жыл бұрын
Are we binning because we are using discrete Markov chains?
@DonnyDonowitz22
@DonnyDonowitz22 4 жыл бұрын
Great video. Thank you very much.
@viralml
@viralml 4 жыл бұрын
Welcome, Fernando!
@borisgotov9838
@borisgotov9838 5 жыл бұрын
Can you beat a provider spread with 4% positive probability?
@viralml
@viralml 5 жыл бұрын
It would probably beat 50% of day traders :-)
@mikhailtzevelekos3083
@mikhailtzevelekos3083 4 жыл бұрын
He can apply martingale
@sourdurian2839
@sourdurian2839 4 жыл бұрын
Hi Manuel .. at 10:50 i see that you did pd.concat(new_set) .. and then new_set_df.shape you get 1998581, how did you get that number and it seems like you didnt concat the new_set with any other frames. Thanks!!
@eminbaybarstimurstudent3802
@eminbaybarstimurstudent3802 3 жыл бұрын
Hey Manuel, it is a great video but I have a question about the grid matrix, I learnt it with the name called the "Emission" matrix and as far as I know it gives the probabilites of observing that sequence given the state, so each rows represent a marginal probability distribution of the sequences, then shouldn't the rows' summation be equal to 1 ? In this example I see some rows whose sum exceed 1. Am I missing something ?
@sdoofette
@sdoofette 4 жыл бұрын
Brilliant Video and tutorial thanks for that, a topic that seems to be missing is the feature selection part in order to remove the noisy signals out, would you know of any good source in Python to do that?
@crypticnomad
@crypticnomad 4 жыл бұрын
Thanks for the awesome video on an awesome topic. I didn't come here looking for stock specific ideas but rather to learn more about markov chains. After watching the video I am a bit interested in trying neural network embeddings using the vocabulary you generate here. The problem I am working on is essientally trying to predict when some other model(which I don't have access to) is likely to produce a false positive, true positive, false negative or true negative. The original model has roughly a 69% overall accuracy and is decently calibrated(0.205 brier score) but the false positives and false negatives are an issue. Would this method scale well to more than two outputs(like 4 in my use case)?
@_matis_
@_matis_ 3 жыл бұрын
For trading,would you reccomend me the hmm or markov chains?Sorry i am totally new to this...
@viralml
@viralml 3 жыл бұрын
You need to backtest thoroughly any strategy yourself - recommendations aren't worth anything.
@_matis_
@_matis_ 3 жыл бұрын
@@viralml Yes,i am aware that i need to backtest my strategy.But rn i am trying to understand the differences between chains and hidden models.As a person who doesn't have a strong mathematical or statistical background it is very challenging to understand those terms when applied to real life situations.It is a bit easier to understand the theory when someone uses analogies with weather or food,but for trading i am still not sure which path is more suited...
Incredible Dangers in Browsers (Affects all of them)
21:02
Rob Braxman Tech
Рет қаралды 304 М.
Evolution of the Alphabet | Earliest Forms to Modern Latin Script
16:13
UsefulCharts
Рет қаралды 2,2 МЛН
Шок. Никокадо Авокадо похудел на 110 кг
00:44
Самое неинтересное видео
00:32
Miracle
Рет қаралды 2,9 МЛН
小天使和小丑太会演了!#小丑#天使#家庭#搞笑
00:25
家庭搞笑日记
Рет қаралды 12 МЛН
Прогнози и анализи със Силва Дончева
46:02
Famous Historian EXPOSES ISR*EL’S FACTS! | Isr*el’s Future In The Quran!
30:55
Calling Scammers by their real names
20:55
Jim Browning
Рет қаралды 45 МЛН
Markov Chains - VISUALLY EXPLAINED + History!
33:07
Kapil Sachdeva
Рет қаралды 13 М.
Problems You will Encounter on Linux (and How to Solve Them)
23:01
Rob Braxman Tech
Рет қаралды 94 М.
Шок. Никокадо Авокадо похудел на 110 кг
00:44