Disclaimer: I am not an investment advisor. When I describe my own trading activities, it is not intended as advice or solicitation of any kind.

30 December 2010

Wrapping Paper Everywhere

Just to warn you up-front, this is not a trading post.

The bintgoddess and I returned from five days in Michigan just yesterday, both with pretty serious headcolds.  This makes three colds for me in six weeks, which is just <sarcasm>really awesome</sarcasm>.  I'm trying to remember the preceding year or two when I watched the bintgoddess get colds at normal intervals while I managed to fend them off without a sniffle.  But bringing that memory forward over the ringing in my stuffed up ears is a little challenging at the moment.  I just woke up from 11 hours of sleep punctuated by bizarre pseudo-fever dreams, and the bintgoddess sleeps on.

The worst part is that we're pretty sure we both picked this up on Sunday, and we saw friends and family Sunday, Monday, and Tuesday.  I really hope we didn't pass it along to everyone else, but if the entire Detroit Metro Area fails to show up for work on Jan 3, 2011, you can blame us.

It was great to see many of our Detroit-area friends on this trip, and I have to say that the scheduling really worked out well.  We managed to see everyone we had discussed visiting, and didn't feel like anyone got short-changed on time.  We even laid some preliminary plans for going with another couple to Punkin' Chunkin' next year, which looks like a fantastic nerdy silly time.  With its massive Discovery Channel coverage this year, I'm sure next year's PC will be booked to the gills.

With all the friends and family we visited, it was a pretty full trip.  But there was still time to try to cope with four dogs and four people cooped up in a house.  My coping method of choice was to disappear into my laptop, where I started learning about delivering rich web applications via Flash movies (SWFs).  I'm working on a top secret project which I hope to deliver as a Facebook application, and I reckon Flash is probably the best way to make it a reality.  Unwilling to pony up hundreds of dollars for Adobe's development environment, I started looking at other avenues.

The one that I settled on is OpenLaszlo, named for either a painter, or a cat who was named after the painter, it isn't completely clear.  OpenLaszlo is an open-source language that is based on an interesting combination of XML and JavaScript, and lets you compile to either SWF (8 or 10), or to DHTML.  There are a few things you can't do in DHTML like embed fonts, but I think Flash is a better solution for my particular problem anyway.  OpenLaszlo's pedigree is impressive: H&R Block, Wal-Mart, and Pandora are all using OpenLaszlo to deliver rich content.

Over the break, I read through the QuickStart guide, and started digging my way through the Developer's Guide.  I've gotten to Chapter 10 (of 57), and so far have built a little test application that doesn't really do anything useful, but lets me exercise what few skills I have managed to accumulate.  You can check it out here if you're so inclined, but don't expect much.  If you're a developer-type and interested in the OpenLaszlo code that made it happen, you can find that here.  I added ".txt" onto the end of the file so that Firefox will just display it instead of trying to download it.  As I keep working through the Dev Guide, I will from time to time post my progress up on markmccracken.net.  I will probably not keep the source file up to date, though, unless someone asks me to.

16 December 2010

Predestined for Failure

Old Business
As I have noted recently, I am running about two to three days behind posting my trading activity.  There are a number of excuses for this, of course, and none of them all that valid.  I have also lagged behind in reading the blogs of others, and this morning I read an excellent post from one of my favorite options bloggers, Mark Wolfinger.  Unfortunately for my Iron Condor trade, I read it 11 days late. 

In this post he discusses the correct strike-pricing for protective debit spread adjustments.  He states several times that one should never buy farther OTM options than the iron condor itself, and that's exactly what I did.  Over the next few months, I need to reflect on this and tweak my adjustment strategy.  I'm hoping using this advice will help flatten out my returns, because I'm experiencing somewhat more volatility and stress than I would like, given the low income potential of this trade.

The AAII Sentiment Survey for 12/15/2010 still shows some very bullish investors out there, although slightly fewer than last week: 50% are bullish, down from 53% on 12/8/2010.  As expected, this results in a continued no-position for CS|MACO, which doesn't participate in trends that are fueled by investor mania.

New Business
I bought some Research in Motion (RIMM) puts this morning at the last minute.  I generally like to buy these a week or two before the earnings release, but I wasn't paying close attention and missed out.  RIMM has always been one of my favorite shorts during earnings season, and I personally think that they have no future without a major retooling of their business.  Nobody talks about "Crackberry" anymore, now it's Android this and Android that, with the occasional fan-boy crowing about iPhone coming to Verizon (still).  I was expecting RIMM to admit a further reduction in its market share, disappoint on earnings numbers, and guide lower for next quarter.  But that didn't happen, and when I left the office in disgust, RIMM was up 5%.  So tomorrow I'll unload the put for a 50% loss and move on.

Another put position I entered today was Kinder Morgan Energy Partners (KMP).  KMP owns and manages energy transportation and storage facilities in North America.  It has a positive correlation to natural gas prices, but not a dramatically high one because its income is fee-based.  Thus KMP's income fluctuates more with demand for natural gas than with natural gas itself.  KMP has a big dividend yield: 6.3%  So why short it?  Oh let me count the ways:

1. Jim Cramer loves it, and he usually loves at the top and hates at the bottom.
2. They have a $22B market cap, revenue of $8B, $192M in cash, and $13B in debt.  Debt is more than 50% of the market cap, and nearly 68x higher than cash reserves.  That means they're using debt to finance their dividends.
3. Quarterly earnings have declined 10.8% since this time last year, to $1.25/share.  Dividends are $4.44 per share, so they're also paying more in dividends than they're earning in profits.
4. They need to quadruple their profits in order to cover those dividends, but the highest praise that Cramer can come up with is that high dividend stocks are good in a rising interest rate environment.  Yes, true.  But that doesn't solve KMP's internal fiscal problems.

This stock needs to fall.  I bought some March 2011 puts on it, and I'm working orders to buy some more on a rally.  I don't know when it will fall or how far, but my puts are there to profit when it does.

Last but not least, I bought some calls on GLD (Gold ETF) today, expiring in March.  If the current short-term sell-off continues, I'll buy some more.  I'm looking for a GLD price above 150 by expiry.  That would be a massive return on the call investment.

15 December 2010

Now I Can Afford That Operation

The CiG trade, which bought Eurodollars on an entry signal a week ago, finally gave an exit signal on Monday at the close, so I exited the position by selling GEH1 at 99.59.  That gives a $75 profit.  Since I trade this in paperMoney, I wasn't paying a great deal of attention to how much I should trade, but this one really brought that home.  The risk of one Eurodollar contract is not equal to the risk of one S&P contract - not even close - and the margin requirements reflect that.  Eurodollars carry a margin requirement of $877.50 per contract, while S&P futures require $5625 per contract.  In order to take the same amount of risk, I should be trading 6-7 Eurodollars for every contract of S&P I'm willing to commit margin for.  If I had, this $75 profit would have been $450-525... very similar to the $500 I made on the S&P signal.

In other news, one of my Iron Condor exiting orders also filled on Monday, closing out my remaining 660/650 put spreads.  This leaves my protective debit put spreads on with nothing to protect, and it also tilts the delta into the negative territory again: -20.  With December expiry coming this weekend, and with implied volatility near its 52-week lows, it seems best to close this one out.  I'm working orders to close the two call spreads - the original 810/820 and the kite-component 830/840, the naked long 820-call of the kite, and the protective 630/640 put debit spreads.  Since my current position still has positive theta, though, I see no reason to rush things.  Either way the market moves it will approach my exiting limit orders, so hopefully over the next week or two we'll get a little end-of-year waggle so I can squeeze out a few cents per contract on the way out.  If not, I have a month before I have to make a final decision.  Once theta goes negative, or if delta gets uglier, the pressure will be on to make that decision a bit sooner.

I've had a limit-sell order working on Microsoft for a few weeks now, and it filled today.  I'm still a believer in the stock, but I bought quite a few shares of it when it was depressed, so I'm just rotating some capital out to bring my position value back down where I want it to be.  Readers of my facebook notes will recall that I had 5 "units" of capital in Microsoft.  This sell brings me back down to 5 units of capital in position value.

I'm expecting another increasingly bullish (for me that means bearish) sentiment survey this week, released tonight sometime.  If that's true, CS|MACO will still stand by and watch the Fed Cheerleaders... er, I mean Stock Market... without getting involved itself.

09 December 2010

Such a Slacker

I've been distracted most evenings lately from the four Xbox games I picked up during Black Friday madness, and so it has taken me even longer than usual to record thoughts, trades, and rambling nonsense.  As if that weren't enough to eat up my attention, the Bintgoddess and I just received our HTC Incredibles we ordered through Amazon Wireless, and I at least have been spending more time than I should customizing and moving into my new phone.  I had intended to switch from AT&T+iPhone to Verizon+Android when my contract ran out in August, but the Bintgoddess' pre-pay plan ran out of minutes, and we could save more money to switch us both to a family plan now, despite the early termination fee from AT&T.  With nearly free phones (1 cent each from Amazon Wireless) and free 2-day shipping, the choice was pretty clear.  And yes, Amazon did charge my credit card $0.02.  Silliness.

Iron Condor
The January 2011 Iron Condor position has required some adjustment to keep it close to delta-neutral recently.  Recall that I opened a 650/660/810/820 iron condor on Nov 8, and then adjusted it Nov 16 by buying a 630/640 put spread.  Since we're into December, I'm now erring on the side of closing positions rather than opening them - but I'll still increase a position if it's the right thing to do for the risk or the greeks.

The stock market had been rallying pretty hard the last week or two - in fact, it has been rallying pretty hard ever since the day after I put on that downside protection.  This is not a surprise - it's just how I roll: don't believe me? watch me play poker on Full Tilt sometime.  But I digress.  With the stock market rallying and delta going pretty negative, it was time for some upside protection.

First, I bought back about half of the 810/820 call spreads for 1.40: a very reasonable 10c loss.  This moved the delta up about halfway to where it needed to be, but gamma was still pretty negative.  Another up-move and the position would be in trouble again, so I beat the rush and put on a Wolfinger Kite Spread.  Specifically, I bought back an extra 810 call for 3.70, and financed that by selling four 830/840 call spreads for 50c each.  Not only did this bring delta to a nice manageable level and give me some much-needed upside protection, it also significantly improved my max-loss on the upside.  Of course if MDW is reading this blog, he's probably seething that it isn't a perfect Kite Spread - I should have sold the 840/850s, or reduced the sales by 1 contract.  Tough.  I am convinced this was the right trade to make, whether it can rightfully be called a Kite or not.

The next day, I took advantage of another rally to buy back a few of the 660/650 put spreads for 45c.  This lowered delta a bit again, but like the previous day's adjustment, it really helped out in the max-loss department.  The total position now has a nice flat S-curve to it, and theta miraculously is still 13.  So a sideways market for the next 30 days should net me about .25 per contract - that may not sound like much, but that's 2.5% margin-return on a monthly trade.

It's also about time to be looking for a February trade, but I'll learn my lesson from January and wait for volatility to come up a bit.  Using paperMoney is nice, because I have so much fake margin in there that I can make trading decisions without having to be concerned about margin.  If I want to put on February before taking off January, so be it.  Doing that with real funds would take some very careful money management... or more money than I have.

CS|MACO
Still very bearish signals (53% are bullish as of last night, way too many for my taste) from investors, who happen to be right this time about the market as it sustains an uptrend, and bullish signals from the trend following MACO component.  As a result, it still waits in (fake) cash.

CiG
Eurodollar futures (GEH1) gave a bullish entry signal on Tuesday, so I bought them at the stock market close for 99.56.  Trading Eurodollar futures is similar to watching a bad horror movie: long periods of mind-numbing boredom punctuated by moments of pure terror.  So far I'm in the boredom phase - two days after buying them, I'm up 3 ticks.  W00t!  No exit signal yet, so I wait.

05 December 2010

Happy 1975

It's 1975 this month in my "year a month" project, and my band list yields:

Black Sabbath: Sabotage
Deep Purple: Come Taste the Band
Rainbow: Ritchie Blackmore's Rainbow
The Who: The Who by Numbers
ZZ Top: Fandango!

This month is kind of a loser, though.  Mid-way through last month I used the Sabbath album to round out free shipping on an unrelated Amazon purchase.  The Deep Purple album just sucks, so I didn't get that one.  I had high hopes for Rainbow, seeing as how it is the debut album for one of Ronnie James Dio's earliest projects (let us not speak of Elf).  I was already familiar with Man on the Silver Mountain, and hoped the rest of the album would be just like it, but sadly no... didn't get that one either.  The Who by Numbers is a bit of a step up from some of their early pop-filled discs, but not quite what I'm looking for; I may pick it up someday, but not today.  Behind Blue Eyes is a big standout on this album, but of course we already have that one from the Greatest Hits album we picked up some years back.

Thank goodness for ZZ Top, or this month would be a complete bust.  This early ZZ Top is right on the edge of my blues tolerance, but if I'm in the right mood it's perfect.  I dig the live versions of a few of the songs at the end - they pulled out a few more stops live than they did in the studio.  I've never seen them live, but I certainly would if the chance came along.

Maybe the nicest part is that I had a $5 Amazon MP3 credit sitting around, and that is coincidentally the price of this album.

29 November 2010

CS|MACO last week

Last week, SPY closed below its 25-day moving average on Tuesday, so I closed the CS|MACO long SPY position Wednesday morning.  Wednesday, SPY rocketed higher, closing back above the 25-day; but the AAII.com survey also came out Wednesday after the close, and individual investors have gotten bullish enough again to make the CS component bearish.  Bearish plus Bullish = Flat, so CS|MACO is once again on the sidelines.

CS saved money that MACO would have lost, since SPY has closed lower than Wednesday the succeeding two trading days.  These periods of consolidation, where SPY hovers around even for a while, can get expensive.  I'm glad I have those individual investors to fade.

Mini-Rant
Speaking of fading individual investors, the topic of conversation over coffee at the office this morning was privatization of Social Security so as to give individuals the ability to manage their own retirement investments.  The general consensus is that this would be a great thing... for us professionals.  Investing well is hard: like any other probability-based activity, looking backwards in time at what you should have done makes it look very easy.  But actually doing the right things traveling into the future takes a great deal of effort, discipline, time, and -- dare I say it -- luck.
I'm trying to stay away from the political quagmires around dinking around with Social Security.  Whether I'm for it or against it doesn't change my premise here, which is that individuals managing their own money, in the aggregate, will severely underperform just about any index you care to use.  Despite my "morons" tag I throw in whenever I talk about individual investors, it isn't because they're dumb.  It's just that they have other things on their mind than investing.  The folks taking the other side of their trades (i.e. fading them), on the other hand, are professionals.  They spend all day every day thinking about markets, and most of them have vast resources at their beck and call for maximizing their return.

The reason investment banks such as Goldman Sachs have done so well and generated such staggering amounts of wealth is because they're playing against amateurs: you.  So the next time you get the urge -- if you ever get the urge -- to argue for the privatization of Social Security, think about who is more likely to profit in a trade between you and Goldman Sachs.  If you answer, "Me! I am! I'm above average!" then I applaud your confidence.  But please don't be insulted if you find me on the other side of some of your trades.

22 November 2010

Collar Trade for the Month

This weekend was expiry for November 2010 options, and the collar trade was short Nov 53-calls.  Since QQQQ closed on Friday at 52.47, those calls expired worthless.  I sold new Dec 54-calls this afternoon for 38c/share.  With QQQQ trading at 52.70 when I placed the trade, this just barely violated my "at least 2.5% out of the money" rule.  But the next strike up (55) would have been 4.4% out of the money and barely worth the commissions, so I felt it was close enough.

Not really anything else to say there... it's a pretty mechanical trade, and there was nothing all that complicated to consider this month.

19 November 2010

Trading Diary for Nov 19

CiG
On Tuesday, I closed a losing CiG trade at the open based on a view that the S&P Futures (ESZ0) were going to sell-off throughout the day.  It turned out I was right, and by the end of the day CiG had given a new Buy signal.  Following this signal with real money might have been psychologically difficult, since all Tuesday long the market was acting like the sky was falling; but that's the essence of a buy-the-dips strategy, and with paperMoney the buy decision was an easy one.

