SlideShare a Scribd company logo
HMM & Stock
Prediction
David Chiu @ ML/DM Monday
http://ywchiu-tw.appspot.com/
HIDDEN MARKOV MODEL
• Finite state machine which has some fixed number of
states
• Provides a probabilistic framework for modeling a time
series of multivariate observations
STOCK PRICE PREDICTION
Every time history repeats itself
• Stock behavior of past is similar to behavior of current day
• The Next day’s stock price should follow about the same past data
pattern
BENEFIT OF USING HMM
• Handle new data robustly
• Computationally efficient to develop and evaluate
• Able to predict similar patterns efficiently
HMM ON STOCK PREDICTION
• Using the trained HMM, likelihood value P for current
day’s dataset is calculated
• From the past dataset using the HMM we locate those
instances that would produce the nearest P likelihood
value.
CHARACTERIZE HMM
• Number of states in the model: N
• Number of observation symbols: M
• Transition matrix A = {aij} , where aij represents the transition
probability from state i to state j
• Observation emission matrix B = {bj(Ot)} , where bj(Ot) represent the
probability of observing Ot at state j
• Initial state distribution π = {πi}
MODELING HMM
PROBLEM OF HMM
1. The Evaluation Problem - Forward
– What is the probability that the given observations O = o1 ,o2
,...,oT are generated by the model p{O|λ} with a given HMM λ ?
1. The Decoding Problem - Viterbi
– What is the most likely state sequence in the given model λ that
produced the given observations O = o1 ,o2 ,...,oT ?
1. The Learning Problem - Baum-Welch
– How should we adjust the model parameters {A,B,π } in order to
maximize p{O|λ} , whereat a model λ and a sequence of
observations O = o1 ,o2 ,...,oT are given?
BAUM-WELCH ALGORITHM
• Find the unknown parameters of a hidden Markov model(HMM).
• Generalized expectation-maximization (GEM) algorithm
• Compute maximum likelihood estimates and posterior
mode estimates for the parameters (transition and emission
probabilities) of an HMM, when given only emissions as training
data.
FIREARM
TOOL KIT
• R Package
– HMM
– RHMM
• JAVA
– JHMM
• Python
– Scikit Learn
DEMO
GET DATASET
• library(quantmod)
• getSymbols("^TWII")
• chartSeries(TWII)
• TWII_Subset<- window(TWII, start = as.Date("2012-01-01"))
• TWII_Train <- cbind(TWIISubset$TWII.Close - TWII_Subset$TWII.Open,
TWII_Subset$TWII.Volume)
BUILD HMM MODEL
# Include RHMM Library
•library(RHmm)
# Baum-Welch Algorithm
•hm_model <- HMMFit(obs =TWII_Train , nStates = 5)
# Viterbi Algorithm
•VitPath <- viterbi(hm_model, TWII_Train)
SCATTER PLOT
• TWII_Predict <- cbind(TWII_Subset$TWII.Close, VitPath$states)
• chartSeries(TWII_Predict[,1])
• addTA(TWII_Predict[TWII_Predict[,2]==1,1],on=1,type="p",col=5,pch=25)
• addTA(TWII_Predict[TWII_Predict[,2]==2,1],on=1,type="p",col=6,pch=24)
• addTA(TWII_Predict[TWII_Predict[,2]==3,1],on=1,type="p",col=7,pch=23)
• addTA(TWII_Predict[TWII_Predict[,2]==4,1],on=1,type="p",col=8,pch=22)
• addTA(TWII_Predict[TWII_Predict[,2]==5,1],on=1,type="p",col=10,pch=21)
DATA VISUALIZATION
SCIKIT LEARN
#Baum-Welch Algorithm
•n_components = 5
•model = GaussianHMM(n_components, "diag")
•model.fit([X], n_iter=1000)
# predict the optimal sequence of internal hidden state
•hidden_states = model.predict(X)
MODELING SAMPLE
MODELING SAMPLE
PREDICTION
#State Prediction – using Scikit-learn
•data_vec = [diff[last_day], volume[last_day]]
•State = model.predict([data_vec])
REFERENCE
• Hassan, M. (2009). A combination of hidden Markov model and
fuzzy model for stock market forecasting. Neurocomputing, 72(16),
3439-3446.
• Gupta, A., & Dhingra, B. (2012, March). Stock Market Prediction
Using Hidden Markov Models. In Engineering and Systems (SCES),
2012 Students Conference on (pp. 1-4). IEEE.
Hidden Markov Model & Stock Prediction

