103 online 3 members  + Join RP Base  +
FreeTool

mxdevtool-python

by montrixdev  ·  version 2023.10.30  ·  updated 2 days ago

No reviews yet

Downloads
0
Reviews
0
Size
137 KB
Code check
Clean
Licence
MIT
Released
Nov 2026

Financial Library ( Economic Scenario Generator, Asset Liability Management, Pricing )

mxdevtool-python
MxDevTool(Beta) : Financial Library
==========================

MxDevTool is a Integrated Developing Tools for financial analysis.
Now is Beta Release version. The Project is built on top of QuantLib-Python.

Xenarix(Economic Scenario Generator) is moved into submodule of MxDevTool.
Feature Support
Functionalty :

  • Economic Scenario Generator
  • Asset Liability Mangement
  • Random Number Generator (MersenneTwister, Sobol, ...)
  • Moment-Matching Process
  • InterestRateSwap Pricing
  • Option Pricing
  • Fast Calculation
Version Rule
Version syntex is {Major}-{Miner}-{QuantLib_Version}-{Patch}
Installation
To install MxDevTool, simply use pip :

 {.sourceCode .bash}
$ pip install mxdevtool

Install Troubleshooting
If you have following error :

ERROR: No matching distribution found for ( numpy ) (from mxdevtool==0.8.30.2)

You need to install ( numpy ) first.

If you use python 3.9 and following error
RuntimeError: The current Numpy installation ('~~~\\numpy\\__init__.py') fails to pass a sanity check due to a bug in the windows runtime. See this issue for more information: https://tinyurl.com/y3dm3h86

use numpy version numpy==1.19.3 ->
Link

Quick UsageHull White Model Generate
import sys, os
import mxdevtool as mx
import mxdevtool.xenarix as xen
import mxdevtool.termstructures as ts
import numpy as np

filename = './test_hw1f.npz'
ref_date = mx.Date.todaysDate()

def model():
    tenor_rates = [('3M', 0.0151),
                ('6M', 0.0152),
                ('9M', 0.0153),
                ('1Y', 0.0154),
                ('2Y', 0.0155),
                ('3Y', 0.0156),
                ('4Y', 0.0157),
                ('5Y', 0.0158),
                ('7Y', 0.0159),
                ('10Y', 0.016),
                ('15Y', 0.0161),
                ('20Y', 0.0162)]

    tenors = []
    zerorates = []

    interpolator1DType = mx.Interpolator1D.Linear
    extrapolator1DType = mx.Extrapolator1D.FlatForward

    for tr in tenor_rates:
        tenors.append(tr[0])
        zerorates.append(tr[1])

    fittingCurve = ts.ZeroYieldCurve(ref_date, tenors, zerorates, interpolator1DType, extrapolator1DType)
    alphaPara = xen.DeterministicParameter(['1y', '20y', '100y'], [0.1, 0.15, 0.15])
    sigmaPara = xen.DeterministicParameter(['20y', '100y'], [0.01, 0.015])

    hw1f = xen.HullWhite1F('hw1f', fittingCurve, alphaPara, sigmaPara)

    return hw1f

def test():
    print('hw1f test...', filename)

    m = model()
    timeGrid = mx.TimeDateGrid_Equal(ref_date, 3, 365)
    rsg = xen.Rsg(sampleNum=5000)
    results = xen.generate1d(m, None, timeGrid, rsg, filename, False)

if __name__ == "__main__":
    test()

Usage
Import MxDevTool Library :

import os, time, platform
import numpy as np
import mxdevtool as mx
import mxdevtool.shock as mx_s
import mxdevtool.xenarix as xen
import mxdevtool.termstructures as ts
import mxdevtool.quotes as mx_q
import mxdevtool.marketconvension as mx_m
import mxdevtool.data.providers as mx_dp
import mxdevtool.data.repositories as mx_dr
import mxdevtool.utils as utils

Models and Calc
Set Common Variables :

ref_date = mx.Date.todaysDate()
**(period, rf, div)**
tenor_rates = [('3M',  0.0151, 0.01),
               ('6M',  0.0152, 0.01),
               ('9M',  0.0153, 0.01),
               ('1Y',  0.0154, 0.01),
               ('2Y',  0.0155, 0.01),
               ('3Y',  0.0156, 0.01),
               ('4Y',  0.0157, 0.01),
               ('5Y',  0.0158, 0.01),
               ('7Y',  0.0159, 0.01),
               ('10Y', 0.0160, 0.01),
               ('15Y', 0.0161, 0.01),
               ('20Y', 0.0162, 0.01)]

tenors = []
rf_rates = []
div_rates = []
vol = 0.2

interpolator1DType = mx.Interpolator1D.Linear
extrapolator1DType = mx.Extrapolator1D.FlatForward

for tr in tenor_rates:
    tenors.append(tr[0])
    rf_rates.append(tr[1])
    div_rates.append(tr[2])

x0 = 420
**yieldCurve**
rfCurve = ts.ZeroYieldCurve(ref_date, tenors, rf_rates, interpolator1DType, extrapolator1DType)
divCurve = ts.ZeroYieldCurve(ref_date, tenors, div_rates, interpolator1DType, extrapolator1DType)

utils.check_hashCode(rfCurve, divCurve)
**variance termstructure**
const_vts = ts.BlackConstantVol(refDate=ref_date, vol=vol)

periods = [str(i+1) + 'm' for i in range(0, 24)] # monthly upto 2 years
expirydates = [null_calendar.advance(ref_date, p) for p in periods]
volatilities = [0.260, 0.223, 0.348, 0.342, 0.328, 0.317, 0.310, 0.302, 0.296, 0.291, 0.286, 0.282, 0.278, 0.275, 0.273, 0.270, 0.267, 0.263, 0.261, 0.258, 0.255, 0.253, 0.252, 0.251]

curve_vts = ts.BlackVarianceCurve(refDate=ref_date, dates=expirydates, volatilities=volatilities)

utils.check_hashCode(const_vts, curve_vts)

Models
Geometric Brownian Motion ( Contant Parameter ) :

gbmconst = xen.GBMConst('gbmconst', x0=x0, rf=0.032, div=0.01, vol=0.15)

Geometric Brownian Motion :
gbm = xen.GBM('gbm', x0=x0, rfCurve=rfCurve , divCurve=divCurve, volTs=curve_vts)

Heston :
heston = xen.Heston('heston', x0=x0, rfCurve=rfCurve, divCurve=divCurve, v0=0.2, volRevertingSpeed=0.1, longTermVol=0.15, volOfVol=0.1, rho=0.3)

Hull-White 1 Factor :

alphaPara = xen.DeterministicParameter(['1y', '20y', '100y'], [0.1, 0.15, 0.15])
sigmaPara = xen.DeterministicParameter(['20y', '100y'], [0.01, 0.015])

hw1f = xen.HullWhite1F('hw1f', fittingCurve=rfCurve, alphaPara=alphaPara, sigmaPara=sigmaPara)

Black–Karasinski 1 Factor :

bk1f = xen.BK1F('bk1f', fittingCurve=rfCurve, alphaPara=alphaPara, sigmaPara=sigmaPara)

Cox-Ingersoll-Ross 1 Factor :

cir1f = xen.CIR1F('cir1f', r0=0.02, alpha=0.1, longterm=0.042, sigma=0.03)

Vasicek 1 Factor :

vasicek1f = xen.Vasicek1F('vasicek1f', r0=0.02, alpha=0.1, longterm=0.042, sigma=0.03)

Extended G2

…