npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@acransac/index

v1.1.0

Published

Print reports on the performance of investments

Downloads

24

Readme

Introduction

index is a command line program that prints a report on the performance of a series of investments. The performance is measured by indices which are described with a chart, highlights and the full list of values. Currently, the indices are:

  • the relative market value of the investment compared with the first valuation. For example, starting with 100, a reading of 101.23 means that the assets appreciated by 1.23% relatively to the inception value. This index is not affected by cashing into or out of the investment.
  • the return on investment. This is the ratio of cash withdrawn to cash invested over time, considering a full sale of assets and cash out at the date of the index computation. The time value of cash flows is accounted for.

The input to the program is user-provided json data describing the investments, with a time series of market values and cash flows, and possibly the compound rates, with a series of time intervals and associated rate values. The user also chooses the time interval to report on. The output is meant to be easily printable and readable in a terminal (even the graphs) and is formatted as Markdown.

See for example here, the performance of an investment of USD1000.00 in Vanguard's exchange-traded fund VOO (that tracks the S&P500 index) over 2020 as output by index.

Installation

index is delivered as a npm package and is more convenient to use if installed globally:

    $ npm install --global @acransac/index

It can be uninstalled with:

    $ npm uninstall --global @acransac/index

Usage

Providing Input

The input to the program is json data describing the market values of the assets and cash flows in or out of an investment over time. Additionally, to account for the time value of cash flows, the input can also include json data describing the compound rates to apply over time, or a single rate value that is used for all cash flows from all funds.

Funds

One investment is called a fund and there can be several of them in the input. Apart from the list of valuations and cash flows, a fund has a name and a base currency in which market values and cash flows are expressed.

The schema is as follows:

    <input>        ::= <fund>+
    <fund>         ::= <fundName> <currency> <assetsValue>+
    <fundName>     ::= string
    <currency>     ::= string
    <assetsValue>  ::= <valueDate> <marketValue> <addedCash>
    <valueDate>    ::= string
    <marketValue>  ::= number
    <addedCash>    ::= number

where the value date is formatted as YYYY-MM-DD and added cash is positive for deposits and negative for withdrawals to and from the fund respectively.

See an example of json input:

[
  {
    "fundName": "Investments In The USA",
    "currency": "USD",
    "assetsValues":
      [
        {"valueDate": "2020-01-01", "marketValue": 1000.00, "addedCash": 1000.00},
        {"valueDate": "2020-12-31", "marketValue": 1100.00, "addedCash": 0.00}
      ]
  },
  {
    "fundName": "Investments In The EU",
    "currency": "EUR",
    "assetsValues":
      [
        {"valueDate": "2021-01-01", "marketValue": 1000.00, "addedCash": 1000.00}
      ]
  }
]

You can also check the input for the introduction's example here.

Compound Rates

A compound rate is represented by a time interval over which it is effective and by a numeric value. There can be multiple compound rates in the program's input to vary the compounding effect over many time intervals.

The schema is as follows:

    <input>        ::= <rate>+
    <rate>         ::= <interval> <value>
    <interval>     ::= string
    <value>        ::= number

where the interval and value are provided as a pair (an array of two elements). The interval is formatted as YYYY-MM-DD/YYYY-MM-DD with the first date being the beginning and the second, the end. Importantly, multiple rates should cover a continuous interval of time where one rate starts where another ends, spanning the valuation interval of all funds in the input. Also, the rates' values should be annual.

See an example of json input:

[
  ["2020-01-01/2020-07-01", 1.10],
  ["2020-07-01/2021-01-01", 0.95],
]

You can also check the input for a variation with rates on the introduction's example here.

Finally, it is possible to specify a single rate value for all cash flows from all funds with a number directly passed to the program. The time interval for such a rate is from the earliest valuation to the latest from all funds.

Using The Command Line Program

Firstly, get a short summary on how to use index and the options available with the following:

    $ index --help

You provide the input to the program by either piping the json data in or indicating the path to it as an argument to the command. Then, there are three parameters that you can tweak:

  • the time interval to report on. You can specify a begin date and / or an end date. If you don't, the earliest and / or the latest valuations' dates are used. The format is YYYY-MM-DD. Note that this interval has no impact on the computation of the indices, it just focuses the reports on the given time period.
  • the dimensions of the charts, height and width. The former is only for comfort of reading but the latter has an impact on the accuracy. Indeed, the charts are just printed characters so that every printed column covers a fixed slice of the choosen time interval. Increasing the width, that is the number of columns, allows the latter to cover smaller amounts of time hence revealing patterns of shorter terms.
  • the compound rates to compute the time value of cash flows. You can either specify the path to a file with the rates' json data or a single numeric value to apply to all cash flows. When this option is unspecified, cash flows are compounded with a rate of 1, meaning their values don't vary with time.

Try it out, print the introduction's example with:

    $ cat docs/example.json | index

or

    $ index docs/example.json

and customize the output:

    $ index docs/example.json -b 2020-07-01 -e 2021-01-01 -h 20 -w 140

Re-evaluate the performance of the introduction's example by accounting for inflation in invested and returned cash flows. Using quarterly core CPI figures for 2020 in the USA from the Federal Reserve Bank of Saint-Louis:

    $ index docs/example.json --rates docs/rates.json

The output can be found here.

Or using a single rate for the annual core CPI in 2020 in the USA from the same institution:

    $ index docs/example.json --rates 1.0171

The output can be found here.