Firstly, great job thus far! I’ve been looking for a solution to implement my already back-tested strategy but as I’m a python novice the catalyst engine seems like an ideal solution.

My problem - I’m trying to run a quick and dirty version of a statistical arbitrage strategy, just to familiarize myself with catalyst and see if the backtest results match those in my other non-catalyst script. The other script I mention screens the polo universe of cryptos, conducts pairwise analysis throughout to determine cointegrated pairs, runs a quick backtest to find pairs with a CAGR >10% and sharpe >0.5% and spits out combinations which meet these criteria. It’s one of these pairs I’m now trying to test using catalyst but I can’t make it open orders! I feel like it’s probably something simple I’m missing but I’ve been fiddling with it for 2 days no and can’t get anywhere so any help would be appreciated.

FYI I’m looking at BTCBCN & BTCLTC, 1m frequency, poloniex (2 days at the start of July).

```
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 18 16:34:41 2018
@author: Alex
removed kalman filter regression for state means - too slow.
"""
# for collecting data & running catalyst
import pandas as pd
from datetime import datetime
from catalyst.api import order, record, symbol, symbols
from catalyst.utils.run_algo import run_algorithm
#for statistical tests
import statsmodels.tsa.stattools as ts
import statsmodels.api as sm
import matplotlib.pyplot as plt
from pykalman import KalmanFilter
import numpy as np
from numpy import log, polyfit, sqrt, std, subtract
def initialize(context):
context.asset = symbol('ltc_btc')
context.asset2 = symbol('bcn_btc')
#context.entryZscore = 2
#context.exitZscore = 0
def handle_data(context, data):
context.i = 0
ltcbtchist = data.history(context.asset,
'price',
bar_count=2800,
frequency = '1T')
bcnbtchist = data.history(context.asset2,
'price',
bar_count=2800,
frequency = '1T')
context.ltcbtchist = ltcbtchist
#ltcbtc = data.current(context.asset, 'price')
#bcnbtc = data.current(context.asset2, 'price')
#print('Data: {}'.format(data.current_dt))
#print('LTCBTC: {}'.format(ltcbtc))
#print('BCNBTC: {}'.format(bcnbtc))
#%%
#Spread
est = sm.OLS(bcnbtchist, ltcbtchist)
est = est.fit()
hr = -est.params[0]
context.spread = bcnbtchist + (ltcbtchist * hr)
#%%
#Halflife
spread = context.spread
spread_lag = spread.shift(1)
spread_lag.iloc[0] = spread_lag.iloc[1]
spread_ret = spread - spread_lag
spread_ret.iloc[0] = spread_ret.iloc[1]
spread_lag2 = sm.add_constant(spread_lag)
model = sm.OLS(spread_ret,spread_lag2)
res = model.fit()
context.halflife = int(round(-np.log(2) / res.params[1],0))
if context.halflife <= 0:
context.halflife = 1
#%%
#Zscore
context.meanspread=spread.rolling(window=context.halflife).mean()
context.stdspread = spread.rolling(window=context.halflife).std()
context.zscore = (spread-context.meanspread)/context.stdspread
#%%
# Trading logic
context.i += 1
if context.i < context.halflife:
return
if context.zscore >= 1:
order(context.asset, amount=1)
order(context.asset2, amount= -1)
elif context.zscore <= -1:
order(context.asset, amount=-1)
order(context.asset2, amount= -1)
def analyze(context, perf):
ax1 = plt.subplot()
perf.portfolio_value.plot(ax=ax1)
#print(context.ltcbtchist)
#print(context.spread.shape)
#print(context.halflife)
print(context.zscore)
#print(context.meanspread)
#print(context.stdspread)
#print(context.spreadlength)
results = run_algorithm(initialize=initialize,
handle_data=handle_data,
analyze=analyze,
live=False,
start=pd.to_datetime('2018-7-1', utc=True),
end=pd.to_datetime('2018-7-2', utc=True),
exchange_name='poloniex',
data_frequency='minute',
quote_currency ='btc',
capital_base=10000 )
```

The zscore seems to be computed, it’s printable (context.zscore) and if you do this you’ll see plenty values above and below 1 and -1 (sell the spread and buy the spread thresholds) but no orders get opened. Any advice would be greatly appreciated.