简体   繁体   中英

Algorithm to Generate Transition Matrix

Transition Probability is given as

在此处输入图片说明

eg, for one product, when the current price is High, the probability of next period being High Price is 0.3, and being Low price is 0.7.

My question is that for two independent products, what is the transition probability?

I'm looking for some results like the following table:

在此处输入图片说明

eg, given the current price level is H for product 1 and H for product 2, the probability of being L for 1 and H for 2 is 0.7*0.3 = 0.21.

The current code that I am using is the following:

from sklearn.utils.extmath import cartesian
pr = np.array([[0.3,0.7],[0.6,0.4]])
P = np.zeros((4,4))
count = 0
for i in range(2):
    for j in range(2):
        P[count] = cartesian((pr[i],pr[j])).prod(1)
        count += 1
P

It works well for two products, but for more products it would be very confusing. eg For four independent products, the transition matrix is 16*16: for each current state (eg HHHH), there are 16 possible future states, eg (HHHH, HHHL, HHLH, HHLL, HLHH, .... etc)

Is there an easy and clear way to do this?

You are generating a simple markov TM if I am correct.

Now you want to look at what the transition probability is for 1 product, given two others? Am I correct? Well, then you are just going to learn again from the data, but this time, look at each occurance of pairs of data and treat them as an n-gram.

Your matrix is indeed going to get really big, but that shouldn't pose a problem right away.

If you want to look back a big amount of periods, then you might want to consider another technique that can handle timeseries better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM