I've messed around with backtesting for several years.
One idea i ran on backtest.org in 2009-2010 turned $10k into $13 million in 25 years and keep in mind that if the end date of the backtest was 2016 it would be closer to $20 million. Hopefully, one of you can code this since I'm just starting to learn Python:
Go for companies between market cap of $200 - $500 million dollars. Set EPS growth to %15 over past 3 years. Do not set the date higher than 3 years because you want new companies. Price per share over $4 so you are weeding out penny stocks. Stock pays no dividend. This weeds out the oil exploration and other unsavory business types. Also, you want a small company to be investing its money back into itself. Hold the stock for specifically 8 months. This is the window when micro-cap specific funds first come....when the stock breaches $250million or $500million market cap.
Around the same time in 2010, I ran a comparison of 36 strategies on my TD Ameritrade account. The winner is RSI 30 70 but even better is if I tweak the numbers to be closer to 25 75. I used a script from this site to replicate. Unfortunately I can't seem to add more than 4 stocks to the list. I would probably add a few other liquid & volatile ($1billion+ market cap) stocks such as Tesla, Shake Shack. In a perfect world I would combine the idea above with the one below. Go in and out of based on RSI of small explosive growth companies. You would really only be able to do this with a smaller account (sub $100k) because microcap stocks don't have the liquidity. This script below has Sharpe ratio of over 4. I was trying to do FANG but didn't know how to add Facebook.
This example algorithm uses the Relative Strength Index indicator as a buy/sell signal.
When the RSI is over 70, a stock can be seen as overbought and it's time to sell.
When the RSI is below 30, a stock can be seen as oversold and it's time to buy.
Because this algorithm uses the history function, it will only run in minute mode.
We will constrain the trading to once per day at market open in this example.
import talib
Setup our variables
def initialize(context):
context.stocks = symbols('NFLX', 'AMZN', 'BWLD', 'GOOG')
context.max_cash_per_stock = 100000.0 / len(context.stocks)
context.LOW_RSI = 24
context.HIGH_RSI = 76
# Create a variable to track the date change
context.date = None
def handle_data(context, data):
todays_date = get_datetime().date()
# Do nothing unless the date has changed
if todays_date == context.date:
return
# Set the new date
context.date = todays_date
cash = context.portfolio.cash
# Load historical data for the stocks
prices = history(18, '1d', 'open_price')
# Use pandas dataframe.apply to get the last RSI value
# for for each stock in our basket
rsi = prices.apply(talib.RSI, timeperiod=14).iloc[-1]
# Loop through our list of stocks
for stock in context.stocks:
current_position = context.portfolio.positions[stock].amount
# RSI is above 70 and we own shares, time to sell
if rsi[stock] > context.HIGH_RSI and current_position > 0:
order_target(stock, 0)
log.info('{0}: RSI is at {1}, selling {2} shares'.format(
stock.symbol, rsi[stock], current_position
))
# RSI is below 30 and we don't have any shares, time to buy
elif rsi[stock] < context.LOW_RSI and current_position == 0:
# Use floor division to get a whole number of shares
target_shares = cash // data[stock].price
order_target(stock, target_shares)
log.info('{0}: RSI is at {1}, buying {2} shares.'.format(
stock.symbol, rsi[stock], target_shares
))
# record the current RSI values of each stock
record(nflx_rsi=rsi[symbol('NFLX')],
amzn_rsi=rsi[symbol('AMZN')],
bwld_rsi=rsi[symbol('bwld')],
goog_rsi=rsi[symbol('goog')],)