Display CHANGE in Fundamental Data Value

As we know, many data providers such as Norgate provide two different types of data: bar-by-bar data series (e.g., prices vs time) and single-point fundamental data available only at the most recent bar (for example the number of shares outstanding). We can display the value of this Norgate data item in Amibroker with the following code snippet:

#include_once "Formulas\Norgate Data\Norgate Data Functions.afl"
ShOut = NorgateFundamentals ("SharesOutstanding");
   Plot (ShOut, "ShOut", colorBlack, styleDots, styleLeftAxisScale);	// or similar.

What we see in Amibroker when we do this is one single value, repeated for each bar. Even though plotted in Amibroker on a chart vs time, we know this is not actually the number of shares outstanding vs time, because it is only single-point data; the most recent day’s data. Of course that is quite OK, as we do understand that it is not really a time series.

Now imagine that we make a note of the value today, and that between now and the next day, the company issues more shares or does a share buyback, either of which causes a change in the number of shares outstanding. Then, next time we run Amibroker with Norgate data source, we will again see only a single value of ShOut, but now it will be the NEW value. Unless we have actually made a note of the previous day’s OLD value of ShOut, we may not realize that it has changed.

But if we had noted and plotted the OLD value of ShOut as a fixed value, then we would be able to see the difference. This is what I would like to do, but I have not yet figured out an elegant way to do it, even though I expect that it is probably fairly easy in Amibroker (maybe VarSet / VarGet or similar ?)

“Shares Outstanding” here is just an example, and it could be anything else from Norgate’s (or other) single-point data. What I want to do is to see if the value has changed since the previous time that I looked in Amibroker. I understand that, in principle, it involves saving the value of a Norgate single-point data item as a fixed value with some different name, and then comparing that against what I get the next time when I call the same data from Norgate. (Obviously we would not be able to actually see this working until the data actually changes).

How I can determine and display if/when Norgate (or other fundamental data provider's) single-point, most recent fundamental data changed from one day to the next? Any assistance / comments gratefully received. Thanks in advanvce, from TonyM.

An idea could be to write the value into a file and each day read that file to make a comparison. If today's value is different from the one stored into the file then you get your answer and in this case you should update the file for the next days check.

Hi,
I agree with @2DD that you could use a file. The key is that the previous value needs to be stored persistently. Here I have had a go at using persistent static vars. I also have used the Notepad previously for symbol specific storage - particularly where you want the stored information to be easily viewed.

I think this should work but it cant be tested real time easily so devise your own test method to verify to the extent required.
Feedback welcome.

#include_once "Formulas\Norgate Data\Norgate Data Functions.afl"

Plot( Close, "Price", colorDefault, styleCandle | styleNoTitle | styleNoLabel );    // basic price plot
Title = StrFormat( "{{DATE}}, O %g, H %g, L %g, C %g  |  {{VALUES}}", O, H, L, C );  // basic title

SharesOut = NorgateFundamentals ( "SharesOutstanding" );
CurrentDate = LastValue( DateNum() );

Persist = True;
Symb = Name();

ShOutPrev = StaticVarGet( "_ShOutVal_" + Symb );
ShOutDatePrev = StaticVarGet( "_ShOutDate_" + Symb );

// first run initialization
if( IsNull( ShOutPrev ) OR IsNull( ShOutDatePrev ) )
{
    StaticVarSet( "_ShOutDate_" + Symb, CurrentDate, Persist );
    ShOutDatePrev = CurrentDate;
    StaticVarSet( "_ShOutVal_" + Symb, SharesOut, Persist );
    ShOutPrev = SharesOut;
}

// On value change
if( ShOutPrev != SharesOut )
{
    // plot old and new
    Title += "\n" + Symb + " Shares Outstanding changed from " + NumToStr( ShOutPrev, 1.0 ) + " to " + NumToStr( SharesOut, 1.0 );
    // save date of change
    StaticVarSet( "_ShOutDate_" + Symb, CurrentDate, Persist );
}

// On bar after change
if( ShOutDatePrev < CurrentDate AND ShOutPrev != SharesOut )
{
    /// update saved value
    StaticVarSet( "_ShOutVal_" + Symb, SharesOut, Persist );
}

John.

1 Like

@TonyM, personally I would opt to store data to an associated file for each ticker.

I would probably build a folder structure similar to the AmiBroker database (with the root in some specific path location, based on the current database loaded). Using many folders to spread the files will make file access a bit faster.

Each time a ticker is displayed, I will check the Norgate data and then open the file to see if the data is stored there, reading all the text lines of the file. If there is no data stored in the file or the current Norgate fundamental is different from the last one stored in the file, I will add a new line (writing the date and the value in an unambiguous and easy-to-parse format)

In such a way, you'll be able to display multiple changes in the fundamental value over time.

One variation I foresee is the need to do the same for multiple fundamentals.
In such a case, to keep the reading, writing, and parsing as simple as possible, instead of using a single file for each ticker, I will use a folder (named as the ticker).
Under this folder I would put different files each named like the fundamental I'm looking for like "sharesoutstanding", "ttmfcf", "ttmroipct", etc. and I would apply the read/write logic as described above to these files.

One advantage of this method is that it will easily allow you, as needed, to backup data, move data, and erase data outside of Amibroker, including creating/writing files with other applications if you have access to other sources (scraping comes to my mind).

1 Like

I forgot to indicate that when the file you would like to read does not exist, you'll need to create it (and, if required, also create the path structure, using the fmkdir() function) and write to it the first line of data as per the current fundamental.

Hi 2DD, thank you. Conceptually definitely on the right track, i'm sure. The main question is how to implement effectively.

Hi JohnHT, many thanks for your answer and for taking the time to write the AFL code, much appreciated. This is almost exactly at the level of complexity that i want for this specific problem and that i can easily understand. Now i look forward to testing it out.

Hi beppe, thank you for your suggestions and outline plan of how to implement this comprehensive & powerful solution. It is bit more than my immediate needs (and possibly also more than my current level of ability) but is an excellent plan that would be suitable for me or anyone else interested in building up a fundamentals time-series database. I would expect there may be quite a few experienced traders who, just like me, appreciate the value of what you describe, but lack the time or the coding ability to implement it themselves and would be happy to pay for a working product that does what you mention. Have you considered the possibility of commercializing this as an addon / addin for Amibroker?

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