I have some code that uses a for / next loop that takes a list of stock tickers and fetches some data from Bloomberg (MY CURRENT CODE shown below). It works well, but it would be much better if I did not have to open the program and change out the tickers in the body of the code each time the list of stocks changes. It would be very much better to put up a UI box and allow the user to enter in a list of tickers (IBM PG CAT).
My first attempt was to modify some of Gareth's code from the forum (below) and try to substitute %i after "for" in my current code. %i would be the variable that would hold the list of tickers supplied by the user. I assumed the resulting code would insert the user supplied tickers in place of "IBM PG CAT" and run the for next loop as it would when I enter the tickers directly into the code after %i. But this did not happen. Instead, I got an error "Syntax error in control statement in "FOR """ on line XX."
Could someone help me figure out what I've done wrong?
Many thanks!
MY CURRENT CODE:
for %i IBM PG CAT etc...
%name = %i + " US Equity"
fetch(link) bloom::%name 'Historic Price
stocks_price_gp.add {%i}_US
frml {%i}_rtn = ({%i}_US/{%i}_US(-1) - 1) * 100
stocks_rtn_gp.add {%i}_rtn
frml {%i}_excess = {%i}_rtn - tbill_rtn
if @obs({%i}_excess) > 0 then
stocks_excess_gp.add {%i}_excess
endif
next
GARETH'S CODE (Modified by me):
%i = "" 'variable to store list of stocks
!result = 0 ' variable that will track the result of dialogs. -1 indicates user hit Cancel. 0 Indicates user hit OK.
!result = @uiedit(%regs,"Enter the list of stocks") ' put up an Edit dialog asking for regressors list.
if !result=-1 then 'if user cancelled, then stop program
stop
endif
UI Dialog Question
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13401
- Joined: Tue Sep 16, 2008 5:38 pm
Re: UI Dialog Question
%name = %i + " US Equity"
Re: UI Dialog Question
FYI:
I just realized that in my MODIFIED GARETH code, I neglected to change the "%reg" to "%i" in the following line:
!result = @uiedit(%reg,"Enter the list of stocks")
!result = @uiedit(%i,"Enter the list of stocks") <== FIXED
BUT...
I still get the same error, even though I changed "%reg" to "%i"...
Hmmmm?
I just realized that in my MODIFIED GARETH code, I neglected to change the "%reg" to "%i" in the following line:
!result = @uiedit(%reg,"Enter the list of stocks")
!result = @uiedit(%i,"Enter the list of stocks") <== FIXED
BUT...
I still get the same error, even though I changed "%reg" to "%i"...
Hmmmm?
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13401
- Joined: Tue Sep 16, 2008 5:38 pm
Re: UI Dialog Question
Sorry, I'm struggling to follow what the issue is. Could you post an example that causes the error?
Follow us on Twitter @IHSEViews
Re: UI Dialog Question
Here is a simplified excerpt from the code. When I run it, a UI dialog box opens asking for a list of stocks. I enter "CAT IBM PG", for example, in the UI box. Then, I expect the code to take each ticker that is stored in "%i" from the user supplied input and loop those stocks through the for next loop, fetching prices from Bloomberg. But I am getting this error:
"Syntax error in control statement in "FOR "CAT IBM PG"" on line 65." WHERE LINE 65 is "for %i"
%i = "" 'variable to store list of stocks
!result = 0 ' variable that will track the result of dialogs. -1 indicates user hit Cancel. 0 Indicates user hit OK.
!result = @uiedit(%i,"Enter the list of stocks") ' put up an Edit dialog asking for regressors list.
if !result=-1 then 'if user cancelled, then stop program
stop
endif
for %i
%name = %i + " US Equity"
fetch(link) bloom::%name 'Pull historic prices from Bloomberg
endif
next
"Syntax error in control statement in "FOR "CAT IBM PG"" on line 65." WHERE LINE 65 is "for %i"
%i = "" 'variable to store list of stocks
!result = 0 ' variable that will track the result of dialogs. -1 indicates user hit Cancel. 0 Indicates user hit OK.
!result = @uiedit(%i,"Enter the list of stocks") ' put up an Edit dialog asking for regressors list.
if !result=-1 then 'if user cancelled, then stop program
stop
endif
for %i
%name = %i + " US Equity"
fetch(link) bloom::%name 'Pull historic prices from Bloomberg
endif
next
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13401
- Joined: Tue Sep 16, 2008 5:38 pm
Re: UI Dialog Question
Code: Select all
%i = "" 'variable to store list of stocks
!result = 0 ' variable that will track the result of dialogs. -1 indicates user hit Cancel. 0 Indicates user hit OK.
!result = @uiedit(%i,"Enter the list of stocks") ' put up an Edit dialog asking for regressors list.
if !result=-1 then 'if user cancelled, then stop program
stop
endif
for %j {%i}
%name = %j + " US Equity"
fetch(link) bloom::%name 'Pull historic prices from Bloomberg
endif
next
Follow us on Twitter @IHSEViews
Re: UI Dialog Question
This works great!
Many thanks!
Many thanks!
Re: UI Dialog Question
Gareth,
Thank you for your help with this UI dialog question from a week ago. It works, but only to a point.
It seems that the UI dialog only accepts a limited number of characters. The list of tickers I need to input is quite long, so most of the list gets truncated when I enter them into the UI dialog.
Is there a workaround for this?
Many thanks!
KC
Thank you for your help with this UI dialog question from a week ago. It works, but only to a point.
It seems that the UI dialog only accepts a limited number of characters. The list of tickers I need to input is quite long, so most of the list gets truncated when I enter them into the UI dialog.
Is there a workaround for this?
Many thanks!
KC
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13401
- Joined: Tue Sep 16, 2008 5:38 pm
Re: UI Dialog Question
Follow us on Twitter @IHSEViews
Who is online
Users browsing this forum: Bing [Bot] and 2 guests