defjukie has asked for the wisdom of the Perl Monks concerning the following question:
I wonder whether anyone has attempted to use Perl to write scripts to back-test various trading strategies? I have written a simple program to test a simple interrelationship between sterling and dollars, and the strategy I tested (unsurprisingly) failed. Ah well, t'was merely a programming exercise...
Has anyone else attempted more complex trading systems using Perl and how did they find the compatibility of Perl with statistical testing? There are certainly programming languages (or basic programs) more designed to the task, but Perl is all I know (apart from awk and a little C) and surely anything can be done with Perl???
I have never put Perl to this use, so it is new territory for me. As an aside: Anyone know of any Perl scripts or modules people have written to determine regression equations? Seems highly complex, so I'll stick with STATA but I'd like to know if anyone else has done it.
Re: Using Perl for writing Trading Systems
by Akhasha (Scribe) on Dec 23, 2004 at 03:08 UTC
|
I haven't used Perl for this but have thought at length about the same problem domain. I'd be looking into Perl Data Language for dealing with numerically intensive tasks... (though it seems to be down at the moment)
When it comes to regression, Statistics::Regression might be what you're after. | [reply] |
Re: Using Perl for writing Trading Systems
by xdg (Monsignor) on Dec 23, 2004 at 05:01 UTC
|
Yes, sort of. I've used it for calculating a resampled efficient investment frontier. The great strength of perl for this task, I think, is the ability to munge input data quickly and easily and to quickly recode your program to test variations. It may not be the fastest simulation, but the speed of development/coding makes up for the speed of running, at least for the purposes I have for it. That said, PDL is certainly the way to go if you're dealing with any large data sets. On the statistics front, I wound up rolling my own so I knew exactly what was going on, so I'm not sure of a good recommendation there. (This from my early perl days -- now I'd probably look for a good module, or else would write my code in a way I could then release. It's on my "one of those days" list to revamp and release it.)
I'm in the process of coding some other simulation stuff right now -- keep your eyes peeled on CPAN in the next month and you'll probably see it. It may or may not be useful to you, but I plan to include support for bootstrap resampling, etc., which is nice for backtesting investment returns.
-xdg
Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.
| [reply] |
Re: Using Perl for writing Trading Systems
by aquarium (Curate) on Dec 23, 2004 at 04:24 UTC
|
| [reply] |
|
Thanks for the reply.
Firstly, I am primarily concerned with the currency, as opposed to the equity, markets but I must say I disagree with your claim that "if you're serious about making money, just follow company/government decisions and the resulting market impact". Alas, if it was that easy, there would be no problem. We would all be rich.
Guys who make fundamental analysis profitable have a mass network of contacts within the handful of companies which they trade. Company reps visit with fund managers to attempt to persuade them, and thus a few other hundred sheep, to buy their stock. They have information that the stay-at-home trader doesn't have. I question the foundation of fundamental annalysis for anyone, but for guys without a wealth of contacts it is impossible. By the time the news comes out the moves have been made.
Though most monks don't have networks of contacts, we do have data. The internet has made data freely available. This is why statistics can be the only way for the small investor to trade.
People who believe every bit of market noise is reducible to a news snippet are, as Nassim Taleb would say, "fooled by randomness" - props to tphyahoo for giving this book a mention.
| [reply] |
Re: Using Perl for writing Trading Systems
by Tomte (Priest) on Dec 23, 2004 at 10:11 UTC
|
I second the recommendation of PDL for meddling with numbers; on the statistics front I suggest R, I never used it with perl (I used it with python), but there are also perl-bindings. We were more than content, as it was easily capable of dealing with a very large data-set (30MB), SPSS couldn't even dream to work on (we had an SPSS license and tried it first, but it simply couldn't handle the amount of data per sample, let alone all samples...), STATS, which we considered switching to and had an evaluation license for, was of no use either; though I liked it a lot compared to SPSS...
regards,
tomte
An intellectual is someone whose mind watches itself. -- Albert Camus
| [reply] |
I've seen job adverts for this.
by tphyahoo (Vicar) on Dec 23, 2004 at 12:19 UTC
|
I'm fairly certian I've seen job adverts for perl programmers to maintain software at proprietary trading corps. So the answer is probably, yes. Whether any of this code is in the public domain is another issue.
Also, anybody who wants to build programs to autotrade should read Nassim Taleb's "Surprised By Randomness."
And get a real job. :)
thomas. | [reply] |
|
| [reply] |
Re: Using Perl for writing Trading Systems
by dba (Monk) on Dec 23, 2004 at 16:17 UTC
|
I searched for modules in CPAN, but couldn't find what I was looking for. I use WWW::Mechanize and LWP modules to get free data (Yahoo finance) and subscription data for specific equities based on pre-determined criteria and load them into a database( using DBI) and run various SQLs to test different strategies. | [reply] |
|
Thanks for the reply.
Have you found these strategies profitable? I don't want to know the actual strategy, that is your gospel and for you only, but I just wonder: have you found statistically significant patterns?
Once I complete my MA (bout 1 1/2 years) I am going to work for a proprietary trading firm, so this is more than just an intellectual interest....
| [reply] |
|
There are plenty of mathematics modules on CPAN...
found this bundle of modules...
Can't really comment on them right now... once I have my exams and essays out the way - roll along, January 19th!- I will spend a week sifting through the stuff (no doubt, I will inform the monastery of anything of interest)
Anyway, thanks for your help dudes. This is a subject I will return to soon.
peace out
| [reply] |
|
For the limited period (past 2 months), I was able to validate a pattern for a specific group of stocks. However, Iam not ready to place my hard earned cash yet :) I will apply the pattern for the next month or so on paper and then slowly start using it.
| [reply] |
|
|
|