0

I am currently in the analysis phase of developing some sort of Locale-based Stock Screener ( please see Google's' for similar work) and I would appreciate advice from the SO Experts. Firstly the Stock Screener would obviously need to store the formulas required to perform Calculations. My initial conclusion would that the formulae would need to be stored in the Database Layer. What are your ideas on this? Could I improve speed( very important) by storing formulas in a flat file(XML/TXT)?

Secondly, I would also like to ask advice on the internal execution of formulae by the Application. Currently I am leaning towards executing formulae on parameters AT RUN TIME as against running the formulae on parameters whenever these parameters are provided to the system and storing the execution results in the DB for simple retrieval later( My Local Stock Exchange currently does NOT support Real Time Stock Price updates). While I am quite certain that the initial plan ( executing at run time) is better initially , the application could potentially handle a wide variety of formulae as well as work on a wide variety of input parameters. What are your thoughts on this?

I have also gone through SO to find information on how to store formulae in a DB but wanted to enquire the possible ways one could resolve recursive formulae i.e. formaulae which require the results of other formulae to perform calculations? I wouldn't mind pointers to other questions or fora at all.

[EDIT] [This page]2 provides a lot of infromation as to what I am trying to achieve but what is different is the fact that I need to design some formulae with SPECIAL tokens such as SP which would represent Stock Price for the current day and SP(-1) would represent price for the previous day. These special token would require the Application to perform some sort of DB access to retrieve the values which they are replaced with.

An example formula would be:

(SP/SP(-1)) / 100

which calculates Price Change for Securities and my idea is to replace the SP tokens with the values for the securities when Requested by the user and THEN perform the calculation and send the result to the user.

Thanks a lot for all your assistance.

Community
  • 1
  • 1
Kris Ogirri
  • 161
  • 1
  • 14
  • Why would you want to store the formulas in the database in the first place? Is it a requirement to be able to alter the formulas during runtime? Or would a set of existing formulas suffice that can be chosen at runtime? – Axel Jun 04 '10 at 20:35
  • The idea is that I would be able replace the variable_holders ( for lack of a better word) in the formula with the actual input parameters used. As an example, Stock Price Change = (Current Stock Price/ Stock Price of Previous Day) * 100. I would want to store something like ({SP}/{SP(-1)) / 100 as a formula in the DB with a name, Do you think this is overkill? All opinions are welcome! Seriously , ALL. – Kris Ogirri Jun 04 '10 at 20:58
  • Do you need to let the users modify the formulae (meaning: do you need to use some kind of "natural" (sorry) language)? – Dr. belisarius Jun 11 '10 at 22:17
  • @belisarius: In the initial phases , users will not be able to modify the formula. This feature may be added to the application if requested. I have modified the question to provide more insight into what I am trying to do. – Kris Ogirri Jun 15 '10 at 18:24
  • @Kris Ogirri I've used things like this http://java.sun.com/developer/technicalArticles/J2SE/JavaRule.html with similar purposes. Although they are targeted to managing Rules, they can manage calculation too. Ilog http://www-01.ibm.com/software/websphere/ilog_migration.html is a commercial alternative – Dr. belisarius Jun 15 '10 at 18:45
  • I might be missing something here - but why do you want to store the formulae in a data store as opposed to just coding them as functions? Could you not just write a function double StockPriceChange(Stock s) { return (s.CurrentPrice / s.PreviousDayPrice) * 100; } The requirement to store the formulae as editable entities in a data store adds a LOT of complexity to this application, but I'm not convinced that this is what you're actually intending to ask - am I wrong? – Chris McAtackney Jun 16 '10 at 09:25
  • @C.McAtackney: Because the possibility of the formulae changing over time are quite real and in the event that the formula changes I would not want to have to modify the source code. I understand this adds a fair amount of complexity to the solution but I feel it is necessary. Thanks. – Kris Ogirri Jun 16 '10 at 09:36

1 Answers1

0

Kris, I don't mean to presume that I have a better understanding of your requirements than you, but by coincidence I read this article this afternoon after I posted my earlier comment;

http://thedailywtf.com/Articles/Soft_Coding.aspx

Are you absolutely sure that the "convenience" of updating formulae without recompiling code is worth the maintenance head ache that such a solution may possibly become down the line?

I would strongly recommend that you hard code your logic unless you want someone without access to the source to be updating formulae on a fairly regular basis.

And I can't see this happening too often anyway, given that the particular domain here, stock prices, has a well established set of formulae for calculating the various relevant metrics.

I think your effort will be much better spent in making a solid and easily extensible "stock price" framework, or even searching for some openly available one with a proven track record.

Anyway, your project sounds very interesting, I hope it works out well whatever approach you decide to take. Good luck!

Chris McAtackney
  • 5,192
  • 8
  • 45
  • 69
  • I wanted the potential for enabling users to define their own Formulae which would be usable by the Application but thanks a lot for the (very sound) advice and the provided site is quite interesting. What do you mean by a 'Stock Price ' framework BTW? – Kris Ogirri Jun 16 '10 at 18:29