- ago
I'm trying to convert the WL6 fundamental queries below ...
CODE:
double fiDividendTTM = usb.FundamentalDataSeriesAnnual("[yc] dividend", 0)[bars.Count-1]; double EPSttm = usb.FundamentalDataSeries("[z] Zacks Adjusted Earnings", 4, 0)[bars.Count-1];
... into WL7 code. The WL7 help docs for YCharts does mention the FundamentalDataSeriesAnnual(...) function a few times, but the VS Object Browser can't find this function anywhere. If there's a linq query against bars.EventDataPoints that can compute what FundamentalDataSeriesAnnual(...) does for the most recent annual period--a single value--what would that be? My linq-query savvyness isn't that good.
0
346
Solved
6 Replies

Reply

Bookmark

Sort
- ago
#1
The mentions of FundamentalDataSeriesAnnual in the WL7 help for YCharts is a leftover from its WL6 Wiki page. WL7 does not have such a method. I presume the most straightforward way to access this kind of data is to use the Morningstar data which is annual by nature.
0
- ago
#2
Yes, but I also need to do a quarter offset as shown below:
CODE:
double EPSttm = usb.FundamentalDataSeries(epsCmd, 4, 0)[lastBar]; //sum most recent 4-qtr blk; [lastBar]=[fiEPSmrq.Bar] double EPSttmPrevQt = usb.FundamentalDataSeries(epsCmd, 4, 1)[lastBar]; //sum previous 4-qtr blk shifted 1 qtr
The goal of the quarter offset is to contrast the quarter difference over a year block.

I don't need the DataSeries, only the last scaler value for the contrast. Sounds like I need to write an annual integrating function with an offset parameter to go through the bars.GetEventDataPoints("Earnings") collection and sum up the quarters. To do it any other way would be too easy. :(

If you can think of another way, and still compute the contrast, I'm all ears.
0
Glitch8
 ( 10.41% )
- ago
#3
Hmm I think that the FundamentalRatio indicator could serve this purpose if we add a denominator option of “None”. It can already perform annual summation.
1
- ago
#4
In the example code below I plotted 2 fundamentals - EPS and Payout Ratio, both also with corresponding series shifted forward by a quarter. I used WEEKLY bars and therefore shifted the series forward by 13.
Data source: Morningstar.
Play with it to get what you need.
Enjoy!

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; using System.Linq;         //for Fundamentals i.e. Event Data namespace WealthScript { public class MyStrategy : UserStrategyBase {       //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {          //======= FUNDAMENTALS =======          if (bars.EventDataPoints.Count > 0)          {             List<EventDataPoint> fList;             // Earnings Per Share (annual) - Morningstar             fList = bars.EventDataPoints.Where(i => i.Value > 0 && i.Name == "Earnings Per Share" && i.ProviderName == "Morningstar").ToList();             if (fList.Count > 0)             {                TimeSeries fEPS = Fundamental.Series(bars, "Earnings Per Share", true);                PlotTimeSeries(fEPS, fEPS.Description, "pEPS", Color.FromArgb(200, Color.DarkGreen), PlotStyles.GradientBlocks);                TimeSeries fEPSFwd1qtr = fEPS >> 13;                PlotTimeSeries(fEPSFwd1qtr, fEPSFwd1qtr.Description, "pEPS2", Color.FromArgb(150, Color.MediumPurple), PlotStyles.GradientBlocks);             }             fList.Clear();             // Payout Ratio (annual) - Morningstar             fList = bars.EventDataPoints.Where(i => i.Value > 0 && i.Name == "Payout Ratio %" && i.ProviderName == "Morningstar").ToList();             if (fList.Count > 0)             {                TimeSeries fPayoutRatio = Fundamental.Series(bars, "Payout Ratio %", true);                PlotTimeSeries(fPayoutRatio, fPayoutRatio.Description, "pPR", Color.Red, PlotStyles.ThickHistogram);                TimeSeries fPayoutRatioFwd1qtr = fPayoutRatio >> 13;                PlotTimeSeries(fPayoutRatioFwd1qtr, fPayoutRatioFwd1qtr.Description, "pPR2", Color.FromArgb(150, Color.PaleVioletRed), PlotStyles.ThickHistogram);             }             fList.Clear();          }          else          {             DrawHeaderText("Fundamental info not available", Color.DarkBlue);          }       } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { } //declare private variables below } }


2
Glitch8
 ( 10.41% )
- ago
#5
Looks great!
0
- ago
#6
I don't need an entire TimeSeries. I only need a scaler value to compute the most recent EPS growth rate. I took a look at this problem and solve it with the FundamentalSum() function (below), which returns a double. You're welcome to include it in the Community.Components library if you like.

Honestly, I didn't realize this function could be implemented with only a few lines of code; I'm surprised. Happy computing.

CODE:
using System.Collections.Generic; using WealthLab.Core; using WealthLab.Backtest; namespace WealthScript5 { public class FundSummer : UserStrategyBase {       public double FundamentalQtrSum(List<EventDataPoint> source, int aggregate, int offset)       {          double sum = 0.0;          for (int qtrCnt=1, sourceIdx=source.Count-1-offset; qtrCnt <= aggregate; qtrCnt++)             sum += source[sourceIdx--].Value;          return sum;       }              //create indicators and other objects here; executed before main trading loop       public override void Initialize(BarHistory bars) {          List<EventDataPoint> earnings = bars.GetEventDataPoints("Earnings");          double currentYear = FundamentalQtrSum(earnings,4,0); //4-qtr sum w/o offset          double qtrBeforeYear = FundamentalQtrSum(earnings,4,1); //4-qtr sum offset 1 qtr          double prevYear = FundamentalQtrSum(earnings,4,4); //4-qtr sum offset 4 qtrs     WriteToDebugLog(((currentYear-qtrBeforeYear)/qtrBeforeYear).ToString("0.#% quarter growth (ttm)"));       }       //execute the strategy rules here; executed once per bar in backtest       public override void Execute(BarHistory bars, int idx) { } } }
2
Best Answer

Reply

Bookmark

Sort