Mariner Backtesting - check_list()

Validates a list has items, else returns a list with a single value of 0. Used to ensure a list has values before doing a max operation. E.g. max(md.bar.daily(start=-10).high.

Code:

 def check_list(list):
    if len(list) > 0:
        return List
    else:
        return [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:

Example 1 Check list of values.

 import ktgfunc

a = [1,2,3]

ktgfunc.check_list(a)

Console

[1,2,3]

Example 2 Check empty list.

 import ktgfunc

a = []

ktgfunc.check_list(a)

Console

[0]

Use Case 1 Get max value in list.

 import ktgfunc

a = [1,2,3]

b = ktgfunc.check_list(a)

print max(check_list)

Console

3

Use Case 2 Get max value of empty list.

 import ktgfunc

a = []

b = ktgfunc.check_list(a)

print max(check_list)

Console

0