Milktrader

Iterating Until Convergence

Thursday, January 13, 2011

Nesting Ruby's Ternary Operator

At first, I thought I might blow up my insect factory for good when I tried this little bit of code. There have been minor explosions in the lab for weeks now and the neighbors are starting to get suspicious. I've given up trying to fix the drywall in the interim as the task has become sisyphean. Do you remember in Iron Man when Tony Stark finally got his portable nuclear power source to work? Well, that's what this is. Behold the heart of White Bumblebee, implemented in Ruby code.


 fast > upper  ?  puts("Long")  : 
 fast < lower  ?  puts("Short") :
                  puts("Testing Current Position")

You can google the Ruby ternary operator, but I haven't found a nested implementation so you can understand my concern about possible bug shrapnel back at the lab. I prettyfied the code, because that's what they do in Ruby world. They are big into pretty. And they scorn ugly. Me? I'm not a metrosexual sort of guy, more jeans and t-shirts and baseball caps with golf marker clips attached. But I'm comfortable being in the same room.

To get White Bumblebee fully implemented in Ruby, I need to achieve several things. First is importing data. This is being accomplished with the yahoofinance gem. Next step involves some data manipulation, or let's call it coding trickery, to get the data clean for analysis.

I'm running into a bit of trouble with the subsequent step of applying technical analysis to the data. I've decided that instead of implementing technical analysis in Ruby from scratch, it would be more prudent to borrow someone's library. Alas, unlike the yahoofinance gem for getting data, there is no gem for getting simple technical analysis. But, there is a Ruby wrapper function called talib_ruby that makes available the C/C++ TA-lib library of technical analysis functions. I'm a bit foggy on how to actually use this wrapper function to get to the C/C++ functions, but once the fog clears, the road is a trivial path.

Then, I simply iterate a hash of data through the White Bumblebee super-reactor and it's time to blast off into the world of real trading.

2 comments:

  1. Hey Milk Trader,
    Awesome blog btw ,congratulations. I just felt slightly lost though how you got to coding White Bumblebee in Ruby. I mean i understand the Traderstudio->Excel->R->C progression as you were trying to develop better tools for your market analysis but where did Ruby come from?
    Also have you developped your first trading system yet that has been deployed with real money?

    ReplyDelete
  2. Ruby is part of my polyglot curriculum. Also, it is the foundation of Rails, which I'm using for a website concept. As far as deploying money with a system, I have arrived at an existential crisis with the whole idea. What I really don't like about systems trading is that it attempts to eliminate human intervention instead of leveraging it, and this is a problem for me.

    Glad you enjoy the blog.

    ReplyDelete