Skip to content

holmen1/smith-wilson-par

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smith-wilson-par

Description

A RESTful API to extrapolate Risk Free Rates from par swap rates using the Smith-Wilson method.

See EIOPA Risk Free Rate Technical Documentation

Usage

API

sw_parameters.json

{
  "par_rates": [0.0363, 0.033716, 0.030886, 0.02917],
  "par_maturities": [2, 3, 5, 10],
}
uvicorn api.main:app
INFO:     Started server process [9354]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
curl -X POST 'http://127.0.0.1:8000/api/eiopa' -H 'accept: application/json' -H 'Content-Type: application/json' -d @./Data/sw_parameters.json
{"alpha":0.39922635774331505,"rfr":[0.035834839761121895,0.03401966679727653,0.031544539162605245,..., 0.03392432779538157,0.03392816454917802],"price":[1.0,0.9949057833655796,0.9898401220563251,0.984810806107...]}

Rate projection with predefined alpha

curl -X POST 'http://127.0.0.1:8000/api/eiopa?alpha0=0.17' -H 'accept: application/json' -H 'Content-Type: application/json' -d @./Data/sw_parameters.json

Dockerized API

Build

docker build --tag 'smith-wilson-api' .

Run

docker run -dp 8004:8000 'smith-wilson-api'

Test

curl 'http://localhost:8004'
{"message":"Hello from Smith-Wilson API!"}

Stop

docker ps
CONTAINER ID  IMAGE  COMMAND CREATED  STATUS  PORTS NAMES  
399836b60511    holmen1/smith-wilson-api  "uvicorn api.main:ap…"  About a minute ago   Up About a minute  0.0.0.0:8004->8000/tcp, :::8004->8000/tcp unruffled_dewdney
docker stop unruffled_dewdney

Prune

$ docker image prune

Deploy to Azure Container Instances

RESOURCE_GROUP="actuarial-apps-rg"
LOCATION="northeurope"
API_NAME="smith-wilson-api"
GITHUB_USERNAME="holmen1"
ACI_NAME="aci"$GITHUB_USERNAME
docker build --tag $GITHUB_USERNAME/$API_NAME .  
docker push $GITHUB_USERNAME/$API_NAME

Create a resource group

az group create --name $RESOURCE_GROUP --location $LOCATION

Create a container

az container create \
  --name $ACI_NAME \
  --resource-group $RESOURCE_GROUP \
  --image $GITHUB_USERNAME/$API_NAME \
  --ports 8000 \
  --environment-variables 'PORT'='8000' \
  --dns-name-label $ACI_NAME
az container show --resource-group $RESOURCE_GROUP --name $ACI_NAME --query "{FQDN:ipAddress.fqdn,ProvisioningState:provisioningState}" --out table

FQDN ProvisioningState
aciholmen1.northeurope.azurecontainer.io Succeeded

curl -X POST 'aciholmen1.northeurope.azurecontainer.io:8000/rfr/api/rates' -H 'acceptn/json' -H 'Content-Type: application/json' -d @./Data/sw_parameters.json

Pull the container logs

az container logs --resource-group $RESOURCE_GROUP --name $ACI_NAME

INFO: Started server process [19]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: 10.92.0.24:57618 - "GET / HTTP/1.1" 200 OK
INFO: 10.92.0.24:51326 - "POST /rfr/api/rates HTTP/1.1" 201 Created INFO: 10.92.0.25:50880 - "GET /openapi.json HTTP/1.1" 200 OK

Clean up resources

az group delete --name $RESOURCE_GROUP

Notebook

demo.ipynb

TODO

  • Robust find_alpha
  • Deploy to Azure
  • Add tests
  • RequestModel parameter validation
  • Zero coupon bond
  • Add documentation
  • Add logging
  • Add GitHub Actions
  • Add Dockerfile
  • Add Docker-compose

About

Risk Free Rate extrapolation from par swap rates

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published