More Related Content

What's hot

Linear regression with gradient descent
Linear regression with gradient descentLinear regression with gradient descent
Linear regression with gradient descent
Suraj Parmar
 
Long Short Term Memory (Neural Networks)
Long Short Term Memory (Neural Networks)Long Short Term Memory (Neural Networks)
Long Short Term Memory (Neural Networks)
Olusola Amusan
 
Hidden Markov Model - The Most Probable Path
Hidden Markov Model - The Most Probable PathHidden Markov Model - The Most Probable Path
Hidden Markov Model - The Most Probable Path
Lê Hòa
 
Text classification with fast text elena_meetup_milano_27_june
Text classification with fast text elena_meetup_milano_27_juneText classification with fast text elena_meetup_milano_27_june
Text classification with fast text elena_meetup_milano_27_june
Deep Learning Italia
 
Lecture 18: Gaussian Mixture Models and Expectation Maximization
Lecture 18: Gaussian Mixture Models and Expectation MaximizationLecture 18: Gaussian Mixture Models and Expectation Maximization
Lecture 18: Gaussian Mixture Models and Expectation Maximizationbutest
 
Probabilistic Models of Time Series and Sequences
Probabilistic Models of Time Series and SequencesProbabilistic Models of Time Series and Sequences
Probabilistic Models of Time Series and Sequences
Zitao Liu
 
Speaker Recognition using Gaussian Mixture Model
Speaker Recognition using Gaussian Mixture Model Speaker Recognition using Gaussian Mixture Model
Speaker Recognition using Gaussian Mixture Model
Saurab Dulal
 
Binary Class and Multi Class Strategies for Machine Learning
Binary Class and Multi Class Strategies for Machine LearningBinary Class and Multi Class Strategies for Machine Learning
Binary Class and Multi Class Strategies for Machine Learning
Paxcel Technologies
 
Deep Learning for Natural Language Processing: Word Embeddings
Deep Learning for Natural Language Processing: Word EmbeddingsDeep Learning for Natural Language Processing: Word Embeddings
Deep Learning for Natural Language Processing: Word Embeddings
Roelof Pieters
 
Lecture 7: Hidden Markov Models (HMMs)
Lecture 7: Hidden Markov Models (HMMs)Lecture 7: Hidden Markov Models (HMMs)
Lecture 7: Hidden Markov Models (HMMs)
Marina Santini
 
Hidden Markov Model & It's Application in Python
Hidden Markov Model & It's Application in PythonHidden Markov Model & It's Application in Python
Hidden Markov Model & It's Application in Python
Abhay Dodiya
 
Lecture 4: Transformers (Full Stack Deep Learning - Spring 2021)
Lecture 4: Transformers (Full Stack Deep Learning - Spring 2021)Lecture 4: Transformers (Full Stack Deep Learning - Spring 2021)
Lecture 4: Transformers (Full Stack Deep Learning - Spring 2021)
Sergey Karayev
 
Performance Metrics for Machine Learning Algorithms
Performance Metrics for Machine Learning AlgorithmsPerformance Metrics for Machine Learning Algorithms
Performance Metrics for Machine Learning Algorithms
Kush Kulshrestha
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
hunglq
 
Svm
SvmSvm
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう 「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
Junpei Tsuji
 
Reinforcement learning 7313
Reinforcement learning 7313Reinforcement learning 7313
Reinforcement learning 7313Slideshare
 
은닉 마르코프 모델, Hidden Markov Model(HMM)
은닉 마르코프 모델, Hidden Markov Model(HMM)은닉 마르코프 모델, Hidden Markov Model(HMM)
은닉 마르코프 모델, Hidden Markov Model(HMM)
찬희 이
 
Hidden Markov Model
Hidden Markov Model Hidden Markov Model
Hidden Markov Model
Mahmoud El-tayeb
 
Lecture 9 Markov decision process
Lecture 9 Markov decision processLecture 9 Markov decision process
Lecture 9 Markov decision process
VARUN KUMAR
 

What's hot (20)

