Package: pyeviews
The purpose of thepyeviewspackage is to make it easier forEViewsand Python to talk to each other, so Python programmers can use the econometric engine of EViews directly from Python.  This package uses COM to transfer data between Python and EViews.  (For more information on COM and EViews, take a look at ourwhitepaper on the subject.)Here’s a simple example going from Python to EViews.  We’re going to use the popular Chow-Lin interpolation routine in EViews using data created in Python.  Chow-Lin interpolation is a regression-based technique to transform low-frequency data (in our example, annual) into higher-frequency data (in our example, quarterly).  It has the ability to use a higher-frequency series as a pattern for the interpolated series to follow.   The quarterly interpolated series is chosen to match the annual benchmark series in one of four ways: first (the first quarter value of the interpolated series matches the annual series), last (same, but for the fourth quarter value), sum (the sum of the first through fourth quarters matches the annual series), and average (the average of the first through fourth quarters matches the annual series).We’re going to create two series in Python using the time series functionality of thepandaspackage, transfer it to EViews, perform Chow-Lin interpolation on our series, and bring it back into Python.  The data are taken from[BLO2001]in an example originally meant for Denton interpolation.Install thepyeviewspackage using your method of choice.  For example, head over to thepyeviewspackageat thePython Package Indexand at a Windows command prompt:$ pip install pyeviewsOr, download the package, navigate to your installation directory, and use:$ python setup.py installFor more details on installation, see ourwhitepaper.Start python and create two time series using pandas.  We’ll call the annual series “benchmark” and the quarterly series “indicator”:>>>importnumpyasnp>>>importpandasaspa>>>dtsa=pa.date_range('1998',periods=3,freq='A')>>>benchmark=pa.Series([4000.,4161.4,np.nan],index=dtsa,name='benchmark')>>>dtsq=pa.date_range('1998q1',periods=12,freq='Q')>>>indicator=pa.Series([98.2,100.8,102.2,100.8,99.,101.6,102.7,101.5,100.5,103.,103.5,101.5],index=dtsq,name='indicator')Load thepyeviewspackage and create a custom COM application object so we can customize our settings.  Setshowwindow(which displays the EViews window) to True.  Then call thePutPythonAsWFfunction to create pages for the benchmark and indicator series:>>>importpyeviewsasevp>>>eviewsapp=evp.GetEViewsApp(instance='new',showwindow=True)>>>evp.PutPythonAsWF(benchmark,app=eviewsapp)>>>evp.PutPythonAsWF(indicator,app=eviewsapp,newwf=False)Behind the scenes,pyeviewswill detect if the DatetimeIndex of yourpandasobject (if you have one) needs to be adjusted to match EViews’ dating customs.  Since EViews assigns dates to be the beginning of a given period depending on the frequency, this can lead to misalignment issues and unexpected results when calculations are performed.  For example, a DatetimeIndex with an annual ‘A’ frequency and a date of 2000-12-31 will be assigned an internal EViews date of 2000-12-01.  In this case,pyeviewswill adjust the date to 2000-01-01 before pushing the data to EViews.Name the pages of the workfile:>>>evp.Run('pageselect Untitled',app=eviewsapp)>>>evp.Run('pagerename Untitled annual',app=eviewsapp)>>>evp.Run('pageselect Untitled1',app=eviewsapp)>>>evp.Run('pagerename Untitled1 quarterly',app=eviewsapp)Use the EViewscopycommand to copy the benchmark series in the annual page to the quarterly page, using the indicator series in the quarterly page as the high-frequency indicator and matching the sum of the benchmarked series for each year (four quarters) with the matching annual value of the benchmark series:>>>evp.Run('copy(rho=.7, c=chowlins) annual\\benchmark quarterly\\benchmarked @indicator indicator',app=eviewsapp)Bring the new series back into Python:>>>benchmarked=evp.GetWFAsPython(app=eviewsapp,pagename='quarterly',namefilter='benchmarked')>>>print(benchmarked)BENCHMARKED1998-01-01867.4214291998-04-011017.2928571998-07-011097.9928571998-10-011017.2928571999-01-01913.5357141999-04-011063.4071431999-07-011126.8142861999-10-011057.6428572000-01-011000.0000002000-04-011144.1071432000-07-011172.9285712000-10-011057.642857Release the memory allocated to the COM process (this does not happen automatically in interactive mode):>>>eviewsapp.Hide()>>>eviewsapp=None>>>evp.Cleanup()Note that if you choose not to create a custom COM application object (theGetEViewsAppfunction), you won’t need to use the first two lines in the last step.  You only need to callCleanup().  If you create a custom object but choose not to show it, you won’t need to use the first line (theHide()function).If you want, plot everything to see how the interpolated series follows the indicator series:>>># load the matplotlib package to plotimportmatplotlib.pyplotasplt>>># reindex the benchmarked series to the end of the quarter so the dates match those of the indicator seriesbenchmarked_reindexed=pa.Series(benchmarked.values.flatten(),index=benchmarked.index+pa.DateOffset(months=3,days=-1))>>># plotfig,ax1=plt.subplots()plt.xticks(rotation=70)ax1.plot(benchmarked_reindexed,'b-',label='benchmarked')# multiply the indicator series by 10 to put it on the same axis as the benchmarked seriesax1.plot(indicator*10,'b--',label='indicator*10')ax1.set_xlabel('dates')ax1.set_ylabel('indicator & interpolated values',color='b')ax1.xaxis.grid(True)fortlinax1.get_yticklabels():tl.set_color('b')plt.legend(loc='lower right')ax2=ax1.twinx()ax2.set_ylim([3975,4180])ax2.plot(benchmark,'ro',label='benchmark')ax2.set_ylabel('benchmark',color='r')fortlinax2.get_yticklabels():tl.set_color('r')plt.legend(loc='upper left')plt.title("Chow-Lin interpolation:\nannual sum of benchmarked = benchmark",fontsize=14)plt.show()For more information on thepyeviewspackage, including a list of functions, please take a look at ourwhitepaperon the subject.References[BLO2001]Bloem, A.M, Dippelsman, R.J. and Maehle, N.O. 2001 Quarterly National Accounts Manual - Concepts, Data Sources, and Compilation. IMF.http://www.imf.org/external/pubs/ft/qna/2000/Textbook/index.htmRequirementsEViews, of coursecomtypes, numpy, and pandas