@@ -425,6 +425,38 @@ def testSecurityMovingCorrelation(self):
425425 'expected: {1:.12f}\n '
426426 'calculated: {2:.12f}' .format (i , expected , calculated ))
427427
428+ def testSecurityMovingCorrelationNested (self ):
429+ window = 120
430+ x = SecurityLatestValueHolder ('close' )
431+ y = SecurityLatestValueHolder ('open' )
432+ z = x > y
433+ mc = SecurityMovingCorrelation (window , x , z )
434+
435+ for i in range (len (self .aapl ['close' ])):
436+ data = dict (aapl = dict (close = self .aapl ['close' ][i ],
437+ open = self .aapl ['open' ][i ]),
438+ ibm = dict (close = self .ibm ['close' ][i ],
439+ open = self .ibm ['open' ][i ]))
440+ mc .push (data )
441+ if i < window :
442+ start = 0
443+ else :
444+ start = i + 1 - window
445+
446+ if i < 1 :
447+ continue
448+
449+ value = mc .value
450+ for name in value .index ():
451+ xs = self .dataSet [name ]['close' ][start :(i + 1 )]
452+ ys = self .dataSet [name ]['open' ][start :(i + 1 )]
453+ expected = np .corrcoef (xs , ys )[0 , 1 ]
454+ calculated = value [name ]
455+ self .assertAlmostEqual (expected , calculated , 12 , 'at index {0}\n '
456+ 'expected: {1:.12f}\n '
457+ 'calculated: {2:.12f}' .format (i , expected , calculated ))
458+
459+
428460 def testSecurityMovingQuantile (self ):
429461 window = 10
430462 mq = SecurityMovingQuantile (window , ['close' ])
0 commit comments