The idea behind paper trading is to act as a method of "forward testing" a strategy. Paper trading is where we take fake (paper) money, and "pretent" to have invested in a company, only this time we're doing it in real time. This is our way to tracking, without hindsight bias how our strategy actually might do. This still obviously excludes you from actually entering the market, so this very fact makes this not a perfect method to test a strategy, but it is a lot better than an ordinary back-test.
To show how we can do a paper-trading example, we'll use the long/short strategy that we built back form: Achieving Targets - Python for Finance with Zipline and Quantopian 8. That code was:
# Put any initialization logic here. The context object will be passed to # the other methods in your algorithm. def initialize(context): context.features = {} context.stocks = symbols('XLY', # XLY Consumer Discrectionary SPDR Fund 'XLF', # XLF Financial SPDR Fund 'XLK', # XLK Technology SPDR Fund 'XLE', # XLE Energy SPDR Fund 'XLV', # XLV Health Care SPRD Fund 'XLI', # XLI Industrial SPDR Fund 'XLP', # XLP Consumer Staples SPDR Fund 'XLB', # XLB Materials SPDR Fund 'XLU') # XLU Utilities SPRD Fund schedule_function(rebalance, date_rule = date_rules.every_day(), time_rule = time_rules.market_open()) def rebalance(context, data): pass def handle_data(context, data): for stock in context.stocks: ma1 = data[stock].mavg(100) ma2 = data[stock].mavg(300) price = data[stock].price if ma1 > ma2: order_target_percent(stock, 0.11) elif ma1 < ma2: order_target_percent(stock, -0.11)
From here, what we need to do is run this code on a "full backtest" against minute data.
Once you've done that, you should have the option to choose the "live trade algorithm" button at the top right. Clicking that, you have the choice to either paper trade or connect your brokerage account. We'll just go the paper trading route. Once that's done, you're all set.
I've been running the long/short strategy at the time of my writing this for about a month and a half, here's the current situation:
At least so far, this strategy is clearly less volatile, and even currently outperforming.