Git Product home page Git Product logo

tfa's Introduction

📈📉 Treasury Automation challenge

Here is a small app which should do forecasting for balance movements for Treasury team. The whole feature is a pretty big one, but we need a quick prototype to showcase it for Treasury team, so they can decide if this app better than Excel spreadsheets they are using right now.

🗺️Context

When our customer asks for service, basically her request is to transfer money from one place to another. We rely on network of Sending and Receiving Partners (SP and RP). Each RP has a balance associated with it. Each day can be many movements to a balance from different SPs.

Having historical balance movements, one can forecast what will be balance movements next days. And the next important step: having balance movements forecast for today and having balance snapshot amount, one can calculate required wire transfer, to top up the balance. This forecasting and wire calculation is a minimum valuable product for Treasury.

📋Requirements

  1. Provide API endpoint to run forecasting and wire transfer for a given date and balance id

    POST /api/v1/forecasting/{balance_id}/{forecasting_date}
    

    The app shall do one day forecasting, for a given day.

    Here you need to pick a forecasting method you'd like to use. The easiest is seven-day average: having previous 7 datapoints d1, d2, ..., d7, the forecast for today is mean([d1, ..., d2]). You may use more complicated tools, as ETS (exponential smoothing) or Prophet.

    Explore balance_movements table, it has some data, after you apply alembic migrations. For wire calculation you need to take available_balance from receiving_partner_balances table and forecasted balance movements. Then wire amount is max(0, forecasted balance movements - available_balance). If there is enough money on a balance, wire transfer amount is zero.

  2. Provide API to retrieve forecasted amount and wire amount for a given date and balance id.

    They should be persisted in database, it's also historical data, so that one can review what was forecasts and wire amounts for past day.

  3. Finish ForecastingVariance feature to show variance for a given balance and data range. This feature is partly done. There is a web page with two tabs: chart (done) and table (to do). API endpoint is preset but returns mock data, so that's for you to implement it.

    Table shall have columns: date, actual amount, forecasted amount, variance, MAPE. MAPE is a mean absolute percentage metric. Chart shall display two curves: forecasted traffic and actual traffic. The page has Scale selector: (Daily, Weekly or Monthly), but you can implement everything with assumption that only Daily is used and show only daily traffic (both forecasted and actual).

    • Chart is done.

In terms of priorities, Wire Amount calculation is nice to have feature. So you may drop it, if you are out of time.

💎 Quality requirements

We expect at least basic tests for web app and some test cases for python code (both for api and db parts). This project has some examples.

Please state any assumptions that you make, or ask questions in case of ambiguity/incompleteness of requirements.

💻Development

Database setup

You may use postgres from docker:

docker-compose up db

Then you can connect to it:

docker exec -it tfa-db-1 psql -U postgres -d tfa

🐍Python environment

Use pyenv for easy switch between different Python versions

Install python and dependencies:

pyenv install 3.10  # install required python version
pyenv local 3.10  # creates a .python-version file in your current directory

python -V  # check you have python 3.10

python -m venv venv
source venv/bin/activate
pip install -r app/requirements.txt

Then you can set variables from .env and run fastapi app:

uvicorn app.main:app --host 0.0.0.0 --reload --port 8000

There is also docker-compose.yml which bakes images, run alembic migrations and runs fastapi app with reload option and database. So it can be useful for your development

Tests

PYTHONPATH=. pytest tests

🔮Web

Frontend development is done in JavaScript using Vue library. To start development, install nodejs first on your system.

Install nvm and then use it to install node:

nvm install 15.4
nvm use 15.4

Installing dependencies

$ cd web
$ yarn install
...

Configuration

There is a minimal config file: .env.local. Use this example to create your own .env files in the app and web directories.

Serving the application

From the web/ directory I can run:

$ cd web
$ yarn serve
INFO  Starting development server...

Tests

$ cd web
$ yarn jest
 PASS  __tests__/app.test.js
  App
    ✓ renders the correct markup (7ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.904s
Ran all test suites.

Support

If you have any questions, don't hesitate to ask via email [email protected] 🤝

Delivery and next step

Kindly fork this repository, but don't create PR. Instead, add me (@dadwin) and Pierre (@pierre-vigier) as collaborators. We will have a Panel Interveiew meeting to discuss your solution. Kindly prepare a short 5-10min overview/demo of your solution. Thank you in advance!

Good luck!!!

tfa's People

Contributors

leandroviajando avatar dependabot[bot] avatar

Watchers

 avatar

tfa's Issues

Finish ForecastingVariance feature to show variance for a given balance and data range

This feature is partly done. There is a web page with two tabs: chart (done) and table (to do). API endpoint is preset but returns mock data, so that's for you to implement it.

Table shall have columns: date, actual amount, forecasted amount, variance, MAPE. MAPE is a mean absolute percentage metric.

Chart shall display two curves: forecasted traffic and actual traffic.

The page has Scale selector: (Daily, Weekly or Monthly), but you can implement everything with assumption that only Daily is used and show only daily traffic (both forecasted and actual).

Provide API endpoint to run forecasting and wire transfer for a given date and balance id

POST /api/v1/forecasting/{balance_id}/{forecasting_date}

The app shall do one day forecasting, for a given day.

Here you need to pick a forecasting method you'd like to use. The easiest is seven-day average: having previous 7 datapoints d1, d2, ..., d7, the forecast for today is mean([d1, ..., d2]). You may use more complicated tools, as ETS (exponential smoothing) or Prophet.

Explore balance_movements table, it has some data, after you apply alembic migrations. For wire calculation you need to take available_balance from receiving_partner_balances table and forecasted balance movements. Then wire amount is max(0, forecasted balance movements - available_balance). If there is enough money on a balance, wire transfer amount is zero.

Improve forecasting algorithm

Set up a Docker container with Jupyter installed

Try more advanced forecasting methods: exponential smoothing, linear model, ARIMA, LSTMS + Conv1D, Prophet, Neural Prophet

  • Conv1D layers process the input sequence to capture local patterns and extract important features.
  • The output from Conv1D layers is then fed into LSTM layers, which can learn and model the long-term dependencies within the feature representations extracted by Conv1D.
  • The combination of these layers allows the model to effectively capture both short-term and long-term patterns, resulting in better representation of the underlying structure in the time series data.

Make use of Python dev tools

  • Linter: flake8
  • Type checking: mypy
  • Formatting: black, isort
  • Testing: pytest coverage
  • Commands: Makefile
  • Dependency management: poetry
  • CI: Github Actions
  • Better feedback on linting and tests: Pre-commit hooks

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.