PyIF

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.

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 price of HP along with IBM to improve your prediction about the future price values of IBM? The answer is yes.

Using Transfer Entropy you can quantify the reduction in uncertainity about IBM’s price tomorrow knowing HPs price today along with IBM’s price.

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

Example

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)
print(TE)

Learn more about PyIF