Page 1 of 1

Problem when programming with python in EVIEWS 12

Posted: Wed Mar 23, 2022 8:47 am
by francisco
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 7155 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

Re: Problem when programming with python in EVIEWS 12

Posted: Sat Mar 26, 2022 4:45 pm
by EViews Steve
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.

Re: Problem when programming with python in EVIEWS 12

Posted: Sat Mar 26, 2022 7:26 pm
by francisco
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 7103 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 7103 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 7103 times
As you can see, the code runs in Python environment time_series, but not when I want to run from EVIEWS 12.

Re: Problem when programming with python in EVIEWS 12

Posted: Sat Mar 26, 2022 8:14 pm
by EViews Steve
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.

Re: Problem when programming with python in EVIEWS 12

Posted: Sat Mar 26, 2022 9:04 pm
by francisco
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 7091 times

Re: Problem when programming with python in EVIEWS 12

Posted: Tue Mar 29, 2022 10:04 am
by EViews Steve
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 7019 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 7019 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

Re: Problem when programming with python in EVIEWS 12

Posted: Tue Mar 29, 2022 11:20 am
by francisco
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

Re: Problem when programming with python in EVIEWS 12

Posted: Tue Mar 29, 2022 1:49 pm
by EViews Gareth
Would you mind mentioning which machine learning models you're using? (in case we want to add them :) )

Re: Problem when programming with python in EVIEWS 12

Posted: Tue Mar 29, 2022 2:23 pm
by francisco
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