Linear regression with gradient descent
Linear regression with gradient descentLinear regression with gradient descent
Linear regression with gradient descent
 
Long Short Term Memory (Neural Networks)
Long Short Term Memory (Neural Networks)Long Short Term Memory (Neural Networks)
Long Short Term Memory (Neural Networks)
 
Hidden Markov Model - The Most Probable Path
Hidden Markov Model - The Most Probable PathHidden Markov Model - The Most Probable Path
Hidden Markov Model - The Most Probable Path
 
Text classification with fast text elena_meetup_milano_27_june
Text classification with fast text elena_meetup_milano_27_juneText classification with fast text elena_meetup_milano_27_june
Text classification with fast text elena_meetup_milano_27_june
 
Lecture 18: Gaussian Mixture Models and Expectation Maximization
Lecture 18: Gaussian Mixture Models and Expectation MaximizationLecture 18: Gaussian Mixture Models and Expectation Maximization
Lecture 18: Gaussian Mixture Models and Expectation Maximization
 
Probabilistic Models of Time Series and Sequences
Probabilistic Models of Time Series and SequencesProbabilistic Models of Time Series and Sequences
Probabilistic Models of Time Series and Sequences
 
Speaker Recognition using Gaussian Mixture Model
Speaker Recognition using Gaussian Mixture Model Speaker Recognition using Gaussian Mixture Model
Speaker Recognition using Gaussian Mixture Model
 
Binary Class and Multi Class Strategies for Machine Learning
Binary Class and Multi Class Strategies for Machine LearningBinary Class and Multi Class Strategies for Machine Learning
Binary Class and Multi Class Strategies for Machine Learning
 
Deep Learning for Natural Language Processing: Word Embeddings
Deep Learning for Natural Language Processing: Word EmbeddingsDeep Learning for Natural Language Processing: Word Embeddings
Deep Learning for Natural Language Processing: Word Embeddings
 
Lecture 7: Hidden Markov Models (HMMs)
Lecture 7: Hidden Markov Models (HMMs)Lecture 7: Hidden Markov Models (HMMs)
Lecture 7: Hidden Markov Models (HMMs)
 
Hidden Markov Model & It's Application in Python
Hidden Markov Model & It's Application in PythonHidden Markov Model & It's Application in Python
Hidden Markov Model & It's Application in Python
 
Lecture 4: Transformers (Full Stack Deep Learning - Spring 2021)
Lecture 4: Transformers (Full Stack Deep Learning - Spring 2021)Lecture 4: Transformers (Full Stack Deep Learning - Spring 2021)
Lecture 4: Transformers (Full Stack Deep Learning - Spring 2021)
 
Performance Metrics for Machine Learning Algorithms
Performance Metrics for Machine Learning AlgorithmsPerformance Metrics for Machine Learning Algorithms
Performance Metrics for Machine Learning Algorithms
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Svm
SvmSvm
Svm
 
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう 「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
 
Reinforcement learning 7313
Reinforcement learning 7313Reinforcement learning 7313
Reinforcement learning 7313
 
은닉 마르코프 모델, Hidden Markov Model(HMM)
은닉 마르코프 모델, Hidden Markov Model(HMM)은닉 마르코프 모델, Hidden Markov Model(HMM)
은닉 마르코프 모델, Hidden Markov Model(HMM)
 
Hidden Markov Model
Hidden Markov Model Hidden Markov Model
Hidden Markov Model
 
Lecture 9 Markov decision process
Lecture 9 Markov decision processLecture 9 Markov decision process
Lecture 9 Markov decision process
 

Similar to Hidden Markov Model & Stock Prediction

Logistic Regression using Mahout
Logistic Regression using MahoutLogistic Regression using Mahout
Logistic Regression using Mahout
tanuvir
 
Hidden Markov Model (HMM).pptx
Hidden Markov Model (HMM).pptxHidden Markov Model (HMM).pptx
Hidden Markov Model (HMM).pptx
AdityaKumar993506
 
Differential Machine Learning Masterclass
Differential Machine Learning MasterclassDifferential Machine Learning Masterclass
Differential Machine Learning Masterclass
Antoine Savine
 
Hidden Markov Model (HMM)
Hidden Markov Model (HMM)Hidden Markov Model (HMM)
Hidden Markov Model (HMM)
Abdullah al Mamun
 
