@@ -80,9 +80,17 @@ public override void Initialize()
8080 throw new RegressionTestException ( $ "Unexpected { nameof ( Fundamental ) } data count { history [ 0 ] . Values . Count } , expected 2!") ;
8181 }
8282
83+ // assert all fundamental API data match
8384 foreach ( var ticker in new [ ] { "AAPL" , "SPY" } )
8485 {
85- if ( ! history [ 0 ] . TryGetValue ( ticker , out var fundamental ) || fundamental . Price == 0 )
86+ var fundamentalThroughSecurity = Securities [ ticker ] . Fundamentals ;
87+ var fundamentalThroughAlgo = Fundamentals ( ticker ) ;
88+
89+ if ( ! history [ 1 ] . TryGetValue ( ticker , out var fundamental ) || fundamental . Price == 0
90+ || fundamentalThroughSecurity . Price != fundamental . Price
91+ || fundamentalThroughSecurity . EndTime != fundamental . EndTime
92+ || fundamentalThroughAlgo . Price != fundamental . Price
93+ || fundamentalThroughAlgo . EndTime != fundamental . EndTime )
8694 {
8795 throw new RegressionTestException ( $ "Unexpected { ticker } fundamental data") ;
8896 }
@@ -142,7 +150,24 @@ public IEnumerable<Symbol> FundamentalSelectionFunction(IEnumerable<Fundamental>
142150 var sortedByPeRatio = sortedByDollarVolume . OrderByDescending ( x => x . ValuationRatios . PERatio ) ;
143151
144152 // take the top entries from our sorted collection
145- var topFine = sortedByPeRatio . Take ( NumberOfSymbolsFundamental ) ;
153+ var topFine = sortedByPeRatio . Take ( NumberOfSymbolsFundamental ) . ToArray ( ) ;
154+
155+ // selection fundamental data should match all other APIs
156+ foreach ( var fundamentalPoint in topFine )
157+ {
158+ var symbol = fundamentalPoint . Symbol ;
159+ var fundamentalThroughSecurity = Securities . ContainsKey ( symbol ) ? Securities [ symbol ] . Fundamentals : null ;
160+ var fundamentalThroughAlgo = Fundamentals ( symbol ) ;
161+
162+ if ( fundamentalPoint . Price == 0
163+ || fundamentalThroughSecurity != null && ( fundamentalThroughSecurity . Price != fundamentalPoint . Price
164+ || fundamentalThroughSecurity . EndTime != fundamentalPoint . EndTime )
165+ || fundamentalThroughAlgo . Price != fundamentalPoint . Price
166+ || fundamentalThroughAlgo . EndTime != fundamentalPoint . EndTime )
167+ {
168+ throw new RegressionTestException ( $ "Unexpected { symbol } fundamental data in selection") ;
169+ }
170+ }
146171
147172 // we need to return only the symbol objects
148173 return topFine . Select ( x => x . Symbol ) ;
0 commit comments