I closed that second long ESZ0 position on a standard CiG exit signal yesterday afternoon for a $900 profit.  I ended up with a $500 profit per $5500 in margin for the whole trade starting on Friday, which ends up being an overall above-average winning signal.  If I had gritted my teeth and held on instead of getting out Tuesday morning and getting back in Tuesday afternoon, the trade would be down $87.  Going with one's gut usually doesn't work this well, so I'm not sure whether to be proud of myself or not.  But I'm glad it worked out this time.

Yesterday's market was a perfect inverse of Tuesday's: everything was coming up roses, and nothing could ever stop the stock market's inevitable return to massive wealth-generating territory.  You know you're a contrarian if you read that last sentence and a little voice in your head screams "SELL"; in this case that was exactly the right thing to do.  At 9:05 CST, ESZ0 was back down to 1188.00, right back where it was when I dumped it on Tuesday.

I wonder if I'll get another buy signal today...

CS|MACO
On Wednesday, results from a new Independent Investor Survey were released and posted on aaii.com.  Not surprisingly, the rapidly falling S&P markets over the past week soured the backward-looking investors' outlook for the future; the bullish percentage dropped all the way to 40%, a massive 17.6% drop from the previous week.  This was enough to move CS from "initiate sell" to "no initiate, no exit".  Meanwhile, the bullish MACO signal had evaporated on Tuesday when SPY closed below its 25-day moving average.  So that meant the trade went from being locked flat due to opposing Sell!/Buy! signals to being flat due to apathetic meh/meh signals ("meh" is an official trading term I just made up that means "no clear view either way").

Yesterday, however, SPY shot up past its 25-day again and closed above it; this gives a clear new "Buy!" signal from MACO, and CS won't change its opinion until next Wednesday.  I should have bought SPY on the open today, but quite frankly I forgot all about it.  This calls for another official trading term to be thought up: I'll call this "psychological slippage".  In this case, however, I saved myself a little money since SPY was about 50c cheaper than yesterday's close when I realized my mistake and opened the position.  I'll take it.

16 November 2010

Big News for Boring Trades

It's been a busy few days.  The CiG trade finally fired a signal on Friday, but I was in Colorado all weekend so I didn't have time to write it up.  Then I came home with a head-cold just in time to support a major roll-out at the office that went pretty wrong.  By the time I got home last night all I wanted to do was sleep.  So now here we are.  Excuses excuses.
 
Saving Money While Asleep
First the CiG trade on Friday.  You may recall I decided to run it on S&P futures as well as treasury note futures, because I feared that treasury notes would bore me to death.  On Friday, it signaled a buy-on-close on the S&P, so I did.  Things were looking good Monday morning, but not good enough to reach the target exit signal.  By this morning, the whole world was fleeing from risk again and the stock market opened significantly lower.  Since there are no clearly-defined stop rules, I decided to sell the position for a loss shortly after the stock market opened.  I felt that what we were seeing was not a momentary blip but in fact a setup for a selling day.  I was right: I sold the position at 1188 at 9:00.  At the 3:00 close, ES was down to 1176.

Because CiG tries to buy on dips, though, it had another buy signal come out on ES today.  Pleased at my ability to dodge at least some of the sell-off today, I decided to get back in with a new long position at the close.  So I'm still long from Friday, but I took a 12-point ($550/contract) hiatus.  That's almost a winning trade all by itself.  Not a bad money-saving siesta.

No joy in treasury note futures yet.  Yawn.

Insert Spy Pun Here
CS|MACO, another boring trade, is finally starting to see some life.  It has been locked flat while SPY has rallied over the last 3 months, due to the bearish signal coming out of the contrarian investor sentiment component and the bullish signal coming out of the moving-average-crossover component.  One of those two opposing forces was removed today when SPY closed below its 25-day moving average, breaking the SPY>25MA>200MA relationship that has been in place since October 4.  That's not a sell signal yet, though, because the terms of the trade state that I won't enter a position on the removal of a signal.  I need the CS component to affirm its bearishness tomorrow after the close before I can short this puppy.

A Boring Iron Condor is a Good Iron Condor
Unfortunately, this one is starting to get a little exciting.  When I opened the position I groused about my poor judgment a little bit regarding the low price I was paid to initiate.  Sure enough, the VIX almost immediately rallied while RUT flagged, causing my delta to increase as I rode the curve down toward my put spread.  Delta of +16 this morning, so time to adjust already.

It seems ridiculously early to be thinking about exit orders, but I could buy back my call spreads for only 60c already; so I put in some limit orders to buy back at 20c.  That doesn't help my delta, but it does lock in a profit on half the trade - and with some careful adjustment the other half might not cost too much.

As for the put spreads, I looked at the mouse-ear like I used last month and decided it was overkill: RUT was 710 or so when I was adjusting, and my put spreads are 660/650s.  A mouse-ear would throw my delta so horribly negative that I would have to buy back most if not all of my call spreads to contain it.  Plus it was crazy-expensive, at $21.

The next thing I looked at was simply reducing the call spread position.  That would certainly help the delta and the feel of the position, but I felt the cost was a little high.  A variant of this is to roll the call spread down a few strikes, also increasing the position a bit to finance the roll.  This increases risk, and I wasn't happy with the outcome or my perception of the risk-reward trade-off.

I also looked at Wolfinger's Kite Spread, which involves a naked long OTM put and a credit put spread even farther OTM with 3-4x the size on it for financing.  That had some real potential, but it really hurt the theta.  Ultimately I decided I could achieve my delta goals and flatten the value graph best by putting on some 630/640 debit put spreads.  I bought just enough (at 1.90) to get the delta under +5.  By the close, the delta was back up to +5 again, but that's within my parameters.

Boring News for Big Trades
I'm still not holding GLD calls, and I'm glad.  I'm looking for bargains in some of the mining companies right now, but I haven't had time to look very hard yet.  Earnings season is upon us, and if I can capture a couple of positive earnings surprises before the event-driven IV goes through the roof, I'll be a happy camper.

08 November 2010

January Iron Condor

As I planned on Friday, this morning I closed the rest of my December RUT iron condor position for a total profit of 86c per original contract.  I opened the December position on 6 October, so that means I had just about an 8% return on initial margin over the past month.  By normal investing standards, that's an amazing return, but let's put this in context: the same strategy lost 7% on its November position and just under 2% on its October position.  To a normal buy & hold investor, this is pretty frightening levels of risk; to a professional in the futures industry that plays poker and trades options on the side, 8% in a month is bordering on boring.  All a matter of perspective.

On 15 October, I made a pretty big delta adjustment by buying a 760 call.  The original call spread was 770/780, so this is what is known as a "mouse-ear" adjustment.  This is one of the most expensive adjustments that can be made, but also one of the most effective.  I feel like given the market action during that time I should have taken a less extreme approach, but after the prior two losing months I was a little gun-shy.  Despite leaving some profit on the table by solving a minor problem with a big hammer, my confidence definitely benefited from a nice smooth month of price action resulting in a near-target profit.

I also opened a January 2011 position (650/660/810/820) this morning, although with implied volatility as low as it is I don't feel that great about the price I managed to get for it: only a 2.90 credit.  This is a little on the low side, and that reflects the low VIX environment that we're in.  I probably should have waited until VIX popped back up some, but this puts me into unfamiliar territory: I know that a good price during this time-frame is about 3.50, but I'm not quite sure what a good price is a week or more from now.  Rather than sail into unfamiliar waters, I chose to limit my profits over the next month or so.  I'm not sure that was a great decision, but I will persevere.

This is why we paper-trade.

By the way, if anyone tells you how easy it is to make money with Iron Condors, don't believe them - and definitely don't give them any money to manage.  It is a very difficult strategy that takes a lot of creativity and experience to manage effectively.  I'm certainly not an expert, and it might be tempting to discount my assertions of how difficult it is; but clearing companies' databases are littered with busted accounts that jumped into the trade without an appreciation for its subtlety and dangers.  I am determined to learn this trade and how to profit with it, and to succeed where so many others have failed.