Mining Big Data Streams with APACHE SAMOA
Mining Big Data Streams with APACHE SAMOAMining Big Data Streams with APACHE SAMOA
Mining Big Data Streams with APACHE SAMOA
Albert Bifet
 
ANN ARIMA Hybrid Models for Time Series Prediction
ANN ARIMA Hybrid Models for Time Series PredictionANN ARIMA Hybrid Models for Time Series Prediction
ANN ARIMA Hybrid Models for Time Series Prediction
M Baddar
 
AutoML lectures (ACDL 2019)
AutoML lectures (ACDL 2019)AutoML lectures (ACDL 2019)
AutoML lectures (ACDL 2019)
Joaquin Vanschoren
 
iterativealgorithms.ppsx
iterativealgorithms.ppsxiterativealgorithms.ppsx
iterativealgorithms.ppsx
Bharathi Lakshmi Pon
 
Iterative Algorithms.ppsx
Iterative Algorithms.ppsxIterative Algorithms.ppsx
Iterative Algorithms.ppsx
BharathiLakshmiAAssi
 
Mining big data streams with APACHE SAMOA by Albert Bifet
Mining big data streams with APACHE SAMOA by Albert BifetMining big data streams with APACHE SAMOA by Albert Bifet
Mining big data streams with APACHE SAMOA by Albert Bifet
J On The Beach
 
StackNet Meta-Modelling framework
StackNet Meta-Modelling frameworkStackNet Meta-Modelling framework
StackNet Meta-Modelling framework
Sri Ambati
 
Equirs: Explicitly Query Understanding Information Retrieval System Based on Hmm
Equirs: Explicitly Query Understanding Information Retrieval System Based on HmmEquirs: Explicitly Query Understanding Information Retrieval System Based on Hmm
Equirs: Explicitly Query Understanding Information Retrieval System Based on Hmm
International Journal of Engineering Inventions www.ijeijournal.com
 
Different Models Used In Time Series - InsideAIML
Different Models Used In Time Series - InsideAIMLDifferent Models Used In Time Series - InsideAIML
Different Models Used In Time Series - InsideAIML
VijaySharma802
 
Applications of Machine Learning in High Frequency Trading
Applications of Machine Learning in High Frequency TradingApplications of Machine Learning in High Frequency Trading
Applications of Machine Learning in High Frequency Trading
Ayan Sengupta
 
Predicting Stock Market Price Using Support Vector Regression
Predicting Stock Market Price Using Support Vector RegressionPredicting Stock Market Price Using Support Vector Regression
Predicting Stock Market Price Using Support Vector Regression
Chittagong Independent University
 
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML ToolkitAugmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
Databricks
 
Like-for-Like Comparisons of Machine Learning Algorithms - Dominik Dahlem, Bo...
Like-for-Like Comparisons of Machine Learning Algorithms - Dominik Dahlem, Bo...Like-for-Like Comparisons of Machine Learning Algorithms - Dominik Dahlem, Bo...
Like-for-Like Comparisons of Machine Learning Algorithms - Dominik Dahlem, Bo...
WithTheBest
 
Firefly exact MCMC for Big Data
Firefly exact MCMC for Big DataFirefly exact MCMC for Big Data
Firefly exact MCMC for Big Data
Gianvito Siciliano
 

Similar to Hidden Markov Model & Stock Prediction (20)

Logistic Regression using Mahout
Logistic Regression using MahoutLogistic Regression using Mahout
Logistic Regression using Mahout
 
Hidden Markov Model (HMM).pptx
Hidden Markov Model (HMM).pptxHidden Markov Model (HMM).pptx
Hidden Markov Model (HMM).pptx
 
Differential Machine Learning Masterclass
Differential Machine Learning MasterclassDifferential Machine Learning Masterclass
Differential Machine Learning Masterclass
 
Hidden Markov Model (HMM)
Hidden Markov Model (HMM)Hidden Markov Model (HMM)
Hidden Markov Model (HMM)
 
Mining Big Data Streams with APACHE SAMOA
Mining Big Data Streams with APACHE SAMOAMining Big Data Streams with APACHE SAMOA
Mining Big Data Streams with APACHE SAMOA
 
ANN ARIMA Hybrid Models for Time Series Prediction
ANN ARIMA Hybrid Models for Time Series PredictionANN ARIMA Hybrid Models for Time Series Prediction
ANN ARIMA Hybrid Models for Time Series Prediction
 
