Page 1 of 1
Ranked Bar Chart
Posted: Thu Feb 18, 2021 12:37 pm
by GFXFTS
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
Re: Ranked Bar Chart
Posted: Thu Feb 18, 2021 2:43 pm
by EViews Gareth
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:
Re: Ranked Bar Chart
Posted: Thu Feb 18, 2021 2:57 pm
by EViews Gareth
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.
Re: Ranked Bar Chart
Posted: Sat Feb 27, 2021 10:17 am
by GFXFTS
Great. Thanks a lot, Günter
Re: Ranked Bar Chart
Posted: Sun Mar 07, 2021 7:02 am
by GFXFTS
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%)"
Re: Ranked Bar Chart
Posted: Sun Mar 07, 2021 7:59 am
by GFXFTS
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
Re: Ranked Bar Chart
Posted: Mon Mar 08, 2021 8:15 am
by EViews Gareth
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}
Re: Ranked Bar Chart
Posted: Mon Mar 08, 2021 8:17 am
by EViews Gareth
Second question...
Your proposed solution seems to work?
Re: Ranked Bar Chart
Posted: Tue Mar 09, 2021 5:38 am
by GFXFTS
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
Re: Ranked Bar Chart
Posted: Tue Mar 09, 2021 9:18 am
by EViews Gareth
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.
Re: Ranked Bar Chart
Posted: Sun Mar 14, 2021 7:46 am
by GFXFTS
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
Re: Ranked Bar Chart
Posted: Sun Mar 14, 2021 6:10 pm
by EViews Gareth
Just change %labels to be whatever you want them to be.
Re: Ranked Bar Chart
Posted: Mon Mar 15, 2021 8:16 am
by GFXFTS
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
Re: Ranked Bar Chart
Posted: Mon Mar 15, 2021 9:07 am
by EViews Gareth
Code: Select all
%labels = "mylabel1 mylabel2 mylabel3"