stockparfait / experiments

Statistical experiments with financial data
Apache License 2.0
0 stars 0 forks source link

Implement simple price graphs #1

Closed sergey-a-berezin closed 2 years ago

sergey-a-berezin commented 2 years ago

This sets up the core of the experiments app and implements the first very simple "experiment", which simply displays the price series of a number of specified tickers.

The experiments app should have a common config for all of the experiments, so the experiments could be run together, and their results can be plotted on the same page for easy cross-reference.

sergey-a-berezin commented 2 years ago

The first "experiment" will be a simple buy-and-hold "strategy", we'll call it hold.

It takes a list of tickers with the number of shares for each (possibly fractional, default: 1.0 share), and optionally displays each position's value in a given graph.

As an option, instead of the number of shares, each position can be specified as the initial cash amount; the (possibly fractional) shares are then computed and displayed in the legend.

It can optionally add up the position costs and display them in a separately provided graph (can be the same or different from the individual positions' graph).

The prices are displayed in the specified time interval [start, end]. If a bound is unspecified, all the available prices from its side are displayed.

sergey-a-berezin commented 2 years ago

For that, we need to use db.Date as part of the config. Let's make it a message.Message.

And while we're at it, let's also allow non-pointer Message implementations to be populated in the config. Technically, the Init() method on a type T still must be on the pointer type *T, but the message.Init() should check if *T implements message.Message even when it encounters a value of T. The zero / default values must then be handled correctly by setting the zero value of T itself.

sergey-a-berezin commented 2 years ago

The following config:

{
    "groups": [
    {"name": "hold", "timeseries": true, "graphs": [
        {"name": "positions", "title": "Individual positions"},
        {"name": "total", "title": "Portfolio total"}
    ]}
    ],
    "experiments": [
    {
        "hold": {
        "data": {
            "start": "2015-01-01",
            "end": "2017-12-31"
        },
        "positions graph": "positions",
        "total graph": "total",
        "positions": [
            {"ticker": "AAPL", "start value": 1000.0},
            {"ticker": "GOOG", "start value": 1000.0}
        ]
        }
    }
    ]
}

creates the following chart:

Screen Shot 2022-07-13 at 8 14 56 PM