Speaking of boring trades, CS|MACO is still dead-locked flat as CS is screaming short and MACO is screaming long.  Remember I said a trending market is not CS|MACO's friend? Yeah.  The other boring one is the trade I wrote up in Collaboration is Good, which apparently I haven't named - let's call it CiG.  No trades in 10-year note futures there, either, so I think I'll start running it in S&P and Eurodollar futures also.  I ran back through the chart for the last couple of weeks, and it wouldn't have traded anyway, so I haven't missed anything.

07 November 2010

Ranty McRant, volume 1

It's 7am on a Sunday, I've been up for 2.5 hours, and I'm feeling ranty.  The bintgoddess is very familiar with this situation, and I think (I hope) she finds it adorable; but this is the first time I've allowed my rantifications an outlet into the blog, so it feels a little special somehow.  This will be a little less researched than my other entries, and a little more free-association.  You've been warned.

Today's topic: hardware vendors and their sycophantic adoration of Microsoft Windows.  Yes, I realize I'm a Microsoft shareholder, and you'd think that it would make the most sense for me to support the obligatory installation of Windows on every machine created, since doing so would increase my shareholder value.  But let's face it, they don't need me.

My birthday is coming up, and that seems like a good excuse to replace my aging and case-cracked Toshiba Satellite laptop.  It's a ponderous beast, weighing in at about 75lbs and boasting a clock speed of about 15Mhz.  It's so old that it sports stickers that say, "Designed for Windows XP (Windows Vista Capable)", and "Intel Celeron M inside".  That's really something to be proud of, right there.  Sometimes the power cord gets tangled and I have to unplug it to untangle it.  Depending on how many seconds it takes me to do this, the laptop might stay on, or it might go into what I call Dirt-Hibernation mode.  In this mode, it thinks it's hibernating, but it never comes out (making it more like a dirt-nap).  It's a fun and useful piece of technology, especially for testing the effectiveness of rage management techniques.

I've been considering replacing the (no exaggeration this time) 40GB 5400rpm laptop hard drive with a 100-160GB SSD, figuring that doing so would still give me benefits when I eventually replace the thing.  But SSDs aren't that cheap, either, and I hate the thought of buying more hard drive storage... didn't I just wipe 21 HDs so I could dispose of them? I think I did.  What I really want is a sexy new laptop, something lighter, faster, more powerful, with a holographic screen that projects out to a 40" 3D image that hangs in space and lets me interact with it via telepathy.  Failing that, maybe one of those HP Envy notebooks.

So after doing about an hour of research, I flopsied over to the HP Store to configure a notebook just to see what I could expect to pay for the closest (albeit very distant) approximation to awesomeness.  Hoofah, this thing is pricey:

  • Long string of i5-Qwhatever-the-hell processor - god, Intel, SERIOUSLY?
  • ATI Mobility graphics - my only choice
  • 6GB of memory - upgraded from 4GB
  • 500GB 7200 HD, because this was the cheapest option and SSD was both $525 (omg) and whiteboxed (so it sucks)
  • No office software at all
  • Cheapest battery available
  • Several lines of "options" which were the only "options" available, including the screen, the DVD drive, the webcam, the wireless card, and (yes seriously) the keyboard.
  • Microsoft Windows 7 Home Premium - cheapest option
  • Adobe Suck-It We Own You Shop 8 Premiere

Total price: $1300.

Now, I'm a Linux guy.  I run Ubuntu 64-bit on my desktop machine, and the current doorstop-I-mean-laptop has just had its Ubuntu replaced with Mint this morning.  At the office I run a real-time variant of Red Hat Enterprise, and the file server in the house is running FreeNAS (based on FreeBSD).  Why the HELL would I want Windows 7 on my new laptop?  Is it because I like ad-ware like Norton Trial Edition popping up every few minutes to tell me that since I chose the most vulnerable operating system on the planet, I should pay an expensive subscription to protect it?  Is it because I like bloat-ware like Microsoft Office that lets me do really complicated things like write text for the low-low cost of almost 500 dollars, and several GB of hard drive space, and several hundred MB of memory?  Or is it because I want to respond to the daily Adobe pop-ups telling me I need to upgrade Flash, Streak, and Fondle, because this computer belongs to Adobe, after all?

No thank you.

I build my own desktop PCs so that I can put exactly what I want INTO the machine, and exactly what I want ONTO the machine.  When I boot it up, it does what I tell it.  I'm not naive enough to think that it does ONLY what I tell it - even Ubuntu has marketing-related goals that are not completely in line with my own.  But the "partnering" level is low enough that I view it as an acceptable trade-off.

Let me get this clear in everyone's heads: Linux is like over-the-air PBS.  It's mostly ad-free, although it has a few "brought to you by"s.  It costs nothing to enjoy, but it's considered good form to donate time/money/experience to help others enjoy it too.  And it gives a different, somewhat less accessible, experience from Windows; but for some people that experience is far better than Windows'.  On the other hand, Windows is like Cable.  It costs money, it has lots of options that all cost more money, it has a LOT more commercials than PBS, and the cable goes out a lot more than the transmitting tower fails.  You can find the same level of programming on cable/Windows as on PBS/Linux, but you have to look harder through the gunk.  It's extremely accessible - you can surf for hours without asking yourself a single thought-provoking question - but some people actually like thought-provoking questions.  I don't know any people like that, but I hear they exist.  They probably vote Green Party or something.

Anyway, I prefer Linux, and this is what I install into my home-built desktop machines (unless the bintgoddess requests otherwise, obviously).  But a laptop is tougher to build.  To make it all work together seamlessly, to keep it light, and to keep it from overheating, a lot more engineering goes into it from the hardware integrators.  I can't go buy a bunch of laptop parts from NewEgg and end up with my perfect laptop, so that means I have to go to the car dealership - er, I mean, computer retail channels.  There, I assume the position and start sucking down the "partnering", the "up-sells", and the "value-adds", just like everyone else.  Ugh.

My first action with this laptop would be to wipe the hard drive of all the crap-ware, and to install a nice clean Linux variant (probably Mint, since that's what I'm playing with at the moment).  Of course that means if I ever need service, I'll need to reinstall the Redmond Mothership because, obviously, anyone using Linux must be crazy.  But let's face it - the probability of being able to get laptop hardware serviced WITHOUT losing the contents of the hard drive is about 0.00004% (this is an actual statistical figure based on 15 zillion studies, not an exaggeration).  And barring actual hardware failure, there's very little that an HP-authorized service technician can do (other than screw up my computer) that I can't do just as well.  On second thought, I can screw up the computer about as well as him, too.  You're not skiing hard enough if you don't fall, and you're not really using the computer if it successfully boots every time.

But on a $1300 laptop, WHY am I being forced to get Windows?  I know it isn't free - Microsoft is charging HP a super-low OEM price, and HP is wrapping a profit-generating higher price into the price of my laptop.  Accepting a laptop with this operating system on it feels to me like taking out a $100 bill and setting it on fire.  I don't like that feeling when I'm in a casino, so I play poker, and I don't like it when I'm configuring computer hardware. 

Let's be really clear here: I am being charged money for something that I actively do not want.  I do not want it so actively that I am willing to spend my own time and effort to remove the offending product, assuming risk of loss (via supportability) in the process.  What kind of reasonable consumer would enter into a transaction like this?  What kind of reasonable retailer would EXPECT a consumer to enter into a transaction like this?

Wasn't there a big lawsuit recently about hardware vendors being required to give rebates to consumers that chose not to have Windows pre-installed?

My coffee is running out and my rant is running down.  Let me close with the chat transcript from my Live Chat support session.  It's not that exciting, but I feel like I need to have something other than my own prose in here to liven things up.


