On Wed, Jan 26, 2011 at 10:47 AM, Michael Orlitzky <mich...@orlitzky.com> wrote: > On 01/26/2011 12:56 PM, Mark Knecht wrote: >> Michael, >> Thanks for the inputs. It gives me more to think about. >> >> In this case the input language is interpreted, not compiled. The >> trading platform interprets the program and internally turns it into >> buy & sell operations. (Not the piece of code I supplied - that was >> just a small function.) Unfortunately, as the language is proprietary >> to the trading platform there isn't a way to go to any common >> low-level language. >> >> The 'battery of tests' would be, I think, the trading program being >> executed on a certain market, producing a certainly list of buy & sell >> operations and a specific gain or loss. It would be quite easy to >> compare the outcome because it's nothing more than a list of trades. >> If the translated code generates the same list then it works. If not, >> I dig into why. This part of the task seems relatively straight >> forward to me. >> >> I was mainly hoping to find a tool that might generate _reasonable_ >> C code, even if it's not perfect. If the C code compiles and runs then >> I could determine what works, what doesn't, and start fixing things. >> I'm not a C programmer and haven't touched that language in at least >> 15 years so anything that moves me forward would be helpful. >> >> Again, I do appreciate your inputs. If this extra info gives you >> any new ideas please let me know. > > If you don't even have a common low-level language, what you're > essentially doing is creating a compiler for EasyLanguage. Take a small > example, adding two integers in E.L. I won't pretend to know the syntax, > but let's just assume that you have two integers (or numbers or > whatever) 'a' and 'b' declared. > > How do you translate "a+b" to C code? You can declare two ints 'a' and > 'b' in C, of course. But these are 32- or 64-bit integers. So if 'a' and > 'b' are large, "a+b" will overflow. Do EasyLanguage integers work that > way? Probably not... > > How about "a/b"? Does EasyLanguage do integer division, or does it treat > them like floats? If it does treat them like floats, do the rounding and > precision agree with C floats? Probably not, so floats are out too. > > If you try to fix all of these problems, what you'll end up with is > something like a struct EasyLanguageInteger {...} with associated > functions add_easylanguage_integers, divide_easylanguage_integers, etc. > Then, you can translate "a+b" into add_easylanguage_integers(a, b) where > 'a' and 'b' are now structs instead of just ints or floats. > > Then, you'll have to write a parser that understands the rules of > precedence, looping constructs, functions, and everything else so that > they can be converted into the appropriate structs and function calls. > At the end, if it works, you'll have an EasyLanguage compiler. > > Without a spec (the language is proprietary?), you'd have to guess at > most of that stuff anyway, so the chances you'd get it all right are > about zero. > > Your best bet[1] is to create a ton of test data, and feed it to the > E.L. program. Make sure the test data triggers any edge cases. Then you > can attempt to rewrite the code in C, and compare the output. You as a > human who understands what the code does can take a lot of shortcuts > that a translator couldn't. > > > [1] I'm assuming you want to do this for a relatively small number of > programs, and that writing a compiler would not actually be less > time-consuming. > >
OK - this is probably WAY too off topic for this list. If folks strongly want me to stop the thread I will but I appreciate the technical adeptness of folks on this list quite a lot and the eventual outcome would be the use of this thing on Gentoo, so I hope folks won't mind too much if we continue a little further. REALLY great points about the math issues. Thanks. As for testing it _may_ be a slight bit easier than having to get to that level. There is a library in portage called ta-lib which implements lots of standard technical analysis constructs. After it's installed I don't seem to have the C code for the actual functions anymore. What I have is a compiled library as well as some header files to look at. I suspect I can install the library again using portage bt not getting rid of the functions which I could then use as an example for my coding. I have not used this library myself, but I've read enough on the web to be reasonably sure it's results are very consistent with what TradeStation functions of the same type do. For a simple function call like a moving average EasyLanguage would write: Inputs: Price(Close), Length(10) ; variable: MA1(0) ; MA1 = Average(Price,Length); Here is what I see for a similar moving average function from ta-lib: /* * TA_MA - Moving average * * Input = double * Output = double * * Optional Parameters * ------------------- * optInTimePeriod:(From 1 to 100000) * Number of period * * optInMAType: * Type of Moving Average * * */ TA_RetCode TA_MA( int startIdx, int endIdx, const double inReal[], int optInTimePeriod, /* From 1 to 100000 */ TA_MAType optInMAType, int *outBegIdx, int *outNBElement, double outReal[] ); TA_RetCode TA_S_MA( int startIdx, int endIdx, const float inReal[], int optInTimePeriod, /* From 1 to 100000 */ TA_MAType optInMAType, int *outBegIdx, int *outNBElement, double outReal[] ); int TA_MA_Lookback( int optInTimePeriod, /* From 1 to 100000 */ TA_MAType optInMAType ); Maybe I could use the definitions of these functions as a basis for understanding what might be a reasonable set of guesses? From my point of view, a good start at translation would be to use whatever is available in ta-lib whenever possible and only have to deal with other stuff like If/Else, Switch, etc. Just thinking. Thanks, Mark