Mariner Backtesting - percent_change()

percent_change() calculates percent change. Does not take time into consideration.

Code:

 def percent_change(value_start, value_end):
    if value_start != 0.0:
        return float(value_end - value_start) / float(value_start)
    else:
        return 0.0
Parameters:
Name Type Default Information
list list required list of items
Returns:
Type Special Notes
list of items [0] will return [0] if empty list is passed in
Working Example:

Get the percent change between the start and end values. Backtest for TQQQ on 2016/06/15 from 9:30-16:00.

from cloudquant.interfaces import Strategy
import ktgfunc


class TestKTGFunc(Strategy):

    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        return symbol == 'TQQQ'

    # called at the beginning of each instance  
    def on_start(self, md, order, service, account):
        t = service.time_to_string(service.system_time, '%Y-%m-%d')
        bar = md.bar.daily(start=-5)

        print bar.high
        print ('test time: %s\t%s') % (t, ktgfunc.percent_change( bar.high[0], bar.high[-1] ) )

        service.terminate()

Console

[ 105.18000031  104.37000275  101.77999878  100.4536972    98.98999786]
test time: 2016-06-15   -0.0588515157202