M
M
Mikhail Emelyanov2020-07-11 18:17:26
OOP
Mikhail Emelyanov, 2020-07-11 18:17:26

What is the best design pattern to use when calculating financial indicators?

I am writing a robot for playing on the stock exchange (just a pet project, I am learning C #), I want to properly process the work with technical analysis indicators (moving average, stochastic oscillator, etc.).

Simplifying, we can say that each indicator takes as input a certain portion of mandatory information (say, a decimal array) that displays the prices of the instrument under consideration for a certain period of time. And each indicator necessarily produces an output array with indicator values ​​for the same period of time. But - indicators have different inputs ; someone needs an additional int parameter, someone needs three additional double parameters, etc.

What is the best pattern to use for such a differentiation so that the code is readable and structured?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew Nodermann, 2020-07-13
@Lucian

For your task, the best description of indicators would be a declarative approach like SQL , not an imperative one like C#, named arguments and config, i.e. when you describe the indicator in the config, but do not describe the details of its implementation.
This approach will allow you to create an unlimited number of indicators, without describing the business logic for each.
Here is an example of a declarative approach for the nginx server, which describes that the server should listen on port 80 and serve requests coming to the / api address and which path to look for the page, but does not describe how the server should work.

server {
        listen 80;

        root /var/www/example.com/html;
        index index.html index.htm index.nginx-debian.html;

        server_name example.com www.example.com;

        location /api {
                try_files $uri $uri/ =404;
        }
}

Here is another example of a declarative approach:
space({
    name = 'bitcoin',
    fields = {
        { name = 'tx_id', type = 'string' },
        { name = 'block_hash', type = 'string' },
        { name = 'prev_block', type = 'string' },
        { name = 'address', type = 'string' },
        { name = 'value', type = 'string' },
        { name = 'type', type = 'string' }, 
        { name = 'block', type = 'unsigned' },
        { name = 'created', type = 'unsigned' },
        { name = 'expires', type = 'unsigned' },
    },
    indexes = {
        { name = 'primary', type = 'tree', unique = true, parts = { 'tx_id' } },
        { name = 'address', type = 'tree', unique = false, parts = { 'address' } },
        { name = 'block', type = 'tree', unique = false, parts = { 'block' } },
        { name = 'expires', type = 'tree', unique = true, parts = { 'expires' } },
    }
})

It describes the name of the table "bitcoin", the fields of the table and indexes for quick search by value, but does not describe what needs to be done to create such a table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question