simulate the two contracts into the futurenp random seed( walk (np random randint( size= perturb (np random randint( size= walk walk cumsum(rng pd date_range(px index[ ]periods=len(pxnfreq=' 'near np concatenate([px valuespx values[- walk]far np concatenate([px valuespx values[- walk perturb]prices dataframe({'esu 'near'esz 'far}index=rngprices then has two time series for the contracts that differ from each other by random amountin [ ]prices tail(out[ ]esu esz one way to splice time series together into single continuous series is to construct weighting matrix active contracts would have weight of until the expiry date approaches at that point you have to decide on roll convention here is function that computes weighting matrix with linear decay over number of periods leading up to expirydef get_roll_weights(startexpiryitemsroll_periods= )start first date to compute weighting dataframe expiry series of ticker -expiration dates items sequence of contract names dates pd date_range(startexpiry[- ]freq=' 'weights dataframe(np zeros((len(dates)len(items)))index=datescolumns=itemsprev_date weights index[ for (itemex_datein enumerate(expiry iteritems())if len(expiry weights ix[prev_date:ex_date pd offsets bday()item roll_rng pd date_range(end=ex_date pd offsets bday()periods=roll_periods freq=' 'decay_weights np linspace( roll_periods weights ix[roll_rngitem decay_weights weights ix[roll_rngexpiry index[ ]decay_weights elseweights ix[prev_date:item prev_date ex_date more example applications www it-ebooks info