11/07/2010 04:56:09AM Session Started with Agent (Rachel P.)
11/07/2010 04:56:09AM Mark: "Configuring an Envy 14 notebook"
11/07/2010 04:56:15AM Agent (Rachel P.): "Thank you for contacting the HP Home and Home Office Store Chat. My name is Rachel."
11/07/2010 04:56:20AM Mark: "Hi Rachel."
11/07/2010 04:56:37AM Agent (Rachel P.): "I'm sorry. Can you please elaborate on your question so that I may better assist you?"
11/07/2010 04:56:38AM Mark: "I'm planning to replace Windows with Linux on this machine. Is there any way I can avoid buying Windows?"
11/07/2010 04:57:32AM Agent (Rachel P.): "I understand that you want to take out the Windows 7 from the configuration on the HP Envy 14 notebook, right?"
11/07/2010 04:57:41AM Mark: "right"
11/07/2010 04:57:49AM Mark: "I intend to install Linux."
11/07/2010 04:58:02AM Agent (Rachel P.): "I am sorry, Mark, but there is no option for you to take out the OS."
11/07/2010 04:58:23AM Mark: "OK, thanks. I will look at other companys' notebook options, then."
11/07/2010 04:58:46AM Agent (Rachel P.): "Do you have any other questions that I can help you with? I want to make sure that I have completely addressed your concern today and are satisfied with my service."
11/07/2010 04:59:10AM Mark: "Well since I am no longer buying an HP notebook, I can't imagine what you could help me further with."
11/07/2010 04:59:20AM Agent (Rachel P.): "Since you don't need any further assistance, would it be okay if I close this chat?"
11/07/2010 04:59:26AM Mark: "yes, have a nice day"
11/07/2010 04:59:28AM Agent (Rachel P.): "Thank you once again for using HP Home & Home Office Store Chat. Please sign up for our award-winning e-newsletter which features the latest products and promotions for our store. Visit our website at: www.hpshopping.com/newsletter"
11/07/2010 04:59:29AM Session Ended

05 November 2010

Iron Condor: December Adjustments

The upside protection I added to the December iron condor on October 15 has proven to be a profitable adjustment.  As the market wandered higher, I was able to bleed off theta while keeping the position pretty close to delta-neutral.  I've had some low-ball exiting orders working for a while, since getting out is still in front of me, and yesterday one of those orders filled, closing out a portion of my 620/610 put spread and locking in a nice profit on that portion. 

My work schedule yesterday was weird, so I didn't actually notice the fill until this morning before the open.  When I came in this morning, I discovered that between the closing of part of the put spread and the traveling of the market down the curve toward my call spread, my overall position was -20 delta.  That's a lot more delta-negative than I want it to be, so I started looking at ways to adjust it again.

My original plan was to bring the delta back to nearly 0 without turning the theta negative or increasing the overall risk, since after all I have only a little more than a month before expiry, and increasing position at this stage would be kind of dumb.  But the more analysis I do, it seems the best choice is to just close the position entirely.  From where the market closed today, net liquidation value on the position is about 82c per contract.  That's pretty close to the 1.00/contract level that I said made me "thrilled", so that's just fine.

I had already started working orders to adjust the delta before the close, and when I do that I always make the position-decreasing orders more aggressive than the position-increasing orders.  Today was a good example of why I do this, since only one of my orders filled and I didn't have a chance to adjust my other orders to make sure they filled on the close.  As it turns out, that's just as well, since I think I want to cancel my position-increasing orders anyway.

My original plan was to roll the 770/780 call spreads up to 790/800, also decreasing the position.  This costs a fair amount of cash, but it also brings my delta up to +4 again, and makes theta a very healthy +9.  But what am I really gaining by opening that 790/800 position?  My thinking was that I needed to partially finance the 770/780 call spreads, but if I can make 82% of my "thrilled" level just by closing the position, there's no financing I need to do.

So here's my current position, which reflects the partial closing the 770/780 call spreads, but nothing else.  Delta is all out of whack the other way, at +17, and theta is right at 0.  I've got orders working to close the rest a little behind the market.  Once it's open on Monday, I'll adjust everything around to be just about at the market, and put this December iron condor to rest.

Then I'll start looking at opening a new January position.

In other news, I was at the FIA Futures and Options Expo on Wednesday and chatted a bit with the people at the Think or Swim booth about why they're so mean about screen shots.  I actually talked to a young lady who works with Scott Garland, and she indicated that everyone there is nervous about overstepping their bounds with TD Ameritrade, the recent purchasers of Think or Swim.  So far TDA has more less left them alone, but the concern is that they'll get a lot more involved in the day-to-day business instead of just treating ToS like a profit center.

I understand their perspective, but I'm still a little steamed that I can't accurately depict my current position value here because of their concerns about intellectual property.

01 November 2010

Happy 1974

I've been conducting a fun little project over the past 6 months.  I went and looked around at all the bands I knew about or had a few songs or an album or two from, especially the older heavy metal stuff, and built a list of all the years on which they released albums (thank you Wikipedia!).  Then I started at the first year I had, 1968, and bought all the albums I lacked from that year.  Each month, I move forward another year.

I've really enjoyed the Black Sabbath and ZZ Top, but Deep Purple and The Who are starting to get on my nerves.  This month is 1974, so I bought the following:

Deep Purple: Burn
Deep Purple: Stormbringer
(seriously? two in one year? how high could that quality possibly be?)
Judas Priest: Rocka Rolla

OK, full disclosure, I skipped the Deep Purple.  I played samples on Amazon and decided I'd rather have the $20 than the albums.  They have a few songs I really like, but there's a pretty big percentage that makes me want to break a window with my body.  That raises the total cost of those $10 albums quite a bit.

Rocka Rolla is Judas Priest's first album, and the first JP album I've ever owned.  I know later on in their career Rob Halford's voice is going to drive me crazy, but right now it's interesting to hear them in their debut form.  I like to hear the original recordings of huge bands before they were huge, and compare the sound to what they evolved into.

30 October 2010

Collaboration is Good

NeighborTrader has been making some comments lately about a trade he has been backtesting.  At first, he was trying to work out a way to make it an intraday trade so that he could run it at the office as part of his job.  A fairly new trader like him tends to prefer that route, because he has a lot more resources to throw at it sooner if it goes well than if he has to save his money to cover the margin.  Unfortunately for him, after playing with a lot of different variables he came to the conclusion that the trade worked best on daily charts, which means long-term holding times.  Since our firm has a day-trading culture and isn't really set up from a risk-management standpoint to hold trades for more than a few hours, that pretty much precludes him running it as part of his job.

Knowing that I've been running long-term trades in paperMoney, he chatted with me yesterday about his trade and the methodology he was using to backtest it.  I have to admit, I'm pretty impressed at how rigorous he's being with it considering: (a) he has no academic or professional experience with formal backtesting; and (b) it's something he's doing for himself on the weekends and committing very little capital to.  He even went so far as to buy historical data, something most of the guys at the office don't do for their big trades.  He also bought a book to learn proper backtesting methods to minimize the chance of sample bias and curve-fitting.

Since it's his trade, I don't think it's right for me to go into it in detail on a public blog.  He gave me all the information I need to run it myself, and suggested some products to run it in, and I plan to do so, although I can't think of a good name for it right now.  But I'll leave the parameters a little hazy to protect his intellectual property.  Suffice to say that it is pretty similar to CS|MACO in that it looks to enter positions contrary to market consensus, but only to do so when it isn't fighting a strong trend.  It seeks to buy dips and sell spikes, and it's purely technical, using indicators widely available on most charting packages.  It also trades very infrequently, so I might have to run it on more than one product just to avoid being bored.

He's been running it in S&P-500 Futures (it needs a lot of leverage to succeed, and he understands futures very well since that's his job) and a couple of other products.  He just exited a trade in it today for a nice fat profit.  Since I already have CS|MACO running on SPY (the S&P-500 ETF), and I have other trades running on other equity indexes (Iron Condors on Russell, Collars on Nasdaq-100), I think I'll run it against US Treasury 10-year Note Futures.  This trades at the CME since they merged with CBOT, and it's available in paperMoney. 

Speaking of CS|MACO, it's been quiet for a while now.  Individual investors have stayed bullish (they've been right for once), and SPY has stayed above its 25-day moving average.  Long+short = flat, so I've been watching this whole move from the sidelines.  The last couple of weeks haven't been good for any trade except iron condors, with the stock market going pretty much sideways.  Something has to give with CS|MACO soon, though, because the 25-day moving average and the closing price are converging.

29 October 2010

Arms Race, Part 4

In Part 3, I went all the way down the pixel level to describe how my automatic Bejeweled player detects the color and type of the gems on the screen.  Today, we'll use that information to get ridiculously high scores in Bejeweled Blitz.

