Fundamental Data

The Fundamental Data category consists of methods you can use to access and manipulate fundamental data.

BuyAtMarket

FundamentalDataItems

IList<FundamentalItem> FundamentalDataItems(string itemName);
IList<FundamentalItem> FundamentalDataItems(string symbol, string itemName);

The FundamentalDataItems object represents a collection of FundamentalItem objects.


Example

protected override void Execute(){
    // Show the list of the fundamental data item "assets"

    const char tab = '\u0009';                                      
    string item = "assets";
    IList<FundamentalItem> fList = FundamentalDataItems(item);            
    ClearDebug();
    PrintDebug(Bars.Symbol + tab + "Item Count: " + fList.Count);
    PrintDebug("FY" + tab + "FQ" + tab + "Bar" + tab + "Date      " + tab + "Value" + tab + "FormatValue");
    foreach (FundamentalItem fi in fList)
    {
        PrintDebug(fi.GetDetail("fiscal year") + tab
            + fi.GetDetail("current quarter") + tab
            + fi.Bar.ToString() + tab 
            + fi.Date.ToShortDateString() + tab 
            + fi.Value.ToString("$#,0.00")
            + tab + fi.FormatValue().Replace("\n", " ") );
    }                                              
}
BuyAtMarket

FundamentalDataSeries

DataSeries FundamentalDataSeries(string itemName);
DataSeries FundamentalDataSeries(string itemName, int offset);
DataSeries FundamentalDataSeries(string itemName, int aggregate, int offset);
DataSeries FundamentalDataSeries(string itemName, int aggregate, bool average, int offset);
DataSeries FundamentalDataSeries(string symbol, string itemName);
DataSeries FundamentalDataSeries(string symbol, string itemName, int aggregate, bool average, int offset);

Returns a DataSeries that represents the fundamental data for the specified "fundamental itemName". To access symbol-specific fundamental data without calling SetContext, use one of the last two overload signatures to pass the stock symbol. The individual fundamental data items are synchronized to the Bars object that the Strategy is currently operating on, and the fundamental data values become the values of the resulting DataSeries. Bars that do not contain any fundamental data items at their specific date will carry over the value of the previous, most recent fundamental data item. The resulting DataSeries can be plotted on the chart and manipulated as any other normal DataSeries.

Aggregate, average, and offset parameters perform those operations on the itemName Fundamental DataSeries in the order in which they appear in the parameter list. For example, a Fundamental DataSeries will first be aggregated by the number of integer aggregate periods specified. Then, if average is true, the average of the aggregate series is returned. Finally, the series is offset forward in time by the number of offset periods, where the period depends on the specified itemName. (Generally, the period is quarterly for corporate fundamental items.) By offsetting, it's easy to determine quarter-over-quarter or year-over-year changes.

Remarks


Example

protected override void Execute(){
    //  55/34 Breakout strategy with an asset twist
    
    ChartPane fundPane = CreatePane(40, true, false);
    // Preferred plot method for Fundamental data items
    PlotFundamentalItems(fundPane, "assets", Color.Green, WealthLab.LineStyle.Invisible, 1);               

    // Plot "assets" in a time series
    DataSeries assets = FundamentalDataSeries("assets");
    PlotSeries(fundPane, assets, Color.Black, WealthLab.LineStyle.Solid, 1);

    // Delay highest and lowest series by 1 bar to check Closing crossovers/unders
    DataSeries highest = Highest.Series(High, 55) >> 1;
    DataSeries lowest = Lowest.Series(Low, 34) >> 1;

    PlotSeries(PricePane, highest, Color.Green, WealthLab.LineStyle.Dashed, 1 );
    PlotSeries(PricePane, lowest, Color.Red, WealthLab.LineStyle.Dashed, 1 );

    for(int bar = 20; bar < Bars.Count; bar++)
    {
        if (IsLastPositionActive) {
            // exit if assets drop below $50M
            if (CrossUnder(bar, assets, 50000d))
                SellAtMarket(bar + 1, LastPosition, "assets < $50M");
            else if (CrossUnder(bar, Close, lowest))
                SellAtMarket(bar + 1, LastPosition, "lowest 34");
        }
        else { 
            // Trade this instrument only if assets are over $50M                         
            if (assets[bar] > 50000d)
                if (CrossOver(bar, Close, highest))
                    BuyAtMarket(bar + 1);                                       
        }     
    }
}
BuyAtMarket

