Git Product home page Git Product logo

typescript-asset-rebalancer's Introduction

Calculate how to divide a sum entering an investement, between all assets with different allocations. The initial sums may not be already in a balanced allocation.

My objective was to add money to the investment without selling any existing asset. I wanted to find an algorithm that didn't include negative rebalancings. Durying my work I also found a way to calculate how to remove a sum and moving towards the target allocation at the same time.

Usage

The script does not accept arguments and the inputs are hardcoded in the code. So to test with different inputs you must edit the typescript code.

Inputs

Edit the initial part of the main() function to change the inputs. Inputs are:

  • An array were every element represent one asset, the current allocated value (value field) and the allocation target, are the data required. A name of the asset is added for clarity when printing the results.

  • The sum we are going to add in the investment, can be positive (buying) or negative (selling)

Outputs results

After the execution of the script, two results are displayed, one the permits negative rebalancings and another that don't permit them. The results report the sum to add to each asset and the final asset allocation.

How to use the script

Dependencies installation

This script requires node and yarn. I assume you are familiar with node, or at least you have node installed on your machine. To install node visit https://nodejs.org and install the latest LTS (Long Term Support) version.

Clone this repository, and at the root of the repository run yarn install in a terminal.

That's it ๐Ÿš€

Script run

In the package.json are located two scripts to run the application, one that use ts-node and another that first transpile the typescript code in javascript and then execute it with node. Homewer the script can be run directly from the cli like a bash script.

# Directly from the terminal
> ./src/main.ts
# Using ts-node
> yarn start:ts-node
# Transpile and run
> yarn start:node-dev

typescript-asset-rebalancer's People

Contributors

luckv avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.