GithubHelp home page GithubHelp logo

asset-rebalance's Introduction

Asset Rebalancer

This Python project includes an AWS CDK stack that provisions the necessary resources to host a Lambda function for the rebalancing of assets. The solution also utilizes Amazon DynamoDB for data persistence. The Lambda function implemented in Python uses Pandas to manage and calculate asset rebalancing based on given portfolio models.

Prerequisites

Before you deploy the stack, make sure you have the following installed:

  • AWS Command Line Interface (CLI)
  • AWS CDK Toolkit
  • Python 3.7 or later
  • Node.js (for AWS CDK)

Installation

  1. Clone the repository to your local machine by running:

    git clone https://github.com/magoulet/asset-rebalance.git
    cd asset-rebalance
  2. Install the required Python packages in a virtual environment:

    python -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt
  3. Bootstrap your AWS environment to use the AWS CDK:

    cdk bootstrap aws://ACCOUNT_ID/REGION

    Replace ACCOUNT_ID with your AWS account ID and REGION with your preferred region.

Deployment

Deploy the AWS CDK stack with the following command:

cdk deploy

This command deploys the AssetRebalanceStack to your default AWS account/region.

Usage

After deployment, the Lambda function can be triggered via the API Gateway endpoint that is created as part of the CDK stack. The endpoint takes in a JSON payload containing the portfolio model, new money to allocate, and current values of assets.

A sample payload would look like this:

{
    "model": {
        "Asset1": 0.20,
        "Asset2": 0.15,
        "Asset3": 0.15,
        "Asset4": 0.5
    },
    "new_money": 2000,
    "values": {
        "Asset1": 1000,
        "Asset2": 1000,
        "Asset3": 1000,
        "Asset4": 1000
    }
}

Use your preferred tool (e.g., curl, Postman) to send a POST request to the API Gateway endpoint with the payload.

Architecture

The CDK stack does the following:

  • Creates a Python Lambda function for asset rebalancing logic.
  • Sets up an API Gateway REST API to expose the Lambda function as an HTTP endpoint.
  • Provisions a DynamoDB table for storing execution records.
  • Grants the Lambda function permission to write to the DynamoDB table and access environment variables.

The Lambda function accepts a JSON input containing an asset model with desired weights, additional funds to include (new money), and current asset values. It calculates the necessary rebalancing actions and outputs them.

Local Testing

For local testing, you can use AWS SAM with the lambda code, but be aware that for full AWS integrations, you should use your AWS Cloud environment.

Contributing

Contributions to this project are welcome. Please follow these steps:

  1. Fork the repo and create your branch from main.
  2. Make your changes and test.
  3. Issue a pull request with a comprehensive description of changes.

Support

Raise an issue in the repository for any questions or concerns.

License

This project is MIT licensed. See the LICENSE file for details.

asset-rebalance's People

Contributors

magoulet 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.