Code Monkey home page Code Monkey logo

asset-allocation-python's Introduction

ToC:

Asset-Allocation

Asset Allocation implementation in Python

Introduction

The idea here is to encapsulate Asset Allocation logic into a separate component and make it available to other projects (GnuCash Portfolio, and Android apps).

This will include its own data storage.

Dependencies will include:

  • price database, for calculation of current value
  • transaction database for securities, for calculation of current value

Development

Requirements are generated with pipreqs. Install requirements from requirements.txt.

Configuration

On the first run, a config file will be created in the user's directory, based on the template in project's data directory.

Data Store

Data storage is in a SQLite database, which allows for portability, easy queries and relatively easy editing. The sample data file is in "data" folder.

Tests

To lint the code, execute pylint from the project root directory. To run tests, execute pytest from the project root directory.

asset-allocation-python's People

Contributors

mistery avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

asset-allocation-python's Issues

Default Currency

Add the setting for default currency, and perhaps a cli parameter.
The currency is currently hard-coded.

Read prices from external source

As noted in #1, the price database will need to be external. Perhaps another tool, that populates the data?

  • Look into Finance::Quote scripts.
  • GnuCash book has a price database
  • Separate project? (again, shared for Android MMEX and PC)

Allow partial allocation

One stock can belong to multiple asset classes. I.e. a bond fund belongs 60% to international and 40% to domestic bonds.

Configuration

Configuration file is required in order not to constantly repeat parameters.

  • create configuration file
  • add logic for reading the configuration values
  • add option for the location of the database, with default value.
  • add option for the location of the Price database.
  • add cli command for editing config value? It is easier to edit it via text editor.
  • add cli command for deleting the current user's file (when run the next time, it will be created automatically)
  • add cli command to set the aa db path

Option to output HTML

Since the default option is to output ASCII-formatted asset allocation report, a parameter would allow formatting the output as HTML.
Only works with the print (default) option.

--output html

Add initial parser

  • Get the parser from GnuCash Portfolio project.
  • load values from GC book
  • load prices from price db

Create a view model for display

Instead of assembling the rows, create a view model that is to be used for display.
The model is a display row, with columns as properties. Simple string values?

Editing Asset Class from cli

Allow editing asset class from cli.
If modifying Allocation, always recalculate total. It has to be 100%. Provide a Warning if it does not. Exception would block editing while Warning allows the user to modify another record and correct the allocation.

aa edit "id" --allocation "10"

Run on Android

Try some of the available options on Android, based on the list:

  • Chaquopy. Android Studio plugin. Builds into a native Android app.
  • PyBee
    VOC => transpiles single modules into .class files. Does not convert the project dependencies but only individual python modules. Errors when running. No go.
  • Kivy
  • QPython; can not install SQLAlchemy.
  • PyDroid. Interpreter on Android. Works!
  • Termux <= works! This is the option of choice.

Add command for creation of asset class

Allow creating an asset class record through cli.

  • create asset class with minimum attributes, i.e. name. Others are set to default and can be modified by editing.
  • auto-assign and return id on creation

aa add "asset class name" --parent "id"

Depends on #5.

manual check

check the values manually:

  • stock value
  • currency calculation
  • ac sum of stock values
  • allocation diff calculation
  • % calculation (set value)

display full aa model, with stock info

In addition to #16, allow displaying stock information for each asset class:

  • name/symbol
  • current value
  • current %, based on value

Indent stock info one level below each class. This is not shown by default but a switch enables it.

calculate allocation difference

between allocated % / value and current.
add columns to the output
this is used for threshold (i.e. 20% diff triggers a notification)

Add a CLI interface

Allow a command-line interface (CLI) for easy testing and use.

  • the default action is to display the standard allocation report (this is the main output)
  • Try it on Android.
  • add option to output HTML

Links:

Allow manual adjustments to diff amount

From alensiljak/gnucash-portfolio#44.

Allow manual adjustments (buffers) to allocation difference amounts.
This is used when switching allocations but do not want to make an immediate transfer but freeze the amount based on the current prices.
The resulting amount will then depend on the price swings. When allocation is increased by purchasing more stock, the adjustment can be modified.

Create a data store

Create a data store for asset allocation. Use the implementation from MoneyManagerEx for Android for start.

Setting for cash accounts

In order to get the cash asset class amount, there must be a setting that lists the cash accounts to use.
Options:

  • specify all the cash accounts to use
  • specify one, top-level, account to use for cash

The second option should work well, unless there is a specific need to list multiple accounts explicitly.

option to identify unallocated holdings

Find holdings that are not part of asset allocation.
These are securities (non-currency) that

  • exist in the book
  • have non-zero balance
  • are not found in the aa mapping table (stock links)

Compare to AA in MMEX

Compare the report to the one in MMEX for Android and identify any discrepancies.
Also compare to GC Portfolio.

Difference threshold

allow setting difference threshold (i.e. 20%)
and mark the rows in the output, with difference % larger than this value

Model Validation

Create a method for AA model validation.
It can be called via CLI explicitly. It is also utilized at some key points in the app. The validation errors are not exceptions but are reported to the user so that they can be mitigated.

Especially useful when the partial allocation is implemented as it will ensure that the value of any specific symbol is correctly allocated among asset classes.

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.