Back to Community
Smart Money Index for your perusal

Hi guys,

For one of my algorithms I built the Smart Money Index (wikipedia) and it helped to refine the strategy and or the entry size. It's not an indicator on its own, it should only be used to confirm your other indicators.

It's now build for one stock but if you build it in a panda structure you can make it multi stock. Anyone?

Clone Algorithm
17
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
from sklearn import linear_model
import scipy.stats as stats
import talib as t
import numpy as np
import pandas as pd
import pytz
import re
import datetime as dt 
from pytz import timezone
from zipline.utils import tradingcalendar
from brokers.ib import IBExchange 


######################################################################################################################## 
def initialize(context):
    ########################################################################################
    schedule_function(SMIopen, date_rules.every_day(), time_rules.market_open(hours=0,minutes=31))
    schedule_function(SMIpreclose, date_rules.every_day(), time_rules.market_close(hours=1,minutes=0))
    schedule_function(SMIclose, date_rules.every_day(), time_rules.market_close(hours=0,minutes=1))
    ########################################################################################
    set_symbol_lookup_date('2014-12-01') 
    context.secs = symbols('SPY')
    
    # These are the default commission and slippage settings.  
    set_commission(commission.PerTrade(cost=5.00))
    set_slippage(slippage.VolumeShareSlippage(volume_limit=0.25, price_impact=0.1))
    #Summary
    context.today = dt.datetime(2001,1,1)
    context.previoustradingday = dt.datetime(2001,1,1)

    context.lasttrade = {}    

    context.first_run = True
    today= str(context.today)[:10]
    context.SMI = {} 
    context.SMI[today] = {'open':None,'30min':None,'closemin1hr':None,'close':None,'smi':100 }    
    context.MSISeries=[]
    context.MSIMASeries=[]
    context.MSISlopeSeries=[]
    context.SPYcloseSeries=[]
    context.msi_window = 3
    

    
def SMIopen(context, data):
    #its just past the first 30 minutes and we want to know the action of today so far
    
    #I need at least one stock to get the data. the lazy way
    if context.portfolio.positions[symbol('SPY')] ==0:
        order_target(symbol('SPY'),1)   
        pass
    
    context.previoustradingday = context.today
    context.today = str(get_datetime().tz_convert('US/Eastern'))[:10]
    context.SMI[context.today] = {'open':0,'30min':0,'closemin1hr':0,'close':0,'smi':0 }    

    context.SMI[context.today]['open']=history(1, '1d', 'open_price')[symbol('SPY')][-1]
    context.SMI[context.today]['30min']=data[symbol('SPY')].price
    
def SMIpreclose(context, data):
    #its one minute before close and we want to know the action of today
    context.SMI[context.today]['closemin1hr']=data[symbol('SPY')].price
    
    
def SMIclose(context, data):
    #its one minute before close and we want to know the action of today
    if len(context.SMI)>1:
        #log.info(context.SMI)
        yesterday_smi = context.SMI[str(context.previoustradingday)[:10]]['smi']
    else:
        yesterday_smi = context.spy_open
    context.SMI[context.today]['close']=data[symbol('SPY')].price   
    todays_smi= (yesterday_smi - (context.SMI[context.today]['open'] - context.SMI[context.today]['30min']) + ( context.SMI[context.today]['close']- context.SMI[context.today]['closemin1hr']))
    
    context.SMI[context.today]['smi']=todays_smi

    
    
    #silly strategy, only use SMI for confirmation with another indicator
    indicator = 0
    if todays_smi > 1.01*yesterday_smi:
        indicator = 1
    # elif todays_smi < 1.01*yesterday_smi:
    #    indicator = -1
   
    record(smi=todays_smi)

    order_target_percent(symbol('SPY'), indicator, style=MarketOrder(exchange=IBExchange.SMART))
    
    
    
    
######################################################################################################################## 
def handle_data(context, data):
    pass
                 
######################################################################################################################## 
There was a runtime error.