Icb code ranking

First I apologize for my level of English, he is not good. My level of programming is not better either.

I have prepared a formula to rank companies taking into account their Icb classification. I have already finished the whole list.

When I pass the Explore on it, I find errors in the total of some of the codes. In the image that I am putting, you can see that the scan gives a correct result for the code "20103020 Cannabis Producer" (7 companies) but incorrect for the code "20103015 Pharmaceuticals" (he says that there is only 1 value and really I I have more than 200).

I have checked in the forum what the problem may be but I cannot find the answer. I would be very grateful if someone can guide me in finding a solution.

_SECTION_BEGIN("");
// correctly classified ICB list
listIcb = CategoryGetSymbols(categoryICB, StrToNum(IcbID(0)));


// Create the full list of stocks to be ranked
List = listIcb;
ListQty = StrCount(List, ",") + 1;

StockName = FullName();
NameSect = IcbID(2);

Filter =1;

SetSortColumns(-4);
AddTextColumn ( StockName, "Name                                ", 1.2);
AddTextColumn (NameSect, "Sector Icb                                             ", 1.2);
AddColumn (ListQty, "Stocks", 1.2);

_SECTION_END();

Exploration

@mikelamezaga what version of AmiBroker do you have?

I don't use the ICB classification but I see that there have been some changes in the structure which have been addressed in a recent version of the software.

I suggest you check if the problem persists with the latest version or not.

Thanks for your reply.

I have the latest version 6.39.1. (64-bit). I reinstalled the version again to see if there was any later update but the circumstance persisted.

Because of these facts:

e.g. this one

stn = StrToNum("20103015");

will return 20103016 but not 20103015.

Thanks for answering.
I have looked at your recommendation "About floating point arithmetic" but I can't find the answer.
I may not have explained the situation well.

I have classified a large number of companies by the Icb, when I put for example the explore on the Icb 65 Utilities (in that classification I have a total of 184 companies) the result is the following:

65 Utilities: 184 companies (Ok)
6510 Utilities: 182 (Ok)
651010 Electricity: 94 (Ok)
65101010 Alternative Electricity: 1 (but it's really 15)
65101015 Conventional Electricity: 1 (but it's really 68)
651020 Gas, Water and Multi-utilities: 66 (Ok)
65102020 Gas Distribution: 21 (Ok)
65102030 Water: 1 (but really 21)
65103035 Waste and Disposal Services: 1 (but really 19)

I do not know why with some codes it offers a correct result and yet in others it does not. This situation is repeated in the entire series of codes.

20103015 has eight digits.
Please read that KB article again and output

stn = StrToNum("20103015");

via printf. You will see 20103016.

Another thing to keep in mind is that 32-bit floating point number has only 7 significant digit


Here is one possible solution

/// get all symbols being in same ICB category as of selected symbol
/// @link https://forum.amibroker.com/t/icb-code-ranking/25969/6
EnableTextOutput(0);
iid = StrExtract(IcbID(2), 0, ' ');
stn = StrToNum(StrLeft(iid, 6));
sym_list = CategoryGetSymbols(categoryIcb, stn);
printf( "\n%s", sym_list);

for ( i = 0, list = ""; (symbol = StrExtract(sym_list, i, ',')) != ""; i++ ) {
	SetForeign( symbol );
	if ( InIcb(iid) )	list += symbol +",";
	RestorePriceArrays();	
}
list = StrTrim(list, ",");
printf( "\n%s", list);

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.