Look ahead bias - crypto

Hello!
The following code generates look ahead bias while no data is used at all. Can you explain why? :sob:

import alphien
import numpy as np

dtf = alphien.DataFeatures(tickers=alphien.getTickersCryptoSelector(asTickers=True), fields= [“bb_live”,‘OHLC’])
dtf.load(zoom = “2017::2020”)

def mypayoutrandom(dtf):
allocationWeights = alphien.equalWeightCryptoSelect(dtf)
newweights = np.random.sample((4,))
newweights /= (2*np.sum(newweights))
allocationWeights.loc[:, “BTCUSD.bb_live”] = np.array([0.5] * len(allocationWeights))
allocationWeights.loc[:, “ETHUSD.bb_live”] = np.array([newweights[0]] * len(allocationWeights))
allocationWeights.loc[:, “LTCUSD.bb_live”] = np.array([newweights[1]] * len(allocationWeights))
allocationWeights.loc[:, “XRPUSD.bb_live”] = np.array([newweights[2]] * len(allocationWeights))
allocationWeights.loc[:, “USDTUSD.bb_live”] = np.array([newweights[3]] * len(allocationWeights))
return allocationWeights

port = alphien.cryptoPortfolio(alphien.getTickersCryptoSelector(asTickers=True))
port.payout(mypayoutrandom)
port.evaluate(zoom=“2017::2020”)

port.checkCryptoSubmission()

Hi @narcejac,

Running the payout function on dtf twice gives different results.
mypayoutrandom(dtf)
mypayoutrandom(dtf)

There is a reproducibility issue in the payout function. If there is any randomness in your model, a random seed needs to be set. We will be unable to reconcile if the model generates different outputs every time we run it.

Cheers,
reiyun

Using this code:

import alphien
import numpy as np

dtf = alphien.DataFeatures(tickers=alphien.getTickersCryptoSelector(asTickers=True), fields= ['bb_live','OHLC'])
dtf.load(zoom = '2017::2020')

def mypayoutrandom(dtf):
    allocationWeights = alphien.equalWeightCryptoSelect(dtf)
    newweights = np.random.sample((4,))
    newweights /= (2*np.sum(newweights))
    allocationWeights.loc[:, 'BTCUSD.bb_live'] = np.array([0.5] * len(allocationWeights))
    allocationWeights.loc[:, 'ETHUSD.bb_live'] = np.array([newweights[0]] * len(allocationWeights))
    allocationWeights.loc[:, 'LTCUSD.bb_live'] = np.array([newweights[1]] * len(allocationWeights))
    allocationWeights.loc[:, 'XRPUSD.bb_live'] = np.array([newweights[2]] * len(allocationWeights))
    allocationWeights.loc[:, 'USDTUSD.bb_live'] = np.array([newweights[3]] * len(allocationWeights))
    return allocationWeights
1 Like