#NEWLINE# def testSomeTrades( self ) : #NEWLINE# #INDENT# strat = self . __createStrategy ( ) #NEWLINE# stratAnalyzer = trades . Trades ( ) #NEWLINE# strat . attachAnalyzer ( stratAnalyzer ) #NEWLINE# strat . addOrder ( buildUTCDateTime ( 2011 , 1 , 3 , 15 , 0 ) , strat . getBroker ( ) . createMarketOrder , broker . Order . Action . BUY , TradesAnalyzerTestCase . TestInstrument , 1 ) #NEWLINE# strat . addOrder ( buildUTCDateTime ( 2011 , 1 , 3 , 15 , 16 ) , strat . getBroker ( ) . createMarketOrder , broker . Order . Action . SELL , TradesAnalyzerTestCase . TestInstrument , 1 ) #NEWLINE# strat . addOrder ( buildUTCDateTime ( 2011 , 1 , 3 , 15 , 30 ) , strat . getBroker ( ) . createMarketOrder , broker . Order . Action . BUY , TradesAnalyzerTestCase . TestInstrument , 1 ) #NEWLINE# strat . addOrder ( buildUTCDateTime ( 2011 , 1 , 3 , 15 , 31 ) , strat . getBroker ( ) . createMarketOrder , broker . Order . Action . SELL , TradesAnalyzerTestCase . TestInstrument , 1 ) #NEWLINE# strat . addOrder ( buildUTCDateTime ( 2011 , 1 , 3 , 15 , 38 ) , strat . getBroker ( ) . createMarketOrder , broker . Order . Action . BUY , TradesAnalyzerTestCase . TestInstrument , 1 ) #NEWLINE# strat . addOrder ( buildUTCDateTime ( 2011 , 1 , 3 , 15 , 42 ) , strat . getBroker ( ) . createMarketOrder , broker . Order . Action . SELL , TradesAnalyzerTestCase . TestInstrument , 1 ) #NEWLINE# strat . addOrder ( buildUTCDateTime ( 2011 , 1 , 3 , 15 , 47 ) , strat . getBroker ( ) . createMarketOrder , broker . Order . Action . BUY , TradesAnalyzerTestCase . TestInstrument , 1 ) #NEWLINE# strat . run ( ) #NEWLINE# self . assertTrue ( ( round ( strat . getBroker ( ) . getCash ( ) , 2 ) == round ( ( ( ( ( 1000 + ( 127.16 - 127.14 ) ) + ( 127.16 - 127.2 ) ) + ( 127.26 - 127.16 ) ) - 127.34 ) , 2 ) ) ) #NEWLINE# self . assertTrue ( ( stratAnalyzer . getCount ( ) == 3 ) ) #NEWLINE# self . assertTrue ( ( stratAnalyzer . getEvenCount ( ) == 0 ) ) #NEWLINE# self . assertTrue ( ( round ( stratAnalyzer . getAll ( ) . mean ( ) , 2 ) == 0.03 ) ) #NEWLINE# self . assertTrue ( ( round ( stratAnalyzer . getAll ( ) . std ( ddof = 1 ) , 2 ) == 0.07 ) ) #NEWLINE# self . assertTrue ( ( round ( stratAnalyzer . getAll ( ) . std ( ddof = 0 ) , 2 ) == 0.06 ) ) #NEWLINE# self . assertTrue ( ( stratAnalyzer . getProfitableCount ( ) == 2 ) ) #NEWLINE# self . assertTrue ( ( round ( stratAnalyzer . getProfits ( ) . mean ( ) , 2 ) == 0.06 ) ) #NEWLINE# self . assertTrue ( ( round ( stratAnalyzer . getProfits ( ) . std ( ddof = 1 ) , 2 ) == 0.06 ) ) #NEWLINE# self . assertTrue ( ( round ( stratAnalyzer . getProfits ( ) . std ( ddof = 0 ) , 2 ) == 0.04 ) ) #NEWLINE# self . assertTrue ( ( stratAnalyzer . getUnprofitableCount ( ) == 1 ) ) #NEWLINE# self . assertTrue ( ( round ( stratAnalyzer . getLosses ( ) . mean ( ) , 2 ) == ( - 0.04 ) ) ) #NEWLINE# if ( version . LooseVersion ( numpy . __version__ ) >= version . LooseVersion ( '1.6.2' ) ) : #NEWLINE# #INDENT# self . assertTrue ( math . isnan ( stratAnalyzer . getLosses ( ) . std ( ddof = 1 ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . assertTrue ( ( stratAnalyzer . getLosses ( ) . std ( ddof = 1 ) == 0 ) ) #NEWLINE# #UNINDENT# self . assertTrue ( ( stratAnalyzer . getLosses ( ) . std ( ddof = 0 ) == 0 ) )