Showing posts with label strategy. Show all posts
Showing posts with label strategy. Show all posts

4.09.2013

2013: Quarter 1 Results

Yes, I'm alive! More importantly I wanted to share some results. One of the best things about automated trading as that like yourself dear reader, I wasn't sure of how well the strategies have been performing this year; especially those that are not running on live accounts :-) So here's some pretty pictures for you.

The strategy 'b' and strategy 'rs' are both on live accounts. b is one of my oldest strategies; a simple solid performer. rs is something that was moved up at the beginning of the year after very promising results. It's slightly down for the year after a great start. It will be one to watch.
Strategy b
Strategy rs
These are some testing strategies still being run on demo accounts. In general they need various amounts of love before they could be considered ready for live -- some are potentially even unfinished ideas. That said, monitoring how they do is an important part of determining eligibility to move them to live. Hopefully we'll see some more ideas be added to this list as the year goes on.

This one might be turning around. Might just need some tweaks.
Strategy con

Hmm, not so good.
Strategy cor
 Up/down? Movement? I'll have to dig into the basically flat results here.
Strategy l


5.16.2012

Tunnel Vision

Whoosh! Gone is the spring! Well, things have been ticking along on the trading front, and recently I found time to dedicate to coding again :-) There were some design changes to make and some wishlist items. But most importantly, there were strategies to port to the new abstraction layer. They haven't been running in some time due to the switch.
I spent a few hours this past week in earnest porting the strategies and making them work, adding new features to the common framework in support of the strategies, etc. It was only once the first one was running that I begun to wonder -- what in the world is this strategy attempting to do?
While I do like to think I do an honest job of commenting my code, it could always be improved. However the worst part of trying to port the code was the fact I failed to comment (aka, in simple concise English) what the purpose of the strategy was! This omission found in my earliest work was noticed and rectified at some point, but this strategy pre-dated that.
Desperately I searched through my revision history to find an older version that was perhaps simpler and more likely to be understood. Looking at the old version (before porting) did answer my question, but not in a good way. I now understood what the strategy was doing, but I hadn't a clue as to why. It simply made no sense at all.
This sent my head spinning -- I opened up some of the current strategies and although successful, they made no sense to me. I've simply had tunnel vision for too long.
Here I have been porting these things to run in the new and improved layer (making coding a strategy much simpler), but now I have no idea what the point and purpose of the strategies I have running and/or am porting is. I still have the idea of the general concepts of strategies I wish to employ -- some that should perform better in trending versus ranged markets, etc. However, the execution and implementation of those strategies seems to have gotten lost in the focus of coding the framework and making things robust. Time to sharpen my pencils and step back for a minute.
I realize I haven't looked at a chart, I mean really looked at a chart in a long time. Far too long.

1.26.2012

Still watching the euro

Since my last post, the euro has indeed put on an impressive rally back. People are doubling down on there shorts and just getting crushed. This momentum was really easy to feel in the ticks before the event. Still, I like to sit out counter rallies as a matter of safety -- it's way to easy to get caught in reversals and whipsaws. So what is the new trend for the euro this year? That anyone's guess -- as for me I'll just being watching and waiting for new trends. With statements like "low rates through 2014" from the Fed and Bernanke, the euro might not be the worst of the failing currencies in 2012 and could instead see us rally back towards 1.4X.

11.08.2011

Jesse Livermore, speculation, and people

I just finished re-reading Jesse Livermore's auto-biography,Reminiscences of a Stock Operator. What a wonderful read. In this post besides advocating anyone who hasn't yet read the text do so (you can find it FREELY available here: http://www.archive.org/details/ReminiscencesOfAStockOperator), I wanted to highlight a couple quotes from the book on people:

"I absolutely believe that price movement patterns are being repeated. They are recurring patterns that appear over and over, with slight variations. This is because markets are driven by humans and human nature never changes"

"On the other hand there is profit in studying the human factors, the ease with which human beings believe what it pleases them to believe; and how they allow themselves indeed, urge themselves to be influenced by their cupidity or by the dollar-cost of the average man's carelessness. Fear and hope remain the same; therefore the study of the psychology of speculators is as valuable as it ever was. Weapons change, but strategy remains strategy, on the New York Stock exchange as on the battlefield. I think the clearest summing up of the whole thing was expressed by Thomas F. Woodlock when he declared: "The principles of successful stock speculation are based on the supposition that people will continue in the future to make the mistakes that they have made in the past.""

"The message of the tape is the same. That will be perfectly plain to anyone who will take the trouble to think. He will find if he asks himself questions and considers conditions, that the answers will supply themselves directly. But people never take the trouble to ask questions, leave alone seeking answers. The average American is from Missouri everywhere and at all times except when he goes to the brokers' offices and looks at the tape, whether it is stocks or commodities. The one game of all games that really requires study before making a play is the one he goes into without his usual highly intelligent preliminary and precautionary doubts. He will risk half his fortune in the stock market with less reflection than he devotes to the selection of a medium-priced automobile."

On the surface, Livermore traded in a completely different world. Insider trading was rampant, stock manipulation and tip buy/selling was popular, bank runs were common... Hah, see not so different after all? In truth however, humans are the same. The same emotions that drove and controlled the market in Livermore's time do so today. We simply need to accept and understand this. I'll include a few more highlighting the inherent laziness and gullibility of man.

"The average man doesn't wish to be told that it is a bull or bear market. What he desires is to be told specifically which particular stock to buy or sell. He wants to get something for nothing. He does not wish to work. He doesn't even wish to have to think. It is too much bother to have to count the money that he picks up from the ground."

"At first, when I listened to the accounts of old-time deals and devices I used to think that people were more gullible in the 1860's and 70's than in the 1900's. But I was sure to read in the newspapers that very day or the next something about the latest Ponzi or the bust-up of some bucketing broker and about the millions of sucker money gone to join the silent majority of vanished savings."

How true! There is nothing new under the sun1! Re-reading Livermore's observations brings to mind the recent EVE Online ponzi scheme that rather successfully executed it's mission, netting a cool ~50k USD for its creators2.

All said, I will be continuing to study people. In understanding people, I will understand markets.



1. Ecclesiastes 1:9
2. http://www.evenews24.com/2011/08/14/the-1-trillion-isk-ponzi-phaser-inc-speaks/

4.17.2011

Why exits are more important than entries

Often when looking at trading strategies you find yourself looking for keys to figure out the start of a breakout or trend. Jumping on-board when a trend is starting ensures you have a good ride on the trend for healthy profits. But focusing on the entry point is flawed logic. It is the exit point that determines your profit, and ultimately, your success.

Exits are much harder to get right. Whenever you start something you have to think about your exit strategy. It's so easy in the beginning to get into a trade; think about the end. I find the end of something is far more interesting and telling than the beginning. This applies not only to trading, but life as well. Look over your trades for the last week. When did you exit the trade? Why? Don't get caught up on the P/L, or attempt to optimize the exit based on hindsight. You need to understand the raw thought process behind your exit. Study yourself, watch yourself. You'll find your logic may or may not hold when examined after the situation.

A wise sailor once told me, better to be on land wishing you were sailing, than sailing wishing you were on land. It sounds cliched, I know; but think before you trade. Not about profits, entries, or leverage, rather focus on how you're going to get out of the trade.

For myself, I think it's time I changed my exit strategies to be more focused for success, instead of minimizing damage. I guess one should play to the outcome you wish to see, and not the outcome you're trying to avoid.

4.09.2010

Investing like Nassim Taleb

George @ OnlineInvestingAI recently finished Taleb's first book called Fooled by Randomness. I was once again reminded of Taleb's trading strategies, and reminded myself to continue my own contrarian bent. I'm going to assume you know who Nassim Taleb is, and instead are curious how one might invest given this new strategy.

First a quick note. You need to look at all of you liquid assets as investable. Meaning, ideally you will want to calculate the percentages below against your total net worth -- not just simply money you can afford to lose.

The basic idea is to take 10%-20% of funds and buy out of the money options for pennies, and reap big when crazy events happen. Since you don't know when (and no one does) "Black Swans" will happen, you will slowly bleed money to the sellers of these options. The other 80% of your money place into the safest investments you can think of. Don't be so naive as to think US government debt is the way to go here. I would recommend (as would Taleb) buying government debt from several large and "safe" countries of your own choosing. You could try and diversify here, but if you've read Taleb's book(s), you'd simply be fooling yourself. If the US defaulted on there debt, who or what would be left in good shape? Don't misread me here. A US default is only a black swan away from occurring :-) The key is to try and minimize the risk on most of your money, while maximizing the risk on the invested 10-20%. When (not if) a black swan strikes again, you'll profit very nicely.

3.26.2010

Strategy Verification

How do I know my backtesting is sound? How can I verify a strategy is ready for live execution? I employ several techniques to ensure my backtesting results are sound and represent1 what would have actually occurred. Strategies won't be run in live mode with real money until I can check these off. A quick list:

1) Live test and observe
This is more of a general catch all. But running the strategy in live mode will find bugs you won't otherwise find. And sometimes, those could affect backtesting. Any math errors that the server also calculates will show up here.

2) Use debug statements
Dump stack traces during each state change. Be careful of information overload, but the more you dump the more you can verify.

3) Check for logic errors
Make sure your not "cheating" with any of your math. And also verify your boolean and conditionals are executing as you think they should

4) Manually step through data and match output with strategy
This one requires you to trade your own strategy. step by step, on the test dataset. This can reveal coding errors, or strategy errors on your part.

5) Re-run data from live mode in backtesting and compare results
This has to be my favorite. I consider it the ultimate test so to speak, when the strategy will give the same results on the same data, whether run in live mode or backtesting mode. Simply collect data from live mode execution, and rerun in backtesting mode.


1. To the extent that is possible -- backtesting will never account for runtime differences such as slippage, spreads, etc.

Framework Optimizations

During this downtime I'm working on coding the new strategies, and have found it beneficial and necessary in some cases to recode some of the old strategies for quicker backtesting. After all, when one can't be actually trading, what better to do than paper trade eh?

My typical strategy shell as it were has certainly evolved over the course of coding. It never seems to stay up to date, a I continue to add to the framework, and realign my thinking and strategy code. The latest set of optimizations are basic in thought, but slightly harder than first realized to implement. Up until this point laziness combined with several other factors has led to an abuse of running a calcPL() command1. Because of design overlap and poor coding, sometimes this was being calculated 2 or even 3 times per iteration. Obviously this is burning CPU cycles, but more importantly, it's taking valuable time away from strategy analysis and price feed updates. And of course, it's also why backtesting has slowed from "instantaneous" results to taking 10 minutes.

Despite knowing the issue, I decided to take the opportunity to profile my code for the first time. Profiling2 quickly pointed out the problem as well. Several hundred million calcPL() calls made for only a few hundred trades.

Rectifying this CPU waste has been a challenge. The ultimate goal is to completely remove any redundant calls to calcPL(), and instead allow the strategy to "know" when it needs to execute something. Obviously this means more upfront calculation and tracking, as well as storing the data. To the extent it makes sense, the objects have gained additional attributes that will store much of the data. Some of it will remain inside the client. Of course, this is only a first pass, and will likely see its own enhancements as time goes on.

The end result should create very fast iterations while running the strategy. Essentially the new processing order for each iteration will be as follows:

Get the exchange rate
Simple check to see if we need to act


Currently there is both a calcPL() layer and an analysis layer sandwiched in-between those steps. If your strategy can be re-written to fit the simple check model as above, even your smartphone could run it :-)

1. I also wanted to have realtime data of my PL. Instead of pursuing the proper solution, until now I've optimized the calcPL() call. To get this realtime PL data under the new model, there are several approaches one could take. Before coding much of the framework, I had a separate monitor process that also tracked PL. Separation is an easy and wise solution, as you can both monitor and perform additional analysis with it, and gain the separate process stability.
2. I used Devel::NYTProf and got a cool html graph output. CPAN makes things easy, so don't put off profiling for as long as I did.

2.18.2010

Of Systems

Creating a trading strategy isn't something to be taken lightly. It's important to remember we're running a business here. For practical purposes, I'm going to codify my thoughts on trading into trading robots. I have several in various stages of development. The concept behind having multiple robots is simply to target and profit from several different trading environments. Running them concurrently should in theory allow me to profit in any environment. Hehe. Any known environment 1.

1. You don't know what you don't know -- hence I cannot trade the unknown. But, if Nassim Taleb has shown anything, I can profit from it.