Tuesday, March 27, 2007

Fun with XLL

The oldest comment I found while poking around the XLL project is dated Nov, 1996, a bit over ten years ago. I probably wrote my "hello, world" in C around the same time. Anyway, the goal is to call the excel plugin functions in C#/.NET. This should be straight forward, at least in theory: XLL files are merely DLLs with a few special functions. There is no reason they can't be loaded and called via DllImport. However, the following code throws a DllNotFoundException, and GetLastErr promptly returns no error code:

  [DllImport("myxll.xll", EntryPoint="GetVersion")]
  public static extern string XLGetVersion();
Digging a bit deeper with Depends, I found an excel library called XLCALL32.DLL, referenced by the XLL is the cause of trouble. The library can't be loaded with LoadLibrary outside Excel. I suspect that has something to do with the mysterious looking importing variable shown in the right panel below.A suprisingly simple solution is to manually pre-load XLCALL32.DLL with LoadLibraryEx and choose NOT to resolve any external references:
  IntPtr ptr = LoadLibraryEx("XLCALL32.DLL", 
        IntPtr.Zero, DONT_RESOLVE_DLL_REFERENCES);
Then the old P/Invoke trick turns back on (because XLCALL32 has been loaded). This obviously won't work if the XLL contains callback functions into Excel. But for everything else, there is DllImport... And here is a reference to the structure of XLL files. (link to complete e-book).

Monday, March 26, 2007

Walking Backwards

During the past two years, I have been walking completely backwards on the path of technology innovation:

So what's the coming attraction? A bit of 80x86 assemble would be fun...

Thursday, March 22, 2007

BlackStone S-1 Filing

BlackStone's planned IPO is definitely the latest hype in the PE space. The pros are already having fun with its S-1 filing. WSJ/BreakingViews suggests that the managing directors at BlackStone should actually take a pay cut in order to maximize their personal wealth.

Tools I have been using...

Time to create a list of tools I have been using in my current project before jumping into a new bunker next week:

  • SubVersion
  • I honestly don't have a preference when it comes to version control software. I have used VSS, CVS and now SVN. The differences in terms of file lock, branch etc are not really that big a deal. TortoiseSvn sure makes your life a lot easier by integrating version control into windows explorer though.
  • CruiseControl.NET
  • I had been using home-made daily/weekly automated build process and regression tests to ensure continuous integration, before I got to know CruiseControl.NET, that is. Make sure you install the client tool CCTray.
  • BugTracker
  • I feel that bug tracking tools are generally understated in the software development methodologies such as XP. Most developers are probably put off by the term "bug". But bug tracking tools are not limited to track "bugs", they can be used to track new feature developments, document design limitations and provide a structured "knowledge base" for the project. I have used Bugzilla in the past. Built on .NET platform, Bugtracker is not super sophisticated, but it's small enough to get your hands dirty on. And it probably provides enough functionalities for Scrum-sized development teams.
  • TWiki
  • I'm so obsessed with Wiki style documentation at one time, I was called the WikiMan... The benefit of using Wiki for knowledge sharing is that the documents created are naturely structured, and most Wiki implementations provide full-text search functionality. And also because it's so easy to use, a Caveman can do it... TWiki is not .NET based. It's on Perl and Apache. And I never got into the TWiki plugin stuff, which can probably be used instead of the bugtracker. I'd be interested to see a .NET implementation of Wiki --- it has to be at least as good as TWiki though.
  • Reflector
  • Any .Net developer NOT using Reflector? I use it primarily to get a peek into framework library implementations (and Whispering: third party tools). If, however, you want to gain some insights into CLR itself (GC, thread pool, etc), SSCLI is a better bet.
  • Regulator
  • If you ever need to write a multiline regular expression, you need this. Period.
  • ManagedXLL
  • Anyone in Finance will tell you that Excel is the best product of Microsoft. And any developer ever wrote a XLL plugin for Excel will tell you how painful that experience was. Creating Excel plugins in C# with ManagedXLL, on the other hand, is almost pain-free. You still need to watch out for the mysterious way in which Excel updates the spread sheets though.
  • CodeSmith
  • In retrospect, I probably used CodeSmith in a not-so-effective way: we used it to produce the DAO and Store Procs. The design of the system is less clean-cut:
    • If we take a data centric view of the world, we should probably take the typed datasets and push it all the way through out the system.
    • If the view is object centric, an O/R mapping tool (such as NHibernate) would be a better fit.
    There is nothing wrong with CodeSmith though. It's very useful when you need to produce large batches of template based classes.
  • Spring.NET
  • I dont' pretend to be an expert on IOC/DI or AOP. I have only used Spring.NET framework as a generic configurable Factory pattern implementation (IoC, in its simplest sense). Still, I feel the extreme flexibity the framework provides. In fact, I think the downside is that it makes developer easily over-design their system by abusing the pattern with too many dependency injections.
  • GenuineChannels
  • A bidirectional TCP channel implementation. A feature .NET Remoting developers have cried out for since the day .NET came to existence.
  • MSAS/PivotTable/ADOMD
  • This is the first time I tried OLAP reporting. The Microsoft OLAP pipeline is quite impressive, even with MSAS 2000. MSAS integration with Excel pivot table is seamless and it freed up developers from writing an ocean of custom reports as customers could easily slice and dice the pivot table in their liking, not to mention the update is realtime.
