Hello everyone.
I am a novice, im learing python when i programming quantopian , and I do not have the knowledge to do some things, so I ask for help.
I'm doing a system based on the coppock curve.
#Importamos las librerias necesarias
import numpy as np
import pandas as pd
import talib
#iniciamos el sistema
def initialize(context):
#Definimos todos los activos operables
context.gold = sid(26807) #GLD
context.bonds = sid(23921) # Bonds USA over TLT
context.bondscorp = sid(38952) # Bonds Corp Over
context.bondshigh = sid(41604) #Bonds Corp High Yield Short term
context.sp = sid(22739) #SPY
#context.btc = cooming soon
# Funciones programadas, benchmark, comisiones splippage etc..
schedule_function(sp500, date_rules.every_day(), time_rules.market_open())
set_benchmark(symbol('VTI'))
set_commission(commission.PerShare(cost = 0.0050, min_trade_cost = 1.00))
set_slippage(slippage.VolumeShareSlippage(volume_limit = 0.025, price_impact = 0.1))
#Definimos el modulo sobre S&P 500
def sp500(context,data):
#Variables Locales de SP500 para su coppock
roc_1 = 14
roc_2 = 22
cop_wma = 10
bars = roc_1 + roc_2 + cop_wma + 1
#Procesamos el precio, y realizamos el coppock sobre el S&P 500
prices = data.history(context.sp, 'price', bars , '1d').dropna()
roc1 = talib.ROC(prices, roc_1)
roc2 = talib.ROC(prices, roc_2)
roc = roc1[-cop_wma:] + roc2[-cop_wma:]
Coppock = talib.WMA(roc, cop_wma)
if(Coppock[-1] > 1):
order_target_percent(context.sp, 1)
log.info("( Coppock S&P 500 : %.2f )" %Coppock[-1])
log.info(" [SPY] - Hay posiciones por Coppock Positivo ")
elif(Coppock[-1] < -1 ):
order_target_percent(context.sp, 0)
log.info("( Coppock S&P 500 : %.2f ) " %Coppock[-1])
log.info("[SPY] - No hay posiciones por Coppock Negativo")
I would like to add the condition to if
if(Coppock[today] > Coppock[Yesterday):
order_target...............
But I do not know how to do it, could someone give me a solution?
Thank you for all, and sorry for my poor english.