Have ideas to improve npm?Join in the discussion! »

    markov-chain

    0.0.2 • Public • Published

    markov-chain

    Calculate the probability of the next transition state using Markov Chains.

    NPM

    Demo

    https://lab.miguelmota.com/markov-chain

    Install

    npm install markov-chain
    bower install markov-chain

    Usage

    In this example, we calculate the probability of the next state for bull, bear, and stagnant markets.

    State diagram from Wikipedia

    State Diagram

    var MarkovChain = require('markov-chain');
     
    var markovChain = MarkovChain();
     
    markovChain.setInitialStateVector([0, 1, 0]); // bull, bear, stagnant
    markovChain.setTransitionMatrix([
      [0.9, 0.075, 0.025],
      [0.15, 0.8, 0.05],
      [0.25, 0.25, 0.5]
    ]);
     
    console.log(markovChain.nextStateProbability()); // [0.15, 0.8, 0.05]
    console.log(markovChain.nextStateProbability()); // [0.2675, 0.6637500000000001, 0.06875]
    console.log(markovChain.nextStateProbability()); // [0.35750000000000004, 0.56825, 0.07425000000000001]
    console.log(markovChain.getIterationsCount()); // 3
    console.log(markovChain.getCurrentStateVector()); // [0.35750000000000004, 0.56825, 0.07425000000000001]
     
    console.log(markovChain.probabilityAtState(2)); // [0.2675, 0.6637500000000001, 0.06875]
    console.log(markovChain.getIterationsCount()); // 2

    License

    MIT

    Install

    npm i markov-chain

    DownloadsWeekly Downloads

    3

    Version

    0.0.2

    License

    MIT

    Last publish

    Collaborators

    • avatar