Detecting all the colors was pretty tough, and detecting the type of gem in each cell was even tougher; but now we need the software to make a decision and act on it.  Specifically, of all the possible trigger/target combinations available on the board at the moment, which one is the best one to do next?  I chose to go a pretty simplistic route on this, since I was, after all, writing this for the heck of it.

I do not have the software attempt to predict combos or other more advanced plays to maximize points.  This is something that humans playing the game do to some extent without even thinking about it, but it becomes more challenging for software.  Consider the picture below.  I have highlighted the 4 possible moves by drawing a red blobby line between the trigger and target gems.  Which move will generate the most points?  If you said "the bottom-right one", you would be correct, because both the green and red gems would be removed, not to mention the bonus you get from doing a combo move like that.  By the way, the software would call that move "6,5-7,5".  The best move that the software sees from this board is "4,6-3,6" - swapping the white and yellow gems in the bottom-middle of the board.  I'll explain why this is chosen shortly.

Which move is best?
So skipping the combos and any other move in which you choose things based on secondary effects, I can define some scoring rules by decreasing order of weight:
  1. Always use paths with multipliers in them first - this is a no-brainer, because that has long-term positive effects on the entire game.
  2. If a path has a crosshair in it, it will destroy more gems than any other move on the board - except maybe a hypercube, but the software doesn't detect those, so that's moot.
  3. If a path has a flaming gem in it, its explosion will take out a 3x3 square of gems as well as the path gems themselves, yielding 9-10 gems destroyed on a 3-gem path.
  4. Longer paths are better than shorter ones, because they destroy more gems.  Plus, they generate crosshairs, hypercubes, and flaming gems, so that's goodness too.
  5. Paths lower on the board have more opportunities to create combos than paths near the top.  All else being equal, pick the lowest path on the board.
Going back to our picture and following these rules, we can see that there are no multipliers, no crosshairs or flames, and no 4-gem or greater paths.  That gets us all the way to rule #5, where we pick "4,6-3,6" because its highest gem (all of them) is lower than the highest gem of any other path on the board.

OK, great, we have rules of how to pick a path, but we've gotten a little ahead of ourselves.  How do we find the damn things?  In the software, I have a Grid object with 8x8 GridItem objects (aka Gems) in it.  During the detection phase, I set the color and type of each of those gem objects.  When I'm done, I have a software representation of the board as of the last screen capture.  Then I look at each gem and check to see if it is the leading edge gem of one of the following patterns:

The four path patterns in their basic form
In the first pattern, the gray squares are optional.  Readers familiar with Bejeweled will notice that adding one or both optional squares on will cause the path to generate a flaming gem or a hypercube, respectively.  The first case also has a special sub-case where the mirror-image is also possible, with the trigger below the target rather than above, but only the first of the two optional gems is present.  In this special sub-case, we move the trigger to the optional gem position to form a "T" when the path is completed; this generates a crosshair, so it is obviously more desirable.  If both optional gems are present, however, we leave the trigger where it is because hypercubes are awesome - even if the software doesn't know how to use them right now.

Anyway, in examining each gem to see if it is the leading edge of one of the patterns above, I actually examine it 4 times for each of the 4 patterns above - once with each possible 90-degree rotation of the pattern.  Mirror-images are included as well, but they are done within each rotation, so it's only 16 (4x4) checks on each gem instead of 32 (4x4x2).

Once all the processing above is done, we have a full list of every path available for activating.  For each path, we generate a score based on the 5 rules discussed above, and then sort them by score in descending order.  Then we pick the best possible path and execute it by moving the mouse to the trigger, clicking, moving the mouse to the target, and clicking again.  I do the mouse movement and clicking using the XLib API again: XSetInputFocus, XSync, XWarpPointer, XQueryPointer, and XSendEvent in various combinations that I worked out primarily through internet searching and a lot of trial and error.

As I was coding all of this, I went with the most expedient code possible, rather than the highest-performing.  Again, it was a project being done for the heck of it, so spending a lot of time designing around performance was too much like work.  Nevertheless, as I reached code completion, I started being concerned that the image processing and path detection would take so long that the software wouldn't even outscore me.  After all, I can hit 350k pretty reliably every week, and my highest human score was 652k.  Besides speed, I also have the human judgment that lets me pick the combo path automatically as we saw at the start of the post.

I needn't have worried: the screenshot, the origin detection, the color and state detection, the Grid-building, the path detection, and the scoring and decision process all takes 9 milliseconds to finish.  In fact, this thing is so fast that it finds matches as gems fall that don't really exist.  This causes it to have a high mistake rate, so I actually have it sleep (do nothing) for 50 milliseconds between passes to give Bejeweled a little time to catch up.  Even so, it's still mighty fast.

Below are two videos, neither one using boosts.  The first was captured while I was manually playing, and while it's not exactly a stellar run, it's a fairly representative game, finishing with a score of 166k.  The second is a run using my software.  It gets confused a couple of times, pausing for a full second while it reacquires the origin; and notice how it just ignores the hypercubes and makes a lot of stupid plays.  And yet the score speaks for itself.

Playing by hand, for 166k


Playing by program, for 698k

Yeah, that'll do.

28 October 2010

Arms Race, Part 3

In Part 1, I explained my motives for writing software to play Bejeweled Blitz.  In Part 2, I defined the terms and general outline of a program to automatically play Bejeweled Blitz.  In Part 3, I'll start at the screen level and work all the way down to the pixel, showing how I detect the color and state of each gem on the grid.

Where to Begin
I run 64-bit Ubuntu at home, and my browser is Firefox.  To capture and analyze the contents of the screen, I used XLib API calls.  In X, every window is laid out in a hierarchy starting with the root window that holds the desktop, taskbars, and all the top-level application windows.  So first I open my display with XOpenDisplay and store it for the life of the capture job, since it gets used throughout the process.  Next, I wrote a function to search a given window for the word "Bejeweled" in its menu text (using XGetWMName).  If found, it returns a handle to the window.  Otherwise it uses XQueryTree to get an array of all the immediate children and recursively calls itself with each of them.  Then it is just a simple matter of calling that function initially with the result of RootWindow(disp, DefaultScreen(disp)).

Now we drop down a level from screen to window: specifically, the Firefox browser in which Bejeweled is running.  To get an image of that window, it is as easy as calling XGetWindowAttributes to see how big it is, and then XGetImage to get an XImage pointer that we can analyze pixel by pixel.  To get a pixel, I use XGetPixel, passing the XImage that resulted from XGetImage, and the X/Y coordinates of the pixel I want.  This returns me the RGB value of the pixel as a long integer, which I can break into separate color levels with a little ANDing and shifting.

The next problem is finding the grid origin.  There are a lot of better ways to do this, but I chose the simple brute-force method.  In the picture on the right, I've put a red box around the group of pixels that I search for to find the top-left corner of the grid.  To do this, I simply examine every pixel until I find one that matches the first pixel in the red box.  Then I check to see if every other pixel in my test section also matches.  If so, I offset to where the grid origin is and proceed.  Otherwise, I move to the next pixel and do it all over again.  Not especially efficient, but it gets the job done.  This spot on the board is key, because it is only there during game play, and it never changes color except for short time periods during hypercube and crosshair detonation.

Once I know the grid origin, I can divide the grid into an 8x8 array of cells, with each cell 40x40 pixels in size.  At this point I had to get a little more creative, because of the dynamic nature of the gems and the board.  The background changes color frequently in response to multiplier changes, power-ups, and game mode.  The gems also spin when they're clicked on, making pixel-by-pixel identification impossible.  The key here is to focus on what matters, and to eliminate that which doesn't.

Special Multiplier Processing
First I test each cell to see if it is a multiplier.  Through a great deal of manual playing and taking screenshots, I discovered that the x2, x3, and x5 multipliers all had the exact same X shape on the gems, but the x4 was a little different - I haven't analyzed anything higher than x5.  I decided the best way to handle this was to look for a set of pixels that were white, forming the X shape, but examine only those pixels that were common to both shapes.  What I ended up with was the set of pixels depicted to the right, where the gray pixels are white only in x4 or only in x2/3/5.  Then it was a simple matter of checking each pixel in the gem in the right positions to see if it was white.  Anything else that wasn't in the must-be-white list could be ignored.