Of course, these are only from the special menu. The usual would undoubtedly include NUnit, Nant, log4net etc.

The Birth of "Bernanke Put"

After the "Greenspan Put" expired last year, a new one was born @ 2:15pm yesterday.

Tuesday, March 20, 2007

South Park Chess Set

Saw this on a friend's website today. There are a total of 16 Kennies, so it's 16 "bastards" waiting to happen. Any why aren't cartman the King?

Socialism with Chinese characteristics

A WSJ piece on Chinese Property Rights (the second part, after Citigroup's ABN Opening).

China's new law guaranteeing private owners the same rights as public and collective entities might sound like a capitulation to capitalist ideology. Not so, says National People's Congress Vice Chairman Wang Zhaoguo. Equal property rights are required to "uphold and improve the basic economic system of socialism." Whatever the words, Adam Smith would approve. ... And if 1.3 billion Chinese want to call it "socialism," why argue?
Welcome to the world of "Socialism with Chinese characteristics".

Sunday, March 18, 2007

Yen Carry Trade

The stock market and Yen have been trading in locked oppsite steps in the past few weeks. See DJIA and JPY 3 months daily chart above (the JPY chart is in Yen per Dollar). Does this mean that the power of yen carry trade is in its full force? When the stock market advances, speculators borrow more yen, convert them into dollar and invest in the market, hence contributing to the depreciation of JPY; when the trend in stock market is reversed, they unwind their positions and repay the Yen debt, pushing JPY up. The carry trade schema is no more sustainable in the long term than US current account deficit. The reversal of a depreciating yen could pose serious threat to equity investors. Could subprime or the emerging market problems pull the trigger? There is no way to know...

Friday, March 16, 2007

The Road to Market Economy

Thursday, March 15, 2007

What's Volatility?

Think you know what volatility is? Think again:

A stock (or a fund) has an average return of 0%. It moves on average 1% a day in absolute value; the average up move is 1% and the average down move is 1%. Assume that we live in the Gaussian world in which the returns (or daily percentage moves) can be safely modeled using a Normal Distribution. Assume that a year has 256 business days. The following questions concern the standard deviation of returns (i.e., of the percentage moves), the "sigma" that is used for volatility in financial applications. What is the daily sigma? What is the yearly sigma?
See this paper for the answers. This probably doesn't have much real world implication though. Once presented the full time serie of stock prices, instead of this "on average" stuff, I can't imagine any one would make similar mistake.