AutoML lectures (ACDL 2019)
AutoML lectures (ACDL 2019)AutoML lectures (ACDL 2019)
AutoML lectures (ACDL 2019)
 
iterativealgorithms.ppsx
iterativealgorithms.ppsxiterativealgorithms.ppsx
iterativealgorithms.ppsx
 
Iterative Algorithms.ppsx
Iterative Algorithms.ppsxIterative Algorithms.ppsx
Iterative Algorithms.ppsx
 
Mining big data streams with APACHE SAMOA by Albert Bifet
Mining big data streams with APACHE SAMOA by Albert BifetMining big data streams with APACHE SAMOA by Albert Bifet
Mining big data streams with APACHE SAMOA by Albert Bifet
 
StackNet Meta-Modelling framework
StackNet Meta-Modelling frameworkStackNet Meta-Modelling framework
StackNet Meta-Modelling framework
 
Equirs: Explicitly Query Understanding Information Retrieval System Based on Hmm
Equirs: Explicitly Query Understanding Information Retrieval System Based on HmmEquirs: Explicitly Query Understanding Information Retrieval System Based on Hmm
Equirs: Explicitly Query Understanding Information Retrieval System Based on Hmm
 
Different Models Used In Time Series - InsideAIML
Different Models Used In Time Series - InsideAIMLDifferent Models Used In Time Series - InsideAIML
Different Models Used In Time Series - InsideAIML
 
Applications of Machine Learning in High Frequency Trading
Applications of Machine Learning in High Frequency TradingApplications of Machine Learning in High Frequency Trading
Applications of Machine Learning in High Frequency Trading
 
HMM (Hidden Markov Model)
HMM (Hidden Markov Model)HMM (Hidden Markov Model)
HMM (Hidden Markov Model)
 
de Valpine NIMBLE
de Valpine NIMBLEde Valpine NIMBLE
de Valpine NIMBLE
 
Predicting Stock Market Price Using Support Vector Regression
Predicting Stock Market Price Using Support Vector RegressionPredicting Stock Market Price Using Support Vector Regression
Predicting Stock Market Price Using Support Vector Regression
 
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML ToolkitAugmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
 
Like-for-Like Comparisons of Machine Learning Algorithms - Dominik Dahlem, Bo...
Like-for-Like Comparisons of Machine Learning Algorithms - Dominik Dahlem, Bo...Like-for-Like Comparisons of Machine Learning Algorithms - Dominik Dahlem, Bo...
Like-for-Like Comparisons of Machine Learning Algorithms - Dominik Dahlem, Bo...
 
Firefly exact MCMC for Big Data
Firefly exact MCMC for Big DataFirefly exact MCMC for Big Data
Firefly exact MCMC for Big Data
 

More from David Chiu

無中生有 - 利用外部數據打造新商業模式
無中生有 - 利用外部數據打造新商業模式無中生有 - 利用外部數據打造新商業模式
無中生有 - 利用外部數據打造新商業模式
David Chiu
 
洞見未來,用python 與 r 結合深度學習技術預測趨勢
洞見未來,用python 與 r 結合深度學習技術預測趨勢洞見未來,用python 與 r 結合深度學習技術預測趨勢
洞見未來,用python 與 r 結合深度學習技術預測趨勢
David Chiu
 
python 實戰資料科學工作坊
python 實戰資料科學工作坊python 實戰資料科學工作坊
python 實戰資料科學工作坊
David Chiu
 
新聞 X 謊言 用文字探勘挖掘財經新聞沒告訴你的真相(丘祐瑋)
新聞 X 謊言 用文字探勘挖掘財經新聞沒告訴你的真相(丘祐瑋)新聞 X 謊言 用文字探勘挖掘財經新聞沒告訴你的真相(丘祐瑋)
新聞 X 謊言 用文字探勘挖掘財經新聞沒告訴你的真相(丘祐瑋)
David Chiu
 
Data Analysis - Making Big Data Work
Data Analysis - Making Big Data WorkData Analysis - Making Big Data Work
Data Analysis - Making Big Data Work
David Chiu
 
PyCon APAC 2014 - Social Network Analysis Using Python (David Chiu)
PyCon APAC 2014 - Social Network Analysis Using Python (David Chiu)PyCon APAC 2014 - Social Network Analysis Using Python (David Chiu)
PyCon APAC 2014 - Social Network Analysis Using Python (David Chiu)
David Chiu
 
Big Data Analysis With RHadoop
Big Data Analysis With RHadoopBig Data Analysis With RHadoop
Big Data Analysis With RHadoop
David Chiu
 
Social Network Analysis With R
Social Network Analysis With RSocial Network Analysis With R
Social Network Analysis With R
David Chiu
 
Machine Learning With R
Machine Learning With RMachine Learning With R
Machine Learning With R
David Chiu
 
R language tutorial
R language tutorialR language tutorial
R language tutorial
David Chiu
 

More from David Chiu (10)

無中生有 - 利用外部數據打造新商業模式
無中生有 - 利用外部數據打造新商業模式無中生有 - 利用外部數據打造新商業模式
無中生有 - 利用外部數據打造新商業模式
 
洞見未來,用python 與 r 結合深度學習技術預測趨勢
洞見未來,用python 與 r 結合深度學習技術預測趨勢洞見未來,用python 與 r 結合深度學習技術預測趨勢
洞見未來,用python 與 r 結合深度學習技術預測趨勢
 
python 實戰資料科學工作坊
python 實戰資料科學工作坊python 實戰資料科學工作坊
python 實戰資料科學工作坊
 
新聞 X 謊言 用文字探勘挖掘財經新聞沒告訴你的真相(丘祐瑋)
新聞 X 謊言 用文字探勘挖掘財經新聞沒告訴你的真相(丘祐瑋)新聞 X 謊言 用文字探勘挖掘財經新聞沒告訴你的真相(丘祐瑋)
新聞 X 謊言 用文字探勘挖掘財經新聞沒告訴你的真相(丘祐瑋)
 
Data Analysis - Making Big Data Work
Data Analysis - Making Big Data WorkData Analysis - Making Big Data Work
Data Analysis - Making Big Data Work
 
PyCon APAC 2014 - Social Network Analysis Using Python (David Chiu)
PyCon APAC 2014 - Social Network Analysis Using Python (David Chiu)PyCon APAC 2014 - Social Network Analysis Using Python (David Chiu)
PyCon APAC 2014 - Social Network Analysis Using Python (David Chiu)
 
Big Data Analysis With RHadoop
Big Data Analysis With RHadoopBig Data Analysis With RHadoop
Big Data Analysis With RHadoop
 
Social Network Analysis With R
Social Network Analysis With RSocial Network Analysis With R
Social Network Analysis With R
 
Machine Learning With R
Machine Learning With RMachine Learning With R
Machine Learning With R
 
R language tutorial
R language tutorialR language tutorial
R language tutorial
 

Recently uploaded

State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 

Recently uploaded (20)

State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 