If the previous step determined that the cell is a multiplier, then I do a special color test on it, different from other gems.  I check the color of a single pixel just above the "X".  Based on that color, I know the color of the multiplier cell and I stop processing it further for color.  In the picture on the right you can see the pixelated shape of the white X, as well as a red dot where I check the multiplier for color.

Sensing the Aura
The next bit of special processing is to determine whether the cell is flaming or is a crosshair.  These are almost as important to detect as multipliers, because using them increases the chance of getting a multiplier: especially crosshairs, which will generate a multiplier on every use, so long as the multiplier time limit has expired.  Crosshairs also require some special color processing later, so we need to know if the current cell is a crosshair before we start looking at color.

The way I detect crosshairs and flames is to look at the top-middle of the cell, actually bleeding over into the cell above it by one pixel and extending down two pixels into the current cell.  This area is never occupied by gems at rest, so it is a good place to search for auras.  Based on the average color in this region, I determine if we have a crosshair, a flame, or a normal gem in this cell.

Finally, I check the color.  To do this, I only look at the middle 12x12 square of pixels, because this area is all gem (no background) for all colors and shapes, and never is corrupted by flaming aura.  I take the simple average of each of the RGB values in the pixels to come up with the average color.  For non-crosshair gems, I can be pretty precise because there is seldom any variation.  Crosshairs pulsate, though, so I started by examining a bunch of frames of crosshairs and finding optimum RGB values.  Then the program works outward from these values until the calculated average value fits into the range of one of the colors.  In the picture on the right, we can see a flaming blue gem with a red border around its aura zone and its color zone.

Once I know the color and state, I can move on to the next cell, repeating the process until all 64 cells have been identified.  If falling gems, hypercubes, or other temporary embellishments cause a cell to be undetected or mis-detected, it usually has little to no effect on the outcome of the game.  There is enough going on at any given time that little pockets of misinformation can be absorbed.

The conclusion is in Part 4: Playing the Game

26 October 2010

Arms Race, Part 2

In Part 1, I explained my motives for writing software to play Bejeweled Blitz.  In Part 2, I define some terminology and lay some groundwork for the first step of actual programming.  I assume that readers of this blog have played Bejeweled Blitz before; if not, go to Facebook and waste some time.  When you're done "researching", come on back and read the rest of this post.  Since it's a visual game, I'll need to define some terminology so when I describe a gem type we'll all know what I'm talking about.

The board of Bejeweled Blitz is the entire Flash application, including the non-game screens and the artwork behind and around the actual playing area, which I call the grid.  The grid holds all the gems and other playing pieces in an 8x8 array of cells.  The top-left corner cell's top-left corner is the grid origin.  The X values of cells and pixels increase as we travel to the right, and the Y values of cells and pixels increase as we travel down.  The top-left cell is (0,0), and the bottom-right is (7,7).

