sabren.net archives
back to sabren.net...
back to the
archive...
entries for 2002/8/12
simple test cases for montybot working
I'm always amazed what I can do if I plan to have a great
day, and then stay focused. Today I worked hard, ran a bunch of errands, and still had time to work on montybot.
The old python code is ugly as all heck, and doesn't even have
test cases. I'm keeping it around for reference, but basically
starting from scratch.
Here's what a trading strategy looks like after the first few test cases:
class BuyHoldStrategy(Strategy):
"""
I buy early and hold on until the end.
"""
def apply(self, hist, start_cash):
shares = 0
cash = start_cash
if hist:
price = hist[0]
shares = cash / price
cash -= shares * price
assert cash >= 0, "bought more than I can afford"
return cash + shares * hist[-1]
else:
return cash
It's neat, but it won't last. This code depends on knowing the entire history (hist[-1] means the final quote), so it only works for backtesting. I want to trade in real time. If I have time tomorrow, I'll figure out how to make that happen.
consistency
I weigh about 259 pounds today. About the same as I was at the start of the month, and the same as I was on 7/28. What's frustrating is that I've lost weight most of the past two weeks, as this chart shows:
The blue dots represent my actual weight each morning. The purple line is my goal. The green line represents what would have happened if instead of gaining weight on the four gain days, I had simply stayed level: basically, I'd be ten pounds lighter today!
It's not like I'm pushing myself to diet, or beating myself up with intense workouts. On the days I lost weight, I just ate sensibly and took a nice long walk. Some days I did pushups and situps. The weight gains came when I didn't exercise or didn't eat according to my six-small-meal-schedule, or both.
It's frustrating that I'm wasting this much energy going up and down, but at least I can finally see it happening. This is definitely motivation to stick to the plan I've laid out for myself, and it proves that what really matters is consistent action every single day.