#NEWLINE# def _apply_splits( parsed , splits ) : #NEWLINE# #INDENT# '\n    split processing - adjust price and quantity of all pre-split transactions\n    the double loop is intentional since a stock can split more than once, start processing by earliest date\n  ' #NEWLINE# for split in sorted ( splits , key = ( lambda split : split . as_of_date ) ) : #NEWLINE# #INDENT# for transaction in parsed : #NEWLINE# #INDENT# if ( ( transaction . get ( 'symbol' ) == split . from_symbol ) and ( transaction . get ( 'date' ) <= split . as_of_date ) ) : #NEWLINE# #INDENT# factor = ( split . to_quantity / split . from_quantity ) #NEWLINE# transaction [ 'symbol' ] = split . to_symbol #NEWLINE# transaction [ 'quantity' ] = ( transaction . get ( 'quantity' ) * factor ) #NEWLINE# transaction [ 'price' ] = ( transaction . get ( 'price' ) / factor )