Gems can be any of the following colors: Blue, Green, Orange, Purple, Red, White, or Yellow.  The majority of gems are in a normal state, but they can also be explosive (aka flaming), crosshairs, or multipliers.  There is also a non-gem piece called a hypercube (PopCap's term).  These are nearly impossible for my software to identify in a moving board, so I gave up on them and let them be.  Yellow gems can also be in coin form; they still work as yellow gems, but add 100 coins that can be used for boosts between games.  Coins collected during the game count the same as coins left on the board at the end, so in practice yellow gems and yellow coins are equivalent.

Normal
Flaming
Coin
Crosshair
Multiplier
Hypercube

Points are generated by removing the gems from the board, which is done by forming paths of matching gems by swapping two adjacent gems.  Paths can be 3, 4, or 5 gems long.  Depending on the shape and length of the path, flames, crosshairs, or hypercubes can be created from the path.  Since gems fall into the empty spaces left by paths after gem removal, it is possible to get a combo bonus when falling gems fill the holes of a new path.  Multipliers are generated when enough gems are removed in a single move; I think that number is 10-12, but I'm not sure.  There is also a no-multiplier time limit after one is generated, which my software doesn't account for.

Normal gems, coins, and multipliers remove only themselves when matched in a path.  Flames remove a 3x3 square with themselves in the center.  Crosshairs remove the entire row and column upon which they reside.  Hypercubes do not get used in a path: instead, they remove all gems of the same color as whatever gem they are swapped with.

The user must continually look for opportunities to create paths by swapping adjacent gems.  I refer to gems that form a path as path members.  Since only two gems can be swapped per move, we can define the trigger gem as the one which is out of place.  We can likewise define the target gem as the non-matching gem in the trigger's way.  Swapping trigger and target forms the path, removing the gems and activating any special properties in that path.

Speed is of the essence, as mentioned before.  If paths are formed fast enough, a speed bonus is built up; if this is maintained long enough, the game switches into Blazing Speed mode for a few seconds (10, maybe?).  In this mode, all normal trigger gems and coins are treated like explosive flames.  Note that not all members of the path explode - just the one involved directly in the swapping operation.  Thus combos do not get more explosive than normal, either.

A general outline of a working program to play Bejeweled, then, might look like this:
  1. Locate the origin of the grid on the screen
  2. Detect all the gem colors and properties
  3. Build potential paths with triggers and targets
  4. Choose the optimum path and swap its trigger and target gems
  5. Loop back to 2 until the game is over
I felt that the hardest part of the program was detecting the gem colors and properties, so I tackled that first.

Stay tuned for Part 3: Gem Color Detection

24 October 2010

Arms Race, Part 1

Like many of us, I'm on Facebook.  I try to stay away from the social games, since most of them are poorly veiled attempts to hook your brain on electronic crack until you're willing to pay for it (I'm looking at you, Farmville), and some of them are out-and-out information pirates.  But one that I succumbed to completely was Bejeweled Blitz, created by PopCap.  PopCap is truly the master of simple little games that will suck your life away, and I have had my brain claimed by Bejeweled variants from PopCap and other developers before.  In fact, I share this weakness with one of my online poker friends, Missy; I convinced her to sign up for Facebook by telling her about Bejeweled Blitz.  Full disclosure, she was thinking about it anyway, but I think hearing there was a cool new (to her) Bejeweled variant free on Facebook was the final straw.

A quick note about how Bejeweled Blitz differs from normal Bejeweled: it's a 60-second game, so speed is of the essence; there is a personalized high-score board where all of your Bejeweled-playing Facebook friends automatically show up; and they reset the scores every week so that everyone is trying to beat each others' scores all the time.  Here are the top 5 from this weeks' high score board for my group of friends, which I am coincidentally dominating.

Missy and I are both very competitive, and we're used to facing off against each other at the poker table.  It wasn't long - like 3 games, maybe - before she had beaten my high score and I was grimly playing for all I was worth, trying to stay in the #1 spot.  Sixty seconds at a time, I watched hours disappear.  I think it was Missy who coined the phrase "stuck in a Bejeweled loop"; ironically, she was referring to her husband Todd when she first said it, but it easily applied to both of us as well.  Missy became my nemesis, my baby-with-one-eyebrow, my standard against whom my scores were judged.  We both waged psychological warfare, purposely getting semi-OK scores early in the week intending to re-up them when the other person beat the first round.  Sometimes others on my list would set higher scores, and I did my best to beat them, but failing to do so was never as infuriating as allowing Missy to win.

As we both practiced for literally hours per day, we got to be pretty good at it.  In the spirit of competition, Missy would occasionally accuse me of cheating when I set a particularly high score for a week.  In one conversation, she commented that Todd had semi-jokingly suggested that I had written a program to play Bejeweled for me.  I was flattered that he gave me so much credit - I thought that writing such a program would be so tough as to not be worth the effort.  But it got me thinking: could it be done?

Playing Bejeweled for hours a day, 60 seconds at a time, is a great way to waste your life.  But I found that my mind would wander while I played, letting me muse on the activities of the day and look at them from many different perspectives than I usually would.  When I started playing I was coping with a very unpleasant work situation that I hadn't decided how best to change.  As things came to a head about a year ago, I think my time playing Bejeweled after work was therapeutic and productive, letting me find creative ways to deal with some of the less technology-related problems (i.e. politics) that I would not have considered if my mind weren't idle anyway.

Fast forward 8 months or so, and I had no major problems to work out while I played Bejeweled.  My work-related stresses were greatly diminished, and I once more felt like I was contributing my best to a company that appreciated my strengths and gracefully accepted my weaknesses.  That left me with a problem-solving technique in search of a problem.  When Todd commented about writing a program to play Bejeweled automatically, I found my problem.

Stay tuned for Part 2: Defining the Game

21 October 2010

So Much For That Plan

Gold for Cash
In my last post, just two days ago, I briefly outlined my plan for disposing of my GLD Dec calls.  I said that I wanted to hit a price or time target, and when either thing happened I was out.  Of course the very next day gold prices dropped 3%, and then another 2% today, wiping out 20% of the value of my calls.  I'm not quite sure what's going on, but that was outside my comfort zone, and I dumped the calls today for quite a lot less than I planned.  Now that I'm out, I'll detail my price/time limits a little more.

I bought the then-ATM calls over the summer for $5/share of GLD, believing that gold would appreciate in the fall.  Boy did it, and it wasn't long before I was able to sell less than half of them for about $11/share.  That took my initial investment off the table, and I kept the rest riding.  I saw them reach somewhere around $17/share at their high, and I had a price target of $25/share to get out of the rest.  That was pretty aggressive, but I also had a time limit.

Uncomfortable, as I said on Tuesday, with the many small indications of a coming correction in gold, I wanted out soon.  I think most people are idiots (see the CS part of the CS+MACO trade), and when everyone's bullish, it's time to sell.  Worse, literally the whole world is hanging on QE2-related verbiage expected in the minutes from the FOMC's meeting on November 2 & 3.  That economic release is doomed: QE2 is already fully priced in, and all the Fed can do now is disappoint.  At the very least, all the IV comes out of the options after the announcement because the inflection point will have passed.  I definitely wanted out by Nov 2.

I have assumed for quite some time that I am riding a bubble forming in gold, and I swore that unlike the turn-of-the-century tech bubble, I would neither miss the run-up nor hang on for dear life during the pop.  That's why I have been in and out of leveraged gold positions via calls for the last year or so, and that's why I'll get back in after the mid-bubble correction makes everyone hate gold again.  I'm pretty bummed that I gave up so much of my profits by dumping today, but I still made about 150% on the trade since August, so I have no major complaints.

Speaking of CS+MACO...
Adding to the bearish signals this week, AAII published its survey results yesterday after the close: more people are bullish again.  With the CS portion screaming "sell!" and the MACO portion insisting "buy!", CS+MACO is still flat and will stay there for at least another week.

18 October 2010

Assorted Trades

Iron Condor
On Friday, I decided to add a little up-side protection to my December Iron Condor.  I'm trying to act when delta starts getting out of whack, and after a few days of stock market rallies the Dec IC was looking at a delta of about -20.  Sadly I can't be more precise on this because I forgot to jot it down (mental hand-slap).  Anyway, I decided the adjustment that made the most sense was to buy a Dec 760 call.  With my IC strikes at 610/620/770/780, this puts the naked-long call just one strike below my short call.  This adjustment brought my delta up to about +4 as of now, and didn't hurt the theta too much - still nearly 21.  It cost me 9.50, which is a big chunk of change, but I expect it to be the only upside adjustment I'll need to make to this position.

Until I come up with a better solution than Excel, unfortunately I can only display value-at-expiry.  Trust me when I say that current portfolio value is a lot curvier and much more attractive than this.

QQQQ Collar
Also on Friday, my October covered call on QQQQ as part of the collar trade expired in the money and I was assigned on the call.  Pursuant to the rules I set forth in September, I bought QQQQ back this morning at 51.50 and sold calls against it with a strike price of 53 for 56c.  Here are those rules again, since I keep having to search Facebook Notes for the numbers:

1. Monthly calls to be about 3%, and no less than 2.5%, out of the money.
2. 6-month put to be 8% out of the money.
3. No rolling prior to expiry.

Gold Leverage
I am still long-term bullish on gold, and I express that by being long GLD, GDX, and AEM.  I also currently have some Dec calls on GLD that are so profitable that I have sold off enough to cover my original investment and the remainder are worth almost twice what I paid for the whole stack.  Nevertheless, I'm becoming concerned with the borderline irrational expectations for QE2 lately, so I'm ready to take some profits.  I started working a fairly distant sell order on the rest of my GLD calls this morning.  Hopefully it will reach my target price and I'll exit there, but I also have a time limit on this trade; I'll exit when that time limit expires regardless of the price action.

17 October 2010

A Too-Short Weekend

Some friends converged on Chicago for a couple of days of poker and fun this weekend.  Russ came from south Florida to brave the "nice February weather", Emmy sacrificed an important college football game in North Carolina, and Terry brought gifts to commemorate his soon-to-be-champion Oregon Ducks. 

Friday night I hosted the Welcome to Chicago evening, since I live so close to the airport.  Nat came in from Gurnee, bringing his own houseguest - Mike from Germany, who turned out to be a very solid poker player.  We played tournament style first (I came in 2nd to Terry), and then some cash.  Since all of us know each others' play styles so well, it often turns into an over-play contest when we play against each other.  Friday night was no exception, with my personally most embarrassing hand being one in which I bluffed with 8 high into Terry only to discover he had the hand I was pretending to have.  After blowing off an entire buy-in by trying to force the action while card-dead, I rebought and tightened up, able at the end to come back and finish slightly up for the night.

When the night was finally over, Nat and Mike took Terry home with them where he was staying, and Russ and Emmy stayed with us.  The next morning after a quick trip to Panera for some coffee and bagels and a heads-up game with Emmy while Russ got ready to go, we all met at Heaven on Seven for lunch.  We were all due to meet back at Nat's at 7pm for resumption of the night's poker festivities, and everyone was feeling a little iffy from the night before, so we decided to have a laid-back afternoon at my house.

What followed was the bloodiest heads-up shoot-out I think I've ever played in.

We had six people participating, so we drew straws to see who would play in the play-in games, and who would get byes and be able to buy straight in.  Terry and I squared off in one of the play-ins, and Emmy and Nat faced each other in the other.  The best thing I can say about the play-in is that at least by losing it the shoot-out cost me nothing.  Nat won the other a few minutes after Terry beat me, and Emmy and I found ourselves dealing for the next round.  There, Russ beat Terry and Nat made short work of Mike.  The final round was also over in a flash, with Russ taking home the win.  This was practically a replay of our last shoot-out in Atlantic City this spring: Terry beat me in a play-in round, and Russ won the whole enchilada.  At least this time I was smart enough not to put a side-bet on the round with Terry.

Total time for the entire shoot-out: 35 minutes.

Saturday night was an unqualified success.  Nat has a custom poker table in the basement of his new house, and between our out-of-town guests and local poker friends (Marc, James, and Scott all made it), we filled it to capacity.  Since Minnesotans Missy and Todd couldn't work out the logistics of a weekend in Chicago, Nat set up a video Skype call so that they (mostly Missy) could at least enjoy the conversations and atmosphere even though she couldn't play.  Again we started with a tournament (I squeaked past the bubble and finished 3rd to James and Scott), and then moved on to cash.

Nine-handed play encourages a tight style, so to generate a little more action we instituted a 7-2 meta-game.  The way this works is that whenever someone wins with 7-2 - usually with a bluff, obviously - they can show it and have everyone at the table pay them an agreed amount - in this case, $2.  This makes winning with 7-2 much more profitable than simply picking up the pot, especially at a 9-handed table.  As a result, when a player starts betting aggressively it is natural for his opponent(s) to speculate on whether he has a big hand like AA or instead might have 7-2 and be on a big bluff.  When a player folds to 7-2, humiliation ensues from everyone at the table who is annoyed that they have to pay the winner an extra $2.  It's good clean fun.

As I write this, Russ, Emmy, and Terry are scattering back to their respective corners of the country.  For me, at least, this was one of those great weekends that I was sorry to see end today when I dropped Russ and Emmy off at the airport.  I really enjoyed having them stay with us, and I was pleased to finally introduce them to the Bintgoddess and let her see why I count them among some of my closest friends.