PyIF is an open source implementation to compute bi-variate Transfer Entropy. You may be asking yourself what is Transfer Entropy and why should care about it?

Well imagine you want to predict the stock price of IBM tomorrow. Well you could simply guess, the price. An elegant solution would involve you using the past prices of IBM to make a prediction because there is information from the previous prices. This information can be quantified using measures from Information Theory.

However what if the price information from other companies in the same industry as IBM could help improve the accuracy of your prediction? Put simply what if you know the price of another stock such as HP. Is it possible to use the stock prices of HP along with IBM to make a prediction about the future price values of IBM? The answer is yes.

Using Transfer Entropy you can quantify the transfer of information between HP and IBM to aid in your prediction. To put it simply Transfer Entropy is a time asymmetric measure between the transfer of information between dynamic processes (where stock price is an example of a dynamic process).

PyIF can be used to compute transfer entropy between 2 dynamic processes.


The code snippet below generates 1000 random observations 2 times. Then Transfer Entropy is estimated using the 2 random observations.

from PyIF import te_compute as te
import numpy as np
rand = np.random.RandomState(seed=23)

X_1000 = rand.randn(1000, 1).flatten()
Y_1000 = rand.randn(1000, 1).flatten()

TE = te.te_compute(X_1000, Y_1000, k=1, embedding=1, safetyCheck=True, GPU=False)

Learn more about PyIF