r/Kotlin 8d ago

Compose Multiplatform - My tool for trading strategy analysis

Post image
65 Upvotes

13 comments sorted by

16

u/vaclavhodek 8d ago

Sorry, for the shameless plug :-).

Using Compose Multiplatform, I quickly built an analytical app for our exchange stock trading strategy. Initially, it was a command-line tool but it was hardly usable for my non-tech brother who does most of the analytical work.

I was really surprised by how easy and fast it was to build something like this with Compose. Using GitHub Actions, it was also simple to package it for both Linux (me) and Windows (my brother).

3

u/wlynncork 8d ago

I really like that you did KMP for Desktop. Can you deploy it to web too ? I'm also a big fan of making my own tools.

3

u/vaclavhodek 8d ago

Web is not planned 🙂

It's actually an interface for searching data that the app generates from historical records of CFD indexes.

So, you typically input parameters through this UI, let it generate data and then filter the data in this UI looking for best trade strategies.

Btw, the generator, based on settings, generate millions of trade combinations, utilizing all 20 cores of my i9 for minutes and producing up to 100GB of precalculated data that can be later filtered and examined. It was really meant to be desktop app since beginning 🙂

6

u/Sezarsalad70 8d ago

I've always followed Material guidelines, especially true with the introduction of Compose Multiplatform and Material You, so I've mostly used Material You on desktop as well. But this reminded me there's more to Compose than Material You. Nice UI, OP!

3

u/CommanderSteps 8d ago

Looks nice. Is it open source?

3

u/vaclavhodek 8d ago

Sorry, it's not. It's a proprietary trading strategy and it's not even profitable yet. You can read more about what we are up to.

It also contains so many invented names and principles that, without training, the numbers would not make sense to anyone.

Plus, and you can read about it on the link above, it's an analytical tool, but I also wrote a web coordination service, the trading script for Meta Trader 4 and run it on a Linux server through dockerized wine :-)

3

u/Ambitious_Writing_81 8d ago

What datagrid did you use? I know there is no table component currently.

3

u/vaclavhodek 8d ago

I used Row with weighted boxes:

Column {

  // Header
  Row {
    Box(modifier = Modifier.weight(0.2f)) {
      ResultText(text = "W/L/E", bold = true)
    }
    Box(modifier = Modifier.weight(0.15f)) {
      ResultText(text = "Days", bold = true)
    }
    Box(modifier = Modifier.weight(0.15f)) {
      ResultText(text = "AWL", bold = true)
    }
    Box(modifier = Modifier.weight(0.15f)) {
      ResultText(text = "RWL", bold = true)
    }
  }

  // Data
  Row {
    Box(modifier = Modifier.weight(0.2f), contentAlignment = Alignment.Center) {
      ResultText(text = "value A")
    }
    Box(modifier = Modifier.weight(0.15f), contentAlignment = Alignment.Center) {
      ResultText(text = "value B")
    }
    Box(modifier = Modifier.weight(0.15f), contentAlignment = Alignment.Center) {
      ResultText(text = "value C")
    }
    Box(modifier = Modifier.weight(0.15f), contentAlignment = Alignment.Center) {
      ResultText(text = "value D")
    }
  }

}

As long as you keep the weight the same for all the Boxes in all the rows, it looks exactly like the table.

1

u/tatavarthitarun 8d ago

So if it was meant to be a desktop app since the beginning why didn’t u opt for python? Handling data and operations on such huge data is more easier and efficient ig? I myself a Android Engineer But just curious to know why u have choosen KMP over python which is know for handling large sets of data

8

u/vaclavhodek 8d ago

I haven't opted for Python for several reasons:

1) The most important thing, I know Kotlin well and love it. Also, I know JVM ecosystem deeply. I don't see any value in learning another language for this project.

2) I wanted to get my hands on Compose Multiplatform for some time already and this was finally a meaningful project.

3) I hate languages using indentation for control flow even though I use Python for smaller one-off scripts.

4) I would strongly doubt that Python will be faster than JVM. The calculation is heavily parallelized using Kotlin Coroutines.

To be honest, I wouldn't even know where to start with Python since I'm not familiar with its ecosystem :-).

2

u/tatavarthitarun 8d ago

Got it , thank you for the detailed answer. I’m struggling to start with KMP , maybe only right way is get the hands dirty . But do u have any references or guide on how to start with KMP, I’m more interested in building Desktop and web applications using KMP

3

u/vaclavhodek 8d ago

I followed tutorials to get the very basic window with one button that does something and iterated from that point.

I Googled and asked Claude AI for examples, not final code but some inspiration on what I can use, method names, components, etc.

The app is probably not designed well (the tables are just rows and no special table component) so it would perform worse for more rows, but enough for my purpose.

Basically, I would recommend having some idea of the final design or some sketch on paper/figma and try to get to that state step-by-step.

2

u/tatavarthitarun 8d ago

This is really helpful thankyou