Mariner Backtesting - Print Console

Using prints to the application console

Overview:

When building a model, it is crucial to get feedback. An easy way to receive data about things that are going on in the market or inside your script is to use the print statement. Wherever you are in your code, you can print a statement or an object. This puts info into the console so that you can see what's going on.

Remember, feedback is important and we want to make it easy to get it, but an overload of feedback can be detrimental rather than helpful. Too much information can make things difficult for you and slows the system down.

Basic use case:

Basic printing is useful for just getting the console to print the feedback you want. It is very simple to use and has an endless variety of uses.

Interface:
 print 'hello world'
Working Example:

In this example, we print useful information to console.

# Copyright Cloudquant, LLC. All right reserved.
from cloudquant.interfaces import Strategy


class PrintData(Strategy):


    # note that this doesn't start with "self" because it's a @staticmethod
    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        return symbol == 'AAL'

    def on_minute_bar(self, event, md, order, service, account, bar):

        # save bar data to a local variable
        three_min = bar.minute(-3)

        # make sure three_min has 3 bars
        if len(three_min.high) > 2:
            # if the 3 most recent minutes have increasing high prices print data
            if three_min.high[0] > three_min.high[1] > three_min.high[2]:
                print 'Data for the times:', service.time_to_string(three_min.timestamp[0])[11:19] + '\t', service.time_to_string(three_min.timestamp[1])[11:19] + '\t', service.time_to_string(three_min.timestamp[2])[11:19]
                print 'The high prices:\t', three_min.high
                print 'The low prices:\t', three_min.low
                print 'The open prices:\t', three_min.open

                service.terminate()

Console

Data for the times: 09:32:00    09:33:00    09:34:00
The high prices:    [ 35.47000122  35.45999908  35.45000076]
The low prices: [ 35.22000122  35.25999832  35.33000183]
The open prices:    [ 35.36000061  35.38999939  35.38999939]

We could add a lot of lessons on printing, but there's a lot of information already available. Here's a good place to start (https://pyformat.info/).