Skip to main content

Modular YAML based portfolio analytics calculation engine

Project description

Portfolio Analytics Calculation Engine

This project provides a modular YAML based portfolio analytics calculation engine. This engine allows to plug in YAML configurations to compute various portfolio related analytics. Engine adheres to YAML schema and is utilising Polars or Python instructions. This project also hosts a dash app that relies on a local LLM model to create schema compliant YAML files. These YAML files are consumed and interpreted by the calculation engine provided.

Build Package

CodeQL Advanced

Release Package to PyPi


Table of Contents


Overview

The analytics calculation engine is designed to process data based on instructions provided in YAML configuration files. It leverages Polars for data manipulation and supports Sphinx for documentation generation.

System Context

graph TD
    A[User] -->|Interacts with| B[Dash Web UI]
    B -->|Sends JSON data| C[Backend Service]
    C -->|Fetches data from| G[Data Service]
    G -->|Fetches data from| D[SQL Server]
    C -->|Processes YAML files with| E[Calculation Engine]
    E -->|Uses| F[Polars]
    E -->|Uses| I[YAML Files]
    C -->|Interacts with| H[GPT App]
    H -->|Generates| I[YAML Files]
    C -->|Returns results to| B
    B -->|Displays results to| A

Video Demo

IMAGE ALT TEXT HERE


Features

  • Modular design with separation of data, configuration, and computation.
  • Dynamic analytics calculations via YAML configurations.
  • Regression testing capabilities with YAML support.
  • Sphinx documentation for the codebase.

Getting Started

Prerequisites


Installation

  1. Clone the Repository

    git clone https://github.com/maxicusj/polarparrot.git
    cd polarparrot
    
  2. Install Dependencies

    pip install -r requirements.txt
    
  3. Create Environment Configuration (.env)
    Create a .env file in the root directory with the following content:

    DB_SERVER=localhost
    DB_DATABASE=AdventureWorks
    DB_USERNAME=sa
    DB_PASSWORD=password
    
  4. Start Backend Services, Web UI and GPT Assistant
    Start the services with the provided script:

    ./start_services.sh
    

Usage

Running Analytics defined in JSON config file

Run the selected YAML metrics against mockup test data:

python metrics_runner.py analytics_list.json

Running Regression Tests

Run regression on YAML metrics against mockup test data in data.py:

python tests/regression_runner.py

Running Unit Tests

Run the selected YAML metrics against mockup test data:

python tests/unit_tests_runner.py

Running Analytics via CURL Command

You can test the backend service with a sample request:

curl -X POST http://localhost:8088/analytics \
-H "Content-Type: application/json" \
-d '{
  "positions_json": "[{\"instrument_id\": 1, \"weight_1\": 0.00005, \"weight_2\": 0.00004, \"weight_3\": 0.00003, \"weight_4\": 0.00005, \"is_laggard\": true}, {\"instrument_id\": 2, \"weight_1\": 0.00007, \"weight_2\": 0.00006, \"weight_3\": 0.00007, \"weight_4\": 0.00006, \"is_laggard\": false}, {\"instrument_id\": 3, \"weight_1\": 0.0001, \"weight_2\": 0.00008, \"weight_3\": 0.00002, \"weight_4\": 0.0001, \"is_laggard\": true}, {\"instrument_id\": 4, \"weight_1\": 0.00002, \"weight_2\": 0.00005, \"weight_3\": 0.00009, \"weight_4\": 0.00002, \"is_laggard\": true}, {\"instrument_id\": 5, \"weight_1\": 0.00009, \"weight_2\": 0.00007, \"weight_3\": 0.00005, \"weight_4\": 0.00007, \"is_laggard\": false}]", 
  "analytics_list_json": "{\"analytics\": [\"yaml/0002.yaml\", \"yaml/0004.yaml\"]}"
}'

Running Analytics via Web UI

http://localhost:8050

Generating YAML config Files with GPT Assistant

http://localhost:8080

Project Structure

  • metrics_runner.py: Executes analytics calculations as per YAML configurations.

  • regression_runner.py: Validates metrics using regression tests.

  • unit_tests_runner.py: Validates metrics using regression tests.

  • start_services.sh: Starts backend services and the web UI.

  • requirements.txt: Lists required Python packages.

  • .env: Environment variables for database connection.

  • calculation_engine.py: The actual analytics engine.

  • backend_service.py: Backend service.

  • data_service.py: Data service, providing interface to the SQL database.

  • app.py: Web UI for running analytics against provided YAML config and portfolio positions.

  • gpt/gpt_service.py: Web UI for generating YAMLs with the help of an LLM.

  • data/data.sql: Sample SQL table and data population script for instrument_categorization table. Used by analytics engine.


Customization

You can customize this engine by:

  • Adding new YAML files to the yaml/ directory to define analytics configurations.
  • Generating new YAML files by talking to a locally available LLM model(http://localhost:8080) and placing the genrated files to the yaml/ directory to be interrpreted by the engine.
  • Extending the Polars DataFrame manipulation logic in the calculaton_engine.py file.

License

This project is licensed under MIT License.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polarparrot-0.0.11.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polarparrot-0.0.11-py3-none-any.whl (967.4 kB view details)

Uploaded Python 3

File details

Details for the file polarparrot-0.0.11.tar.gz.

File metadata

  • Download URL: polarparrot-0.0.11.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for polarparrot-0.0.11.tar.gz
Algorithm Hash digest
SHA256 0de0a380231b045c6ca884c72fc8a3da588797ee3c4da32aae4b9ea701758c98
MD5 ce2d25ea51122d2026edc252f58277c9
BLAKE2b-256 4eee1fc9872cdfeb6bb576ed50fbd7223d04e74fc6838a0044f170e5af68f88d

See more details on using hashes here.

Provenance

The following attestation bundles were made for polarparrot-0.0.11.tar.gz:

Publisher: publish.yml on maxicusj/polarparrot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polarparrot-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: polarparrot-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 967.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for polarparrot-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 88f1b760c3c65a458ccb36e2dad3d4d5152b6e1f81fc91f527afe3a7170902a9
MD5 3b63d047c6200d780ceda9aa3ad0844b
BLAKE2b-256 a045fa1e78d223a356fee79d35be29266e64eabfdbfeaa56da6b41b82a6c92da

See more details on using hashes here.

Provenance

The following attestation bundles were made for polarparrot-0.0.11-py3-none-any.whl:

Publisher: publish.yml on maxicusj/polarparrot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page