I want to use Kotlin for technical analysis framework, because I have several additional libraries in the java code. I will plan to extend engine for calculation of indicators and strategies.
For example there is present usage of simple moving averages in the condition inside of some strategy:
if (EMA(C, 24) > MA(L, 100)) { ... }
So, there are present two indicators (functions) for exponential moving average EMA, and standard moving average MA. Which have to be calculated from Close prices, and Low prices (it is some standard series of double values), the lengths are 24 and 100.
This condition which directly included indicators are very good for final user of framework and I want to kept this style!
Now the problem: For example, this condition with indicators is part of some strategy code. But this part of code is calculated per price bar. It means many times for each price value. The indicators have own history and can use some additional context, for additional configuration or data. Ideal state will be, EMA(C, 24) function expression has to be bind with specific object/instance of indicator which is not singleton but belongs to this expression, because have some history, added context etc. But I do not want to create objects externally! The structure of condition example has to be kept. Or use some function in function with possibility to inject context or additional data, and kept some history. Main problem is that this line is perform for each bar, it is not just one calling, it is incremental calling of this condition.
Kotlin has many possibilities for functions, lambdas, objects. I'm trying to find some best solution for this type of usecase, which will be FAST/GOOD performance in one hand, and with good writing of conditions in other hand.
Thanks for help and ideas.
Aucun commentaire:
Enregistrer un commentaire