This one seems promising. It uses the pipeline and profit taking to take huge profits from the "bottom feeders". The general trend is very good.
This one seems promising. It uses the pipeline and profit taking to take huge profits from the "bottom feeders". The general trend is very good.
This is the next version. I changed it from weekly rebalance to daily rebalance. Also instead of instantly liquidating out of stocks, I attempt daily to sell them at cost basis. So unrealized losses are never realized with this version. There are obvious risks to that, but I still prefer not to lock in my losses. I think I would rather manually intervene in extreme cases, that absolutely must be liquidated. I think with daily, weekly, monthly addition of capital from my bank account, this would probably end up doing better than the "liquidate right now no matter what" version. Also, notice that I'm in a profit sooner. Just cannot let myself jump ship during downturns which end up deeper with this version.
Hi Charles,
I think there's a "return" missing right after log_open_orders in handle_data. Makes sense?
# This is the every minute stuff
def handle_data(context, data):
# Do NOT do anything if there are unfilled open orders.
# This helps to prevent overbuying.
if get_open_orders():
log_open_orders()
# Maybe Take Profit
for stock in context.portfolio.positions:
if get_open_orders(stock):
continue
Curr_P = float(data.current([stock], 'price'))
if context.portfolio.positions[stock].cost_basis*1.25<Curr_P:
order_target_percent(stock, 0, style=LimitOrder(Curr_P*1.002))
pass
Best