Ideas for New Tick Auto Trading and Back Testing Platform

trading strategies and money management discussion, code, results

Moderator: moderators

greaterreturn
rank: 50+ posts
rank: 50+ posts
Posts: 64
Joined: Mon Feb 11, 2008 2:57 am
Reputation: 0
Gender: None specified

Ideas for New Tick Auto Trading and Back Testing Platform

Postby greaterreturn » Tue May 27, 2008 7:24 pm

Folks,

I am making progress on building a home grown trading platform that I plan to share.

In this thread, would you like to discuss your ideal qualities of a automated trading platform? Note, this means ZERO discretionary trading features.

After starting this out only for personal use, I realized it may benefit others and I may benefit from the interchange of ideas.

So far, these are the requirements/features of this platform under construction. Can you think of any other important ones?

1.1 It must back test in an environment that exactly replicates a live trading environment as much as possible. To do that, it must do the following.
1.1.1 The platform must base all back testing and live trading on tick data directly.
1.1.2 It must build period bars (minute, hour, etc) progressively with each tick just like a live system.
2.1 It must operate with a large history of tick data very efficiently.
3.1 The system must have a base framework with core functionality and offer a separate very simple method of adding custom indicators, rules, and strategies.
4.1 It must handle back testing and live trading of multiple strategies in a portfolio across multiple equities/brokers.
4.1.1 So it must be able to simultaneously run different strategies.
5.1 And it must allow simple separation between the following parts of trading:
5.1.1 Separate trading rules a.k.a strategy.
5.1.2 Separate indicators.
5.1.3 Separate exit handling logic.
5.1.4 Separate money management logic.
5.1.5 Separate tick filtering logic
5.1.6 Separate strategy combination/mixing logic.
5.2.1 It must be rather simple to mix and match these components (like legos). So it must be possible to switch and test different exit handling logic or money management strategy against with the same underlying instrument.

My progress so far is that I have built the "Engine and core framework" at a basic level.

This means that it has basic classes called RulesSupport (for trading rules), ExitSupport, MoneyManagementSupport, PortfolioSupport, StrategySupport , TickEngine, BarSeries, TickSeries, DataSeries, and RandomTestStrategy.

They're all extendable to make custom trading logic, exit logic, or rules.

Just like Lego building block, these classes all have the same "interface" so you can connect different ones together in any order.

That's because they all share the IStrategyAware interface which means that you can mix and match the pieces.

Think of each piece of the strategy like a "filter" that links together with others in a chain. It allows you to interconnect the pieces in any order you like.

The portfolio pieces can connect multiple other pieces simulteneously and


The way this works is that each component piece simply says whether it is long, short, or flat and the position size.


Portfolio <- MoneyManager <- ExitRules <- TradeRules
<- TradeRules
<- MoneyManager <- TradeRules

PERFORMANCE:

This was all built with the fastest performance in mind. To that end, all prices are stored as integers without a decimal point.

Right now, on a single CPU, the system take 4 seconds to load 6 years of tick data, run a simple strategy, and save the trades to a file.

So far it has no charting interface and is completely written in C#.

I just implementing fully automated regression testing to every component using NUnit.

Again, I'm building this for myself. But if there's interest, I might share. Especially if you can contribute ideas, code, or money to the project.

I work on this evenings and weekends since I work full time as a Software Architect.

Personally I plan to use the platform to run an automated system with multiple combined strategies per instrument on many instruments simultaneously and fully automated.

Each individual strategy can have it's only exit strategy or money management with position sizing, trade history and other rules.

Then any combination of strategies can have a special portfolio with rules on how to combine those strategies together whether they're simply overlaid or conditionally applies.

Again, there may also be portfolio lever money management either per instrument or globally.

My plan is to make it all work together and test simultaneously with an optimizer for trying NOT ONLY variables but even testing different combinations.

Finally my plan is to make it possible to zoom into the strategy and examine any individual components performance with charts of its history and trading decisions individually or look at all of them as a whole, etc.

This may sound ambitious. And it is.

I welcome all feedback or ideas.

Sincerely,
Wayne

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

androfx
rank: <50 posts
rank: <50 posts
Posts: 20
Joined: Thu Oct 26, 2006 3:27 pm
Reputation: 0
Location: Europe, Czech Republic... sometimes
Gender: None specified

Postby androfx » Wed May 28, 2008 10:09 am

I am building similar thing myself but I have chosen more dynamic way - when I need some functionality I use something I or somebody else did in the past (Google is my friend). Many times I offload the work to other programs. When I am loosing sight what is going on I optimize a bit or redo parts again. It is helping to be more focused on trading and the target than on how different modules and interfaces are working together.
My needs for data and calculation infrastructure are changing so fast and it is easier to roll a new piece of code then to think of how to remake/optimize/modify current one. My testing programs tends to be up to 1000/2000 lines... anyway.
When there is something I would like to run quicker then I parallelize first (I have usually "jobs" to run so parallelization/clustering is easy). If it is not helping I use optimized algorithms/datastructures and/or resampling/lowering data amount.

I want to minimize the time I spend with computer and trading in favor to other more enjoyable things. So when/if I get working strategy then will optimize all this cooperating stuff, not before.

I understand your inner reasons why you have chosen to program everything from scratch but I feel that the task is huge and you can end up as a seller of a trading platform or evenings and weekends programing guy forever.

My choice of tools: Python, Linux (shell is great), MySQL, MatPlotLib, NumPy/SciPy, Google, ta-lib, Eclipse.

dfstone32
rank: <50 posts
rank: <50 posts
Posts: 2
Joined: Wed Dec 05, 2007 8:07 pm
Reputation: 0
Gender: None specified

Postby dfstone32 » Sun Jun 01, 2008 5:28 pm

Greaterreturn,

I've been working on something similar for a few months in my spare time, my biggest problem so far is converting ticks to bars, the query (stored procedure) I'm using takes a few seconds per bar, which is incredibly slow.

Do you have an optimized query for creating bars from ticks?

If you would like me to send you the code I'm working with I will be more than happy too. Its basically spaghetti but I never planned to do anything but test my own trading strategies with it.

greaterreturn
rank: 50+ posts
rank: 50+ posts
Posts: 64
Joined: Mon Feb 11, 2008 2:57 am
Reputation: 0
Gender: None specified

Postby greaterreturn » Sun Jun 01, 2008 10:04 pm

I only store and retrieve ticks from the database-- not bars.

If you study databases, you will learn that they are efficient at reading and writing organized data but very poor at performance of any type of calculations. Also, it's very difficult to use automated unit testing on stored procedures. Not worth it.

So my tick engine loads ticks from the DB and builds bars on the fly while processing just like in a live environment. That way, the bars have the CURRENT high low and close at any given moment.

It always builds 1 minute, 1 hour, 1 day, 1 session, 1 week, 1 month, and 1 year bars by default. And it's easy (if you know C#) to add other bars with multiples of those.

By default, the minute bars get updated every tick and the others get updated every minute. But, again, you can modify that if you want to update one of them more often.

Right now, it takes the system about 3 minutes to retrieve 6 million ticks (for 8 years of data) for a single currency and serialize that to a file.

From that point it takes only 3 seconds to load that data into memory each time you want to re-run a test.

I found a way to fit a single tick in only 6 bytes so it takes only 35meg for 8 years of tick data.

So far it only takes about 3 seconds on this CPU to run a simple strategy.

I'm going to look into compiler optimizers for .NET and consider a faster CPU. I want one optimization iteration to take under 1 second per currency.

Why? I plan to run all my tests against at least 10 currency pairs simultaneously at all times.

So that could take 10 seconds per iteration of an optimization.

I hope this helps!

Wayne

dfstone32
rank: <50 posts
rank: <50 posts
Posts: 2
Joined: Wed Dec 05, 2007 8:07 pm
Reputation: 0
Gender: None specified

Postby dfstone32 » Sun Jun 01, 2008 11:37 pm

Wayne,

Any chance you could send me some c# files for your tick engine? I thought using an sp, sending a date, period of bar was the way to go. I've also heard that mysql was much faster than sql server and was looking into switching my DB which I'd rather not do. Basically I'm looking to serve up a bar of whatever timeframe each time I click the "next" button. Not so much to automate as practice different strategies manually, which I can do now but I'm looking to make things a little more robust and faster.

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

greaterreturn
rank: 50+ posts
rank: 50+ posts
Posts: 64
Joined: Mon Feb 11, 2008 2:57 am
Reputation: 0
Gender: None specified

Postby greaterreturn » Mon Jun 02, 2008 2:09 am

Df,

Please send a copy of your resume via PM if you're interested.

At this point I don't want to share the code yet unless it makes sense for collaboration. I want to limit time spend supporting it and focus on building/testing it.

If it makes sense, I can setup a subversion repository and give you a password.

That way, if you make changes you can check them in and I can do the same. That way, we can build up the code base.

Right at the moment, I'm creating support framework for calculating model statistics.

NOTE: Neither of us have to share our custom strategies, but we can share improvements to the engine, architecture, etc.

Personally, I'm strongest at "back end" work like infrastructure, DB's, and logic. So I'm capable at User Interface by weak.

In other words, all the GUI has right now is a little dialog box with a radio button to pick whether you want to pull from the database or run from the cache. It allows you to enter an SQL "where" clause to select the date range you want to build into the cache. Finally, it has a progress bar too.

Oh, I have separate tool that I used to scrape all the tick data off a website that has free tick data.

The rest of strategy results, etc is written to files that I examine in Excel.

Sincerely,
Wayne

User avatar
BlackMage
rank: <50 posts
rank: <50 posts
Posts: 7
Joined: Sat Feb 23, 2008 1:22 pm
Reputation: 0
Location: Copenhagen
Gender: Male

Postby BlackMage » Fri Jun 06, 2008 1:45 pm

greaterreturn wrote:In other words, all the GUI has right now is a little dialog box with a radio button to pick whether you want to pull from the database or run from the cache. It allows you to enter an SQL "where" clause to select the date range you want to build into the cache. Finally, it has a progress bar too.


You might want to look into Weifenluos Dock Panel Suite:

http://sourceforge.net/projects/dockpanelsuite/

It is a Visual Studio like Multiple Document Interface and it comes in very handy when your user interface needs starts to grow (which they probably will if you succeed).
Financial Hacker

greaterreturn
rank: 50+ posts
rank: 50+ posts
Posts: 64
Joined: Mon Feb 11, 2008 2:57 am
Reputation: 0
Gender: None specified

Postby greaterreturn » Fri Jul 11, 2008 7:10 pm

BlackMage,

Wow, I just saw your post. This is most helpful. I will definately try it out. I'm at the point now where I'm using ZedGraph for charting needs but the oversimplistic GUI is starting to bother me.

This dock panel appears to add a good framework for a lot of the "niceties" of modern interfaces.

Sincerely,
Wayne


BlackMage wrote:You might want to look into Weifenluos Dock Panel Suite:

http://sourceforge.net/projects/dockpanelsuite/

It is a Visual Studio like Multiple Document Interface and it comes in very handy when your user interface needs starts to grow (which they probably will if you succeed).

greaterreturn
rank: 50+ posts
rank: 50+ posts
Posts: 64
Joined: Mon Feb 11, 2008 2:57 am
Reputation: 0
Gender: None specified

Postby greaterreturn » Fri Jul 11, 2008 7:19 pm

Dfstone,

At the moment I still use MySQL technically but not really. What I mean is that all the tick data is in MySQL but I have a system to pull out what data I need and cache it to a disk file. Then I just just load it from that file each time I run an optimization.

I am a relational database professional for 18 years. So I applied every trick in the book to speed up the query but it still takes 4 or 5 minutes to get 11 millions ticks for one currency pair out of MySQL.

However, it takes less than 3 seconds to load all that data from my custom format data file.

Note, it only takes 3 seconds to load EVERY tick into memory. Plus, it takes only milliseconds for a loop to read through that data and return the ticks that fit a certain criteria.

In reality, no database can ever compete with that kind of speed. In short, relational databases were never built for that kind of data or performance.

For now, I will stick with my proprietary binary format due to the raw speed. But I might look into some "in memory" databases like Berkely DB in the future. I still doubt they can compete with the native speed due to additional API call overhead.

I hope this helps.

Sincerely,
Wayne

dfstone32 wrote:Wayne,

Any chance you could send me some c# files for your tick engine? I thought using an sp, sending a date, period of bar was the way to go. I've also heard that mysql was much faster than sql server and was looking into switching my DB which I'd rather not do. Basically I'm looking to serve up a bar of whatever timeframe each time I click the "next" button. Not so much to automate as practice different strategies manually, which I can do now but I'm looking to make things a little more robust and faster.

Tresor
rank: 50+ posts
rank: 50+ posts
Posts: 93
Joined: Sat Mar 15, 2008 2:30 pm
Reputation: 0
Location: Davy Jones' Locker
Gender: Male

Re: Ideas for New Tick Auto Trading and Back Testing Platfor

Postby Tresor » Sat Jul 12, 2008 8:23 pm

greaterreturn wrote:Folks,

I am making progress on building a home grown trading platform that I plan to share.

In this thread, would you like to discuss your ideal qualities of a automated trading platform? Note, this means ZERO discretionary trading features.

After starting this out only for personal use, I realized it may benefit others and I may benefit from the interchange of ideas.


Hi greaterreturn,

There is one feature that I am missing in all platforms that were designed primarily for US market that I looked at. Namely, I would like a platform that would (i) intake Open Interest data in ticks, (ii) plot Open Interest in ticks, (iii) allow to apply studies of OI in ticks.

Regards

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.


Return to “strategy trading & money management”