This web page illustrates a stochastic price process and one way to generate a transition probability matrix.   
Peter Lohmander 99-10-26
http://www.sekon.SLU.se/~PLO

The program below is written in Qbasic (which is a version of the language Basic).
 

----------------------------------------------------------------------------------
REM Program Slumpp1.bas
REM Lohmander Peter 99-10-26

DIM tt(10, 10), trp(10, 10)
DIM p(10000)
CLS

INPUT " Horizon = "; horizon
INPUT "Do you want to see all prices? (0 = no, yes = 1)"; answer

a = 16.50747
b = .8667586
pekv = a / (1 - b)
stdev = 24.2353
p(0) = pekv

PRINT "Equilibrium price = "; pekv

  FOR t = 1 TO horizon
  eps = 0
  FOR i = 1 TO 12
  eps = eps + RND
  NEXT i
  eps = eps - 6
  p(t) = a + b * p(t - 1) + stdev * eps
  IF answer = 1 THEN PRINT p(t)
  NEXT t
 

FOR i = 1 TO 10
FOR j = 1 TO 10
tt(i, j) = 0
NEXT j
NEXT i
 

FOR t = 1 TO horizon
p0 = p(t - 1)
p1 = p(t)
p0kat = p0 / 40
pokat = INT(p0kat) + 1
p1kat = p1 / 40
p0kat = INT(p0kat) + 1
IF p0kat < 1 OR p0kat > 10 THEN GOTO 1
IF p1kat < 1 OR p1kat > 10 THEN GOTO 1
tt(p0kat, p1kat) = tt(p0kat, p1kat) + 1
1 NEXT t
 

INPUT x
PRINT ""
PRINT " Numbers of transitions from different P(t) to P(t+1) = "
PRINT ""
FOR i = 1 TO 10
FOR j = 1 TO 10
PRINT USING "#####"; tt(i, j);
NEXT j
PRINT ""
NEXT i
 

FOR i = 1 TO 10
sum = 0
FOR j = 1 TO 10
sum = sum + tt(i, j)
NEXT j
FOR j = 1 TO 10
IF sum > 0 THEN trp(i, j) = tt(i, j) / sum
NEXT j
NEXT i
 

INPUT x
PRINT ""
PRINT " Transition probability matrix = "
FOR i = 1 TO 10
FOR j = 1 TO 10
PRINT USING "###.###"; trp(i, j);
NEXT j
PRINT ""
NEXT i

------------------------------------------------------------------------------

Welcome to the home page of Peter Lohmander: http://www.sekon.SLU.se/~PLO