

.. _example_plot_hmm_stock_analysis.py:


==========================
Gaussian HMM of stock data
==========================

This script shows how to use Gaussian HMM.
It uses stock price data, which can be obtained from yahoo finance.
For more information on how to get stock prices with matplotlib, please refer
to date_demo1.py of matplotlib.



.. image:: images/plot_hmm_stock_analysis_1.png
    :align: center


**Script output**::

  fitting to HMM and decoding ... done
  
  Transition matrix
  [[  9.97761569e-01   4.97053978e-19   4.97089098e-19   2.23843130e-03
      4.97053978e-19]
   [  1.74235938e-19   9.82557270e-01   1.11564158e-08   7.43730006e-03
      1.00054191e-02]
   [  5.85230060e-19   2.18990972e-11   9.87965523e-01   2.81780865e-03
      9.21666821e-03]
   [  2.08117603e-19   1.08224882e-02   2.13843446e-19   9.89177512e-01
      2.08272727e-19]
   [  1.98906361e-19   9.56865639e-03   4.09034856e-03   4.98498981e-12
      9.86340995e-01]]
  
  means and vars of each hidden state
  0th hidden state
  mean =  [ 0.01462316  5.84129775]
  var =  [ 0.01820163  1.76748846]
  
  1th hidden state
  mean =  [  1.19298040e-02   1.78742328e+01]
  var =  [ 0.09219055  1.13620583]
  
  2th hidden state
  mean =  [  2.02568973e-04   3.80262077e+01]
  var =  [  2.32112875  97.04136892]
  
  3th hidden state
  mean =  [ -2.11501941e-04   1.38887005e+01]
  var =  [ 0.17889126  2.26717048]
  
  4th hidden state
  mean =  [ -1.00939160e-03   2.22554298e+01]
  var =  [ 0.33450692  3.40001933]



**Python source code:** :download:`plot_hmm_stock_analysis.py <plot_hmm_stock_analysis.py>`

.. literalinclude:: plot_hmm_stock_analysis.py
    :lines: 11-
    