Polish, Polish, and More Polish – Finishing Touches
This morning was all about polishing my app. There are a few things that I need to see get done, but they are being done by another member of the team, and I can't really jump in there without making waves, so I'm doing more of the fluff stuff in order to get things to a production quality level. It's getting close, but it's not there - yet.
One of the things I patched up was the defaulting of the calculated expiration date. One would think that the model would look at the option's expiration and figure out when it really stops trading and then properly ages the instrument. After all, US Equity options that expire on Saturday don't trade on Saturday, so why have the caller tell the model that it's really halted trading on the Friday before the expiration. No matter what I might do, this is what we needed.
So I wanted to make sure we had a decent default for the option - even though they should all be set by a database pull. I've been around long enough to know that it's only a matter of time before one option expiration isn't in the database and then that guy has a date of 0000-00-00, and the code blows up. After all, who really checks those dates before converting them? Yeah... OK... I do, but that's why I wanted a default in the first place. So I created a little method to take a date in YYYYMMDD format, break it up into a struct tm structure, call mktime() and then look at tm_wday to see if it was a weekend. If so, I backed off to the previous Friday and used that as the default.
It's not perfect, but it's a lot better than doing nothing, and even better than just assuming the expiration is the calculation date. It's little stuff like this that junior programmers don't see the value in. They often think that there has to be a database row, and if not, then it's not their fault. It's not about fault - it's about being able to predict problems and write code to at least mitigate a bit of the problem if not correct it entirely. Yeah, it takes some time, and getting yelled at, to figure out that this is the stage to go back through the code and put in all that polish that you do on furniture in the finishing phase.
It's time well-spent.