Hidden Markov Model & Stock Prediction

  • 1. HMM & Stock Prediction David Chiu @ ML/DM Monday http://ywchiu-tw.appspot.com/
  • 2. HIDDEN MARKOV MODEL • Finite state machine which has some fixed number of states • Provides a probabilistic framework for modeling a time series of multivariate observations
  • 4. Every time history repeats itself • Stock behavior of past is similar to behavior of current day • The Next day’s stock price should follow about the same past data pattern
  • 5. BENEFIT OF USING HMM • Handle new data robustly • Computationally efficient to develop and evaluate • Able to predict similar patterns efficiently
  • 6. HMM ON STOCK PREDICTION • Using the trained HMM, likelihood value P for current day’s dataset is calculated • From the past dataset using the HMM we locate those instances that would produce the nearest P likelihood value.
  • 7. CHARACTERIZE HMM • Number of states in the model: N • Number of observation symbols: M • Transition matrix A = {aij} , where aij represents the transition probability from state i to state j • Observation emission matrix B = {bj(Ot)} , where bj(Ot) represent the probability of observing Ot at state j • Initial state distribution π = {πi}
  • 9.
  • 10. PROBLEM OF HMM 1. The Evaluation Problem - Forward – What is the probability that the given observations O = o1 ,o2 ,...,oT are generated by the model p{O|λ} with a given HMM λ ? 1. The Decoding Problem - Viterbi – What is the most likely state sequence in the given model λ that produced the given observations O = o1 ,o2 ,...,oT ? 1. The Learning Problem - Baum-Welch – How should we adjust the model parameters {A,B,π } in order to maximize p{O|λ} , whereat a model λ and a sequence of observations O = o1 ,o2 ,...,oT are given?
  • 11. BAUM-WELCH ALGORITHM • Find the unknown parameters of a hidden Markov model(HMM). • Generalized expectation-maximization (GEM) algorithm • Compute maximum likelihood estimates and posterior mode estimates for the parameters (transition and emission probabilities) of an HMM, when given only emissions as training data.
  • 13. TOOL KIT • R Package – HMM – RHMM • JAVA – JHMM • Python – Scikit Learn
  • 14. DEMO
  • 15. GET DATASET • library(quantmod) • getSymbols("^TWII") • chartSeries(TWII) • TWII_Subset<- window(TWII, start = as.Date("2012-01-01")) • TWII_Train <- cbind(TWIISubset$TWII.Close - TWII_Subset$TWII.Open, TWII_Subset$TWII.Volume)
  • 16. BUILD HMM MODEL # Include RHMM Library •library(RHmm) # Baum-Welch Algorithm •hm_model <- HMMFit(obs =TWII_Train , nStates = 5) # Viterbi Algorithm •VitPath <- viterbi(hm_model, TWII_Train)
  • 17. SCATTER PLOT • TWII_Predict <- cbind(TWII_Subset$TWII.Close, VitPath$states) • chartSeries(TWII_Predict[,1]) • addTA(TWII_Predict[TWII_Predict[,2]==1,1],on=1,type="p",col=5,pch=25) • addTA(TWII_Predict[TWII_Predict[,2]==2,1],on=1,type="p",col=6,pch=24) • addTA(TWII_Predict[TWII_Predict[,2]==3,1],on=1,type="p",col=7,pch=23) • addTA(TWII_Predict[TWII_Predict[,2]==4,1],on=1,type="p",col=8,pch=22) • addTA(TWII_Predict[TWII_Predict[,2]==5,1],on=1,type="p",col=10,pch=21)
  • 19. SCIKIT LEARN #Baum-Welch Algorithm •n_components = 5 •model = GaussianHMM(n_components, "diag") •model.fit([X], n_iter=1000) # predict the optimal sequence of internal hidden state •hidden_states = model.predict(X)
  • 22.
  • 23. PREDICTION #State Prediction – using Scikit-learn •data_vec = [diff[last_day], volume[last_day]] •State = model.predict([data_vec])
  • 24. REFERENCE • Hassan, M. (2009). A combination of hidden Markov model and fuzzy model for stock market forecasting. Neurocomputing, 72(16), 3439-3446. • Gupta, A., & Dhingra, B. (2012, March). Stock Market Prediction Using Hidden Markov Models. In Engineering and Systems (SCES), 2012 Students Conference on (pp. 1-4). IEEE.

Editor's Notes

  1. Transition matrix [[ 8.11812291e-01 2.64161406e-18 3.52349878e-02 2.81734681e-02 1.24779253e-01] [ 8.14457640e-18 9.18502509e-01 8.14974906e-02 8.07189607e-18 8.78456355e-18] [ 2.00105290e-02 2.44748522e-02 8.98883560e-01 2.65606045e-18 5.66310587e-02] [ 4.34984913e-07 3.52347211e-18 3.73302534e-18 8.62880547e-01 1.37119018e-01] [ 3.54215900e-01 6.07265466e-18 6.95345225e-02 1.44955842e-01 4.31293736e-01]] means and vars of each hidden state 0th hidden state mean = [ 6.47102406e+00 1.77594314e+06] var = [ 2.08576453e+03 2.84056347e+10] 1th hidden state mean = [ 3.58949104e+01 3.52922834e+06] var = [ 6.49509351e+03 3.01606472e+11] 2th hidden state mean = [ 8.00347774e+00 2.38896636e+06] var = [ 2.97831204e+03 1.13694938e+11] 3th hidden state mean = [ -1.56406476e+01 1.42048949e+06] var = [ 2.74139080e+03 2.90272908e+10] 4th hidden state mean = [ -7.67653562e+00 2.03930314e+06] var = [ 1.46905928e+04 2.24122434e+11]