This is my first day on quantopian and I've created my first algorithm based on a theory I've had for a while now.
Theory: ERX and ERY are direct inverse mirrors of each other. As one goes up the other goes down. If I can setup an algorithm that simply buys one on its way up and sells the other on its way down, profits can be made no matter what the market condition.
Reality: As you will see when you test my algorithm the return is nearly none existent, if not a complete loss.
I guess I'm looking for any sort of comments and or suggestions; coding related and or theory related. As noted above, this is my first go at a trading algorithm and I'm very new to technical trading so any ideas or suggestions would be much appreciated.
ERX / ERY - 10/30 cross
Theory: ERX and ERY are inverse of each other. If they are bought and sold in an inverse manor money can be made regardless if the market is going up or down.
Start of Algorithm
#define ERX and ERY sid's
context.ery = sid(37044)
context.erx = sid(37513)
#schedule a single trade everyday 15min after market open
schedule_function(erx_ery_cross, date_rules.every_day(), time_rules.market_open(minutes = 15))
define the trading logic
def erx_ery_cross(context, data):
#set var for security to be traded
stk_erx = context.erx
stk_ery = context.ery
#populate moving average information for both securities
MA10_erx = data.history(stk_erx, 'price', 10,'1d').mean()
MA30_erx = data.history(stk_erx, 'price', 30,'1d').mean()
MA10_ery = data.history(stk_ery, 'price', 10,'1d').mean()
MA30_ery = data.history(stk_ery, 'price', 30,'1d').mean()
#define current amount of stock owned for each security
current_erx = context.portfolio.positions[stk_erx].amount
current_ery = context.portfolio.positions[stk_ery].amount
#tradeing logic: compare MA and look for cross. perform this for BOTH securites
if (MA10_erx > MA30_erx) and current_erx == 0:
elif (MA10_erx < MA30_erx) and current_erx != 0:
if (MA10_ery > MA30_ery) and current_ery == 0:
elif (MA10_ery < MA30_ery) and current_ery != 0: