of each contract for exampleat any given time for type of future (say silver or copper futuresmultiple contracts with different expiration dates may be traded in many casesthe future contract expiring next (the near contractwill be the most liquid (highest volume and lowest bid-ask spreadfor the purposes of modeling and forecastingit can be much easier to work with continuous return index indicating the profit and loss associated with always holding the near contract transitioning from an expiring contract to the next (or farcontract is referred to as rolling computing continuous future series from the individual contract data is not necessarily straightforward exercise and typically requires deeper understanding of the market and how the instruments are traded for examplein practice when and how quickly would you trade out of an expiring contract and into the next contracthere describe one such process firsti'll use scaled prices for the spy exchange-traded fund as proxy for the & indexin [ ]import pandas io data as web approximate price of & index in [ ]px web get_data_yahoo('spy')['adj close' in [ ]px out[ ]date nameadj closelength nowa little bit of setup put couple of & future contracts and expiry dates in seriesfrom datetime import datetime expiry {'esu 'datetime( )'esz 'datetime( )expiry series(expiryorder(expiry then looks likein [ ]expiry out[ ]esu : : esz : : financial and economic data applications www it-ebooks info