I'm completely new to Quantopian. Here's my first little program using XIV as example
In the below example, the main idea is to look at each day, if the price of XIV is 2% below previous days close, the buy 100% of XIV, then place an order to sell the full position at a limit price of previous day's close (i.e. target 2% gain). The back tested result seems to show the below algo is not what's intended. Any comments please?
Also, is there a place on the site that one can find generic programs so that newbies can learn from.
def initialize(context):
context.xiv = sid(40516)
def handle_data(context, data):
hist = data.history(context.xiv, 'price', 2, '1d')
if hist[1] / hist[0] < 0.98:
order_target_percent(context.xiv, 1.00)
order_target_percent(context.xiv, 0.00, style=LimitOrder(hist[0]))
Wonder if this is the correct way to program the idea?