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.
@BlackJesus846311 ай бұрын
nerd
@andrewna93625 ай бұрын
Rest. Does it work ? ;)
@elismith24913 жыл бұрын
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.
@69erthx11383 жыл бұрын
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.
@joshuamenter42432 жыл бұрын
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-hc5lc8 ай бұрын
Hi, amazing work. Is there any chance of implementing a fractal in your system ? Many thanks 🙏
@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?
@dennisvacaru27778 ай бұрын
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?
@fiaz24212 жыл бұрын
11:08 where is the date from 2010 gone. It started for 2015
@seannguyen32604 жыл бұрын
Thank you for your video, and how can we estimate probability element in the Markov Matrix? Could you give me any hints? Thank you!
@elismith24913 жыл бұрын
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.
@zzador3 жыл бұрын
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.
@sourdurian28394 жыл бұрын
just started learning Markov chains. complex yet intriguing. Excellent video Manuel!
@snivesz324 жыл бұрын
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.
@viralml4 жыл бұрын
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
@Daniel88santos5 жыл бұрын
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.
@viralml5 жыл бұрын
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?
@jasonpeloquin99503 жыл бұрын
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.
@miguelbayona1574 жыл бұрын
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...
@sergi3d4 жыл бұрын
@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!!
@binmadibinmadi54343 жыл бұрын
can any provide with python code link in github
@rickygrossi76603 жыл бұрын
cant get the code to work? Does anyone have any suggestions?
@miguelbayona1574 жыл бұрын
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"...
@viralml4 жыл бұрын
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 :-)
@miguelbayona1574 жыл бұрын
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...
@viralml4 жыл бұрын
@@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
@sergi3d4 жыл бұрын
@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 Жыл бұрын
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.
@Hitasssss3 жыл бұрын
I do this thing in Excel :D
@samuelcooper98802 жыл бұрын
Nice !
@whatwonderfulworld4 жыл бұрын
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?
@viralml4 жыл бұрын
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!
@whatwonderfulworld4 жыл бұрын
@@viralml can you make a video on option pricing using different models like monte Carlo, binomial, black scholes
@viralml4 жыл бұрын
@@whatwonderfulworld Thanks for the tips, Kaushik - I'll add it to the list.
@MrErolyucel3 жыл бұрын
Very neat. Thank you
@mosherchtman3 жыл бұрын
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
@ReasonToKeepGoing5 жыл бұрын
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.
@viralml5 жыл бұрын
Glad it helped!!
@8a1ad61b4 жыл бұрын
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?
@viralml4 жыл бұрын
Most do
@Diego0wnz4 жыл бұрын
Manuel Amunategui really? :o
@videopunk_project37373 жыл бұрын
Ever heard of the compound interest?
@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.
@stephenhobbs9484 жыл бұрын
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.
@1mfikri3 жыл бұрын
Þþţ
@Anon_life3 жыл бұрын
I love this. HMM?
@Krath19882 жыл бұрын
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 Жыл бұрын
That sounds super interesting. Have you tried coding that?
@user-or7ji5hv8y3 жыл бұрын
Are we binning because we are using discrete Markov chains?
@DonnyDonowitz224 жыл бұрын
Great video. Thank you very much.
@viralml4 жыл бұрын
Welcome, Fernando!
@borisgotov98385 жыл бұрын
Can you beat a provider spread with 4% positive probability?
@viralml5 жыл бұрын
It would probably beat 50% of day traders :-)
@mikhailtzevelekos30834 жыл бұрын
He can apply martingale
@sourdurian28394 жыл бұрын
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!!
@eminbaybarstimurstudent38023 жыл бұрын
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 ?
@sdoofette4 жыл бұрын
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?
@crypticnomad4 жыл бұрын
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_3 жыл бұрын
For trading,would you reccomend me the hmm or markov chains?Sorry i am totally new to this...
@viralml3 жыл бұрын
You need to backtest thoroughly any strategy yourself - recommendations aren't worth anything.
@_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...