FundamentalDataSeriesAnnual

DataSeries FundamentalDataSeriesAnnual (string itemName, int offset);
DataSeries FundamentalDataSeriesAnnual (string symbol, string itemName, int offset);

Returns a DataSeries that sums the 4 quarters of the Fiscal Year. This function is used in the ratio rules that are based on annual growth rates.

Remarks

public DataSeries FDSeriesAnnual(string symbol, string item, int offset)
{
int bar = Bars.Count - 1;			
DataSeries result = FundamentalDataSeriesAnnual(symbol, item, offset);
int fq = (int)GetFundamentalItem(bar, symbol, "fiscal quarter").Value;
while (fq == 4 &amp;&amp; bar > 0)
{
result[bar] = FundamentalDataSeries(symbol, item, 4, false, offset * 4)[bar];				
bar--;
fq = (int)GetFundamentalItem(bar, symbol, "fiscal quarter").Value;
}
return result;
}

You can also use the aggregate overload for FundamentalDataSeries to add the last rolling 4 quarters of a fundamental item:

string eps = "earnings per share";
//Replace this:
//PlotSeries(FundPane,FundamentalDataSeriesAnnual(eps, 0), Color.DeepPink, LineStyle.Solid, 2);
//With this:
PlotSeries(FundPane,FundamentalDataSeries(eps, 4, false, 0), Color.DeepPink, LineStyle.Solid, 2);

Example

protected override void Execute(){
    //Calculate and plot the percentage annual earning growth
    DataSeries income = FundamentalDataSeriesAnnual( "net income", 0 );                                               
    DataSeries income2 = FundamentalDataSeriesAnnual( "net income", 1 );
    DataSeries EG = 100 * (income - income2) / DataSeries.Abs(income2);

    // Plot the annualized income
    ChartPane annualIncomePane = CreatePane(40, true, true);
    PlotSeries( annualIncomePane, income, Color.Blue, WealthLab.LineStyle.Solid, 2);

    // Plot the earnings growth
    EG.Description = "Annual Earnings Growth %";
    ChartPane egPane = CreatePane(40, true, true );
    PlotSeries(egPane, EG, Color.Green, WealthLab.LineStyle.Histogram, 2);                                                                                           
}

BuyAtMarket

GetFundamentalItem

FundamentalItem GetFundamentalItem (int bar, string symbol, string itemName);

Returns the FundamentalItem object for itemName that corresponds to the specified bar and symbol.

Remarks

  • To avoid runtime errors, test for a null object before using the result.
  • A FundamentalItem "off the chart" can be returned, and in this case the its Bar property will be set to -1.

Example

protected override void Execute(){
int bar = Bars.Count - 1;
    FundamentalItem fi = GetFundamentalItem(bar, Bars.Symbol, "assets");
    if (fi != null)
        DrawLabel(PricePane, "Current assets: " + fi.Value.ToString("$#,0") + " (millions)", Color.Blue);
    else
        DrawLabel(PricePane, "Current assets: not available", Color.Blue);                                                      
}
BuyAtMarket

GetNextFundamentalItem

FundamentalItem GetNextFundamentalItem (int bar, string symbol, string itemName);

Returns the FundamentalItem object for itemName following the one that corresponds to the specified bar and symbol.

Remarks

  • To avoid runtime errors, test for a null object before using the result.
  • A FundamentalItem "off the chart" can be returned, and in this case the its Bar property will be set to -1.

Example

protected override void Execute(){
int bar = 0;
    FundamentalItem fi = GetNextFundamentalItem(bar, Bars.Symbol, "assets");
    if (fi != null)
        DrawLabel(PricePane, "first assets report in chart range " + fi.Date.ToShortDateString() + ": " + fi.Value.ToString("$#,0") + " (millions)", Color.Blue);
    else
        DrawLabel(PricePane, "assets: not available", Color.Blue);                                                     
}