Problem when programming with python in EVIEWS 12

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

francisco
Posts: 27
Joined: Fri Jan 15, 2010 3:50 pm

Problem when programming with python in EVIEWS 12

Postby francisco » Wed Mar 23, 2022 8:47 am

Hi,

I am trying to run the following code in Python from EVIEWS 12

Code: Select all

xopen(p)

xon
   import numpy as np
   import pandas as pd
   import itertools
   from prophet import Prophet
xoff

xon
   param_grid = {"changepoint_prior_scale": [0.001, 0.01, 0.1, 0.5], "seasonality_prior_scale": [0.01, 0.1, 1.0, 10.0]}
xoff

xon
   all_params = [dict(zip(param_grid.keys(), v)) for v in itertools.product(*param_grid.values())]
xoff


however, it sends me the following error

Captura.PNG
Captura.PNG (46 KiB) Viewed 2836 times


The same thing happens to me if I use Python 3.8 or 3.9.

Could you please help me identifying where the error is?

Thanks

Francisco

EViews Steve
EViews Developer
Posts: 788
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: Problem when programming with python in EVIEWS 12

Postby EViews Steve » Sat Mar 26, 2022 4:45 pm

Did you try running the Python commands within Python directly without using EViews? If so, does it give you the same error?

When you do this, make sure you're using the same Python environment that EViews is talking to. EViews does a few things behind the scenes during a Python command, but this usually only done when going an XGET or XPUT call, not when simply running a Python command within XON.

The reason I mention this is because your screenshot is strange in it is showing a Python command (last red line) that isn't in the original EViews program you showed at the top of your post (the line starting with 'all_params ='). Was this line actually in your program and you forgot to include it or did this line just appear out of nowhere?

Finally, I noticed you're using a Python environment under Anaconda. To make sure you have access to all the same Anaconda managed Python libraries, update your EViews 12 to the latest version, then open an Anaconda command prompt, switch/activate to the proper 'time_series' environment, then launch EViews from that same command prompt so that EViews 12 is using the same environment variables that Anaconda sets up. Refer to this previous post that discusses using EViews with Anaconda.

francisco
Posts: 27
Joined: Fri Jan 15, 2010 3:50 pm

Re: Problem when programming with python in EVIEWS 12

Postby francisco » Sat Mar 26, 2022 7:26 pm

Thanks for your response Eviews Steve... I'm going to answer your questions.

Did you try running the Python commands within Python directly without using EViews? If so, does it give you the same error?
YES and is OK
Imagen1.png
Imagen1.png (165.31 KiB) Viewed 2784 times

When you do this, make sure you're using the same Python environment that EViews is talking to. EViews does a few things behind the scenes during a Python command, but this usually only done when going an XGET or XPUT call, not when simply running a Python command within XON.
Yes I using the same Python environment… see pictures below.
The reason I mention this is because your screenshot is strange in it is showing a Python command (last red line) that isn't in the original EViews program you showed at the top of your post (the line starting with 'all_params ='). Was this line actually in your program and you forgot to include it or did this line just appear out of nowhere?
Here is the image with code posted…
Imagen2.png
Imagen2.png (46.45 KiB) Viewed 2784 times

Finally, I noticed you're using a Python environment under Anaconda. To make sure you have access to all the same Anaconda managed Python libraries, update your EViews 12 to the latest version, then open an Anaconda command prompt, switch/activate to the proper 'time_series' environment, then launch EViews from that same command prompt so that EViews 12 is using the same environment variables that Anaconda sets up. Refer to this previous post that discusses using EViews with Anaconda.
Yes, that's how i'm doing it
Imagen3.png
Imagen3.png (18.57 KiB) Viewed 2784 times

As you can see, the code runs in Python environment time_series, but not when I want to run from EVIEWS 12.

EViews Steve
EViews Developer
Posts: 788
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: Problem when programming with python in EVIEWS 12

Postby EViews Steve » Sat Mar 26, 2022 8:14 pm

What's the build date of your EViews 12? Is it the latest version?

I'll try to reproduce the issue on Monday to see if I can figure out what's going on. But usually that Traceback error is something that is being reported by Python and not something internal to EViews. I would try to see if using a generic Python installation behaves differently from the Anaconda one. Perhaps I'm not transferring enough environment variables from EViews to our Python interface to get Anaconda to work entirely.

francisco
Posts: 27
Joined: Fri Jan 15, 2010 3:50 pm

Re: Problem when programming with python in EVIEWS 12

Postby francisco » Sat Mar 26, 2022 9:04 pm

Ok, I really appreciate your help EViews Steve.

This is the version of EVIEWS 12 i have,,,
Captura.PNG
Captura.PNG (144.86 KiB) Viewed 2772 times

EViews Steve
EViews Developer
Posts: 788
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: Problem when programming with python in EVIEWS 12

Postby EViews Steve » Tue Mar 29, 2022 10:04 am

After some extensive testing, I believe this error is being caused by our Python interface not supporting for loops, such as this:

Code: Select all

xon
letters = ['a','b','c']
for x in letters
   print(x)
xoff

Even if you were to place all the lines of a for loop into a single line, like this:

Code: Select all

xon
letters = ['a','b','c']
for x in letters: print(x)
xoff

You would still get an error when trying to run it thru our Python interface:
2022-03-29_09h40_33.png
2022-03-29_09h40_33.png (2.43 KiB) Viewed 2700 times

One possibility is to use an EXEC command for the single-line for loop, like this:

Code: Select all

xon
letters = ['a','b','c']
exec('for x in letters: print(x)')
xoff

which results in this:
2022-03-29_09h58_24.png
2022-03-29_09h58_24.png (1.8 KiB) Viewed 2700 times

But using this method with your final command line didn't work, most likely due to the strange way the for loop is being used. Instead, I got the following to generate the same all_params value:

Code: Select all

xon
   param_grid = {"changepoint_prior_scale": [0.001, 0.01, 0.1, 0.5], "seasonality_prior_scale": [0.01, 0.1, 1.0, 10.0]}
   all_params = []
   exec('for v in itertools.product(*param_grid.values()):    all_params.append(dict(zip(param_grid.keys(), v)))')
xoff

Steve

francisco
Posts: 27
Joined: Fri Jan 15, 2010 3:50 pm

Re: Problem when programming with python in EVIEWS 12

Postby francisco » Tue Mar 29, 2022 11:20 am

Thanks Steve,

I did what you say and it works... from now on I'll use the exec function when I have similar problems.

I usually program in python using Eviews to import machine learning models that are not in Eviews, and what you just told me helps me a lot.

Francisco

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

Re: Problem when programming with python in EVIEWS 12

Postby EViews Gareth » Tue Mar 29, 2022 1:49 pm

Would you mind mentioning which machine learning models you're using? (in case we want to add them :) )
Follow us on Twitter @IHSEViews

francisco
Posts: 27
Joined: Fri Jan 15, 2010 3:50 pm

Re: Problem when programming with python in EVIEWS 12

Postby francisco » Tue Mar 29, 2022 2:23 pm

Machine learning and deep learning models useful for forecasting time series, such as NnetAR, Prophet and NeuralProphet models, and models in the GluonTS library such as DeepAR, N-Beats, LSTM and the LigthGBM models.

I also use Python or R programming for feature engineering tasks.

If EVIEWS could run any of these models internally I would be very happy.

Francisco


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 17 guests