Ranked Bar Chart

For questions regarding programming in the EViews programming language.

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

GFXFTS
Posts: 42
Joined: Wed Nov 21, 2018 10:33 am

Ranked Bar Chart

Postby GFXFTS » Thu Feb 18, 2021 12:37 pm

Hello, I would like to rank series (ascending or descending) in a bar chart. I have written the attached .prg and created the chart in the attached .wf . However, I don't know how to rank the series according to their size. Is there a function for doing this by chance? Thanks a lot for your help.
Best wishes, Günter
Attachments
test charts.prg
(608 Bytes) Downloaded 199 times
test_chart.wf1
(1.23 MiB) Downloaded 162 times

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

Re: Ranked Bar Chart

Postby EViews Gareth » Thu Feb 18, 2021 2:43 pm

There's an (undocumented yet) new command in EViews 12 that allows you to order the members of a group based on various statistics.

Command capture does work, so to figure out the command you can open the group interactively, click on View->Group Members, then click the Order button on the button bar. Apply a reordering, then look at command capture to see the command equivalent.

Something like this should work:

Code: Select all

G_G10_PCH.reorder(d) @last
Follow us on Twitter @IHSEViews

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

Re: Ranked Bar Chart

Postby EViews Gareth » Thu Feb 18, 2021 2:57 pm

Quick docs:

Reorder Group Procs

Change the order of the series in a group

Syntax
group_name.reorder(options) order_arg

Where order_arg contains a list of the series in the group in their new order, or can contain one of the following keywords:
@rand Randomize the ordering
@reverse Reverse the current order
@mean Order the series by their mean
@max Order the series by their maximum value
@min Order the series by their minimum value
@median Order the series by their median value
@first Order the series by their first value
@last Order the series by their last value
@obs Order the series by the number of non-NA observations in the group



Options
d Sort by descending (default is ascending)



Examples
group gr1 x y z
gr1.reorder z x y

First creates a group containing X, Y and Z and then reorders the group so that the order of the series is now Z, X Y.

gr1.reorder @reverse

changes the order once more to be Y X Z

gr1.reorder(d) @median

reorders the group so that the series are sorted by their median value, descending.
Follow us on Twitter @IHSEViews

GFXFTS
Posts: 42
Joined: Wed Nov 21, 2018 10:33 am

Re: Ranked Bar Chart

Postby GFXFTS » Sat Feb 27, 2021 10:17 am

Great. Thanks a lot, Günter

GFXFTS
Posts: 42
Joined: Wed Nov 21, 2018 10:33 am

Re: Ranked Bar Chart

Postby GFXFTS » Sun Mar 07, 2021 7:02 am

Hello,

Hope all well.

I have got a problem with displaying the series name in the chart I have created below. The bar chart doesn't display the correct name of the series, e.g. "USDCAD (D/D %)" . Do you know by chance where I make a mistake?

Thanks a lot.

Best,

Günter

' Transformations


for %a USDAUD USDCAD USDCHF USDEUR USDGBP USDJPY USDNOK USDNZD USDSEK USDCNH

frml pch_{%a}=@pch({%a})*100

pch_{%a}.displayname {%a} (D/D %)

next

' Ranked Bar Chart

smpl @last @last

group g_g10_pch PCH_USDAUD PCH_USDCAD PCH_USDCHF PCH_USDEUR PCH_USDGBP PCH_USDJPY PCH_USDNOK PCH_USDNZD PCH_USDSEK PCH_USDCNH


G_G10_PCH.reorder @last

g_g10_pch.bar(contract=last)

freeze(Market_Movers) g_g10_pch.bar(contract=last)

Market_Movers.addtext(t,ac) "G-11 FX Market Movers & Shakers (1D%)"
Attachments
fx_d.wf1
(8.71 MiB) Downloaded 165 times

GFXFTS
Posts: 42
Joined: Wed Nov 21, 2018 10:33 am

Re: Ranked Bar Chart

Postby GFXFTS » Sun Mar 07, 2021 7:59 am

And how would you go about a date and time stamp in such a chart like the one below, please? Thanks a lot, Günter

for

%text = "Source: Bloomberg ("+@strnow("DD-Mon-YY")
%text1 = "," + @time
%text1a = "CET),"
%text2 = " www.fxproject.ch, @GFXFTS ."

Market_Movers.addtext(bl) {%text} {%text1} {%text1a} {%text2}

next

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

Re: Ranked Bar Chart

Postby EViews Gareth » Mon Mar 08, 2021 8:15 am

First question...

That type of graph won't use the displaynames, so you'll have to populate the labels yourself:

Code: Select all

%labels = ""
for %a USDAUD USDCAD USDCHF USDEUR USDGBP USDJPY USDNOK USDNZD USDSEK USDCNH

frml pch_{%a}=@pch({%a})*100

pch_{%a}.displayname {%a} (D/D %)
%labels = %labels + " """ + %a + "(D/D %)"""
next

' Ranked Bar Chart

smpl @last @last

group g_g10_pch PCH_USDAUD PCH_USDCAD PCH_USDCHF PCH_USDEUR PCH_USDGBP PCH_USDJPY PCH_USDNOK PCH_USDNZD PCH_USDSEK PCH_USDCNH


G_G10_PCH.reorder @last

g_g10_pch.bar(contract=last)

freeze(Market_Movers, mode=overwrite) g_g10_pch.bar(contract=last)

Market_Movers.addtext(t,ac) "G-11 FX Market Movers & Shakers (1D%)"
market_movers.setobslabel {%labels}
Follow us on Twitter @IHSEViews

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

Re: Ranked Bar Chart

Postby EViews Gareth » Mon Mar 08, 2021 8:17 am

Second question...

Your proposed solution seems to work?
Follow us on Twitter @IHSEViews

GFXFTS
Posts: 42
Joined: Wed Nov 21, 2018 10:33 am

Re: Ranked Bar Chart

Postby GFXFTS » Tue Mar 09, 2021 5:38 am

Hi Gareth,

Thanks a lot for that.

Almost there I believe but the values don't correspond to the new labelled series if you compare the group "g_g10_pch" and the "market_movers" chart in the attached workfile I am afraid.

I have to admit that I am not a programming expert as you have probably already noticed :-) but maybe this command mixes things up?

%labels = %labels + " """ + %a + """"

It would already help to get rid of " pch_" in pch_{%a}=@pch({%a})*100 and only have "{%a}" there but then we have two series with the same name I guess.

What is the role of these characters by the way please: + " """ and + """" and in %labels = "" ?

Thanks again and best wishes,

Günter
Attachments
movers_shakers.wf1
(965.96 KiB) Downloaded 160 times

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

Re: Ranked Bar Chart

Postby EViews Gareth » Tue Mar 09, 2021 9:18 am

Ah, forgot that you were re-ordering the series in the group. Have to create the labels after the reorder...

Code: Select all


for %a USDAUD USDCAD USDCHF USDEUR USDGBP USDJPY USDNOK USDNZD USDSEK USDCNH

frml pch_{%a}=@pch({%a})*100

pch_{%a}.displayname {%a} (D/D %)
next

' Ranked Bar Chart

smpl @last @last

group g_g10_pch PCH_USDAUD PCH_USDCAD PCH_USDCHF PCH_USDEUR PCH_USDGBP PCH_USDJPY PCH_USDNOK PCH_USDNZD PCH_USDSEK PCH_USDCNH


G_G10_PCH.reorder @last

%labels = ""
%serlist = g_g10_pch.@members
for %a {%serlist}
   %b = @mid(%a,5)
   %labels = %labels + " """ + %b + "(D/D %)"""   
next



freeze(Market_Movers, mode=overwrite) g_g10_pch.bar(contract=last)

Market_Movers.addtext(t,ac) "G-11 FX Market Movers & Shakers (1D%)"
market_movers.setobslabel {%labels}
show market_movers


The + """" bits just add quotation marks around the labels.
Follow us on Twitter @IHSEViews

GFXFTS
Posts: 42
Joined: Wed Nov 21, 2018 10:33 am

Re: Ranked Bar Chart

Postby GFXFTS » Sun Mar 14, 2021 7:46 am

Hi Gareth,

Thanks a lot for this.

How would I go about the labelling in the attached example, please?

Ideally, I would like to name the series as follows:

D_USGGBE10INV = US 10YR BE (Inv.)
D_UXA = Vix Future
D_XAUUSDV3M = Gold Vol
D_XAGUSDV3M = Silver Vol
d_fxvol = G10 FX Vol (PC1)


The group list would also expand over time.

Thanks again and best wishes,

Günter
Attachments
movers_shakers_risk_am.wf1
(1015.36 KiB) Downloaded 145 times
market_movers_risk_d_am.prg
(1.76 KiB) Downloaded 182 times

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

Re: Ranked Bar Chart

Postby EViews Gareth » Sun Mar 14, 2021 6:10 pm

Just change %labels to be whatever you want them to be.
Follow us on Twitter @IHSEViews

GFXFTS
Posts: 42
Joined: Wed Nov 21, 2018 10:33 am

Re: Ranked Bar Chart

Postby GFXFTS » Mon Mar 15, 2021 8:16 am

The problem is that I don't understand the syntax of the label command :-( Would you mind giving me one more example, please? Thanks a lot, Günter

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

Re: Ranked Bar Chart

Postby EViews Gareth » Mon Mar 15, 2021 9:07 am

Code: Select all

%labels = "mylabel1 mylabel2 mylabel3"
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 34 guests