Coder Social home page Coder Social logo

bweilers / index_rebalancing Goto Github PK

View Code? Open in Web Editor NEW

This project forked from firobeid/index_rebalancing

0.0 0.0 0.0 2.39 MB

An optimization implementation for rebalancing an index constitute assets weights

Python 0.23% Jupyter Notebook 99.77%

index_rebalancing's Introduction

Index_Rebalancing

Package Requirments & Versions

pip install x where x is the below listed packages

  • python == 3.7+ Code was tested on versions3.8.10& 3.9.7
  • numpy == 1.21.5
  • pandas == 1.3.5+
  • hvplot == 0.8.0
  • openpyxl == '3.0.9'
  • scipy == 1.7.3

Purpose of Use

  • Fetch an already existing index constitutes assets in the means of rebalacing its weights semi-annually
  • The code is two parts:
    1. Index Construction Rules:Fetch assets based on Z_Value ranking and apply certain buffer for a specific date

    2. Constituent Weighting Scheme: Run an optimization problem given:

      a. minimize $\sum_{i=1}^{n_stocks} [(Capped_Wt - Unapped_Wt) / Unapped_Wt]$

      b. Stock Cap = Min (5%, 20*FCap_Wt)

      c. Stock Floor = 0.05%

Files Navigation

  • Index_Rebalancing.ipynb: Code explanation, building, some data visulaization and divide by parts
  • Index_Rebalancer.py: Executable script alternative for the jupyter notebook
    • In the command line to run (after going to directory location): Type python Index_Rebalancer.py then follow terminal prompts to select rebalancing date.
  • functions.py: Some helper functions needed for the executable script
  • testing.py: Unit testing file for proof of concept on testing
    • In the command line to run (after going to directory location): Type python -m unittest -v testing.py
  • Tasks for Python Test (003).xlsx: Input and destination output file for algo to run and save results in to.

Note: Output tab in the Tasks for Python Test (003).xlsx is already populated with results and the code already is resilient against overwriting existing output based on date already saved, thus delete all contenst in the output tab to see the full proccess of saving the results.

Limitation

The optimization constraint Sector Cap = 50% was not met in the minimization process although passed to the minimization function. That is a limitation is must be investigated, one reason might be numerical precision in the optimizatio process or the constrain equations (for each sector) was not passed programatically correct to the minimization process.

After researching also found that the issue might be from the intial_weights/gusses do not satisfy the future constraints and adjusted those by the intial_weights() function but that also didnt solve the issue and the sector constraint was not met after the optimization process. One thing to note, when the sector consrtaint type ineq is switched to eq in the {'type': 'eq', 'fun': lambda x: np.array(0.5 - (np.sum(x[[indexes]])))} all optimizations constrainst pass the check!

index_rebalancing's People

Contributors

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