Saturday 24 March 2012

Adding to your toolbox

Once your start playing with your data, your will quickly realise that there are many useful technical and financial functions you need to create your own trading strategy. Development of a successful strategy will see you needing to developing two related systems - one for back-testing and one for actual trading, and for both of these you will need a set of tools to help you calculate all the indicators/formulae you will want to use.

You could write the formulas from scratch, although personally, I have found many to be tediously complex and indecipherable, especially when trying to re-interpret them from other applications such as Metastock. A good dll to add to your library is TA-Lib, this comes with a comprehensive list of functions that will set you on your way. Best of all it is opensource which is fairly unusual for anything finance-related.

Just a few tips on using these functions in your C# programs - I assume you are retrieving your data from an SQL database - first, you need to retrieve your data as an  strongly-typed list object:

 IOrderedQueryable<Price> prices = (from p in _db.Prices
                                                   where p.Date <= date
                                                   where p.Date >= _earliestDate
                                                   where p.Epic == epic
                                                   orderby p.Date ascending
                                                   select p);

Next, as most functions in TA-Lib want double arrays (double[]) for input prices, you need to cast your data as follows:

double[] priceCloseSubset = (from p in prices select Convert.ToDouble(p.Close)).ToArray();

You should now be able to utilise these functions in your own designs.

No comments:

Post a Comment