Package: qfrm
Quantitative Financial Risk Management (QFRM) project is a (rapidly growing) set of analytical tools
to measure, manage and visualize identified risks of derivatives and portfolios in finance.Why use Quantitative Financial Risk Management (QFRM) package:We applyobject-oriented programming (OOP) paradigmto abstract the complexities of financial valuation.Plentiful examples: each class has a numerous examples, including sensitivity plots and multidimensional visualization.Resources: we included references (J.C.Hull’sOFODtextbook, academic research and online resources) we used to build and validate our analytical tools.Simplicity, consistency and usability: QFRM uses basic data structures as user inputs inputs/outputs (I/O).Longevity: qfrm dependencies are limited toPython Standard Library, pandas, numpy, scipy, and matplotlib.We try to sensibly vectorize our functions to help you with application of QFRM functionality.All programing is done with usability/scalability/extendability/performance in mind.This project grows rapidly with an effort from a dozen of bright quant finance developers. Check back for updates throughout Fall 2015.Our Team:This is a group of ambitious and diligent Rice University science students from doctoral, masters and undergraduate programs. United in their work, we expand and contribute to finance community and QFRM course, led by Oleg Melnikov, a statistics doctoral student and instructor of QFRM course at Rice University, Department of Statistics.Oleg Melnikov(author, creator), Department of Statistics, Rice University,http://Oleg.Rice.edu,xisreal@gmail.comThaw Da Aung (contributor),  Department of Physics,Thawda.Aung@rice.eduYen-Fei Chen (contributor),  Department of Statistics,Yen-Fei.Chen@rice.eduPatrick J. Granahan  (contributor), Department of Computer Science,pjgranahan@rice.eduHanting Li (contributor), Department of Statistics,HANTING.LI@rice.eduSha (Andy) Liao (contributor), Department of Physics,Andy.Liao@rice.eduScott Morgan (contributor), Department of Computer Science,spmorgan@rice.eduAndrew M. Weatherly (contributor), Department of Computational and Applied Mathematics,amw13@rice.eduMengyan Xie (contributor), Department of Electrical Engineering,Mengyan.Xie@rice.eduTianyi Yao (contributor), Department of Electrical Engineering,Tianyi.Yao@rice.eduRunmin Zhang (contributor), Department of Physics,Runmin.Zhang@rice.eduOOP Design and functionality:In progress:Bond pricing is temporarily disabled (will return soon), but you’ll find numerous exotic option pricing (via Black-Scholes model, lattice tree, Monte Carlo simulation and finite differencing) in the package.classPVCF(present value of cash flows) accepts time-indexed cash flows and a yield curve to compute:net present value (NPV), internal rate or return (IRR), time value of money (TVM)Linearly interpolated yield curve with time-to-maturities (TTM) matching those of cash flows (CF)Visualization: CF diagramclassBond(inheritsPVCF) accepts coupon/frequency/TTM specification along with optional yield curve (with optional TTM) to compute:Valuation and performance analytics: clean/dirty price, yield to maturity (ytm), par and current yieldinterest rates (IR) are assumed to be continuously compounded (CC), but user has a method to convert from/to any frequency.Risk analytics: Macaulay/Modified/Effective durations, convexityVisualization: CF diagram, dirty/clean price convergence, price sensitivity curves and slopes with and without convexity adjustment.classUtilprovides some helpful functionality for verifying/standardizing in I/O of other class’ methods.Planned implementation:Fixed income portfolio analytics, exotic option pricing (via lattice, Black-Scholes model (BSM),
Monte Carlo simulations, and Finite Differencing Methods (FDM)), and further visualization of concepts in finance.Genesis:This project started as aQFRM R packagein Spring 2015 QFRM course (STAT 449 and STAT 649) at Rice University.The course is part of computational finance and economic systems (CoFES) program,
led byDr. Katherine Ensor.Underlying textbook (source of financial calculations and algorithms)Options, Futures and other Derivatives (OFOD)by John C. Hull, 9ed, 2014,ISBN 0133456315is a well established text in finance and risk management. Major certification exams in finance (CFA, FRM, CAIA, CQF, …) list it as a core reference.Install:Directly from PyPI with pip command in a terminal (or windows command, cmd.exe) prompt, assumingpipis in your PATH:$pipinstallqfrmTypical usage:3% annually-paying bond with 3.1 TTM (in years), evaluated at 5% continuously compounded (CC) yield-to-maturity (YTM),
i.e. flat yield curve (YC)>>>Bond(3,1,3.1,pyz=.05).analytics()------------------Bondanalytics:------------------------*Annualcoupon,$:3*Couponfrequency,p.a.:1Timetomaturity(ttm),yrs:3.1*Cashflows,$p.a.:(3.0,3.0,3.0,103.0)Timetocashflows(ttcf),yrs:(0.10000000000000009,1.1,2.1,3.1)Dirtyprice(PVCF),$:96.73623*Cleanprice(PVCF-AI),$:94.03623YTM,CCrate:0.05YTM,rateatcouponfrequency:0.05127Currentyield,rateatcouponfrequency:0.0319*Paryield,rateatcouponfrequency:0.03883Yieldcurve,CCrate:(0.05,0.05,0.05,0.05)Macaulayduration,yrs:2.9208Modifiedduration,yrs:2.77835Effectiveduration,yrs:2.92126*Convexity,yrs^2:8.92202Desc:{}------------------------------------------------------------------------------Medianruntime(microsec)for1iteration(s):11604.918843659107Textbook example (default) of 6% SA bond with 2 years/time to maturity (TTM), see p.83 in Hull’s OFOD/9ed>>>Bond().analytics()4% semi-annual (SA) bond with 4.25 ttm (4 years and 3 mo), evaluated at $97.5 PVCF (which computes to 4.86% ytm or flat YC)>>>b=Bond(4,2,4.25,pyz=97.5)>>>b.ytm()# compute yield from supplied (PVCF) price ($97.5 assumed)0.048615328294339864>>>b.ytm(px_target=(97.5,98,99,100,101))# vectorized computation of yield-to-maturity(0.048615328294339864,0.047305618596811434,0.04470725938701976,0.04213648737177501,0.039592727021145635)>>>b.analytics()# prints full report and visualizationThe same 4% SA bond evaluated with a specific YC.
Zero rates are assumed to have TTM matching those of cash flows (CF), left to right.
Insufficient rates are extrapolated with a constant.>>>b.set_pyz(pyz=(.05,.06,.07,.08)).analytics()The same 4% SA bond evaluated with a specific YC. User provides zero rates with corresponding TTM.
TTM required to evaluate CF are extra/interpolated from existing curve with constant rates on each side.>>>b.set_pyz(pyz=(.05,.06,.04,.03),ttz=(.5,1,2,6)).analytics()This project uses industry-accepted acronyms:AI: accrued interestAPT: arbitrage pricing theoremASP: active server pages (i.e. HTML scripting on server side) by Microsoftb/w: betweenbip: basis pointsBM: Brownian motion (aka Wiener Process)Bmk: benchmarkBOPM: binomial option pricing modelbp: basis pointsBSM: Black-Scholes model or Black-Scholes-Merton modelBT: binomial treec.c.: continuous compoundingCC: continuous compoundingCCP: central counterpartyCCRR: continuously compounded rate of returnCDS: credit default swapCDO: credit default obligationCF: cash flowsCmdt: commodityCorp: corporate (finance or sector)CP: counterparty (in finance)CUSIP: Committee on Uniform Security Identification Procedures, North-American financial security identifier (like ISIN)ESO: employee stock optionETD: exchange-traded derivativeFE: financial engineeringFDM: Finite differencing methodFRA: forward rate agreementFRN: floating rate notesFwd: forwardFX: foreign currency or foreign currency exchangeFV: future valueGBM: geometric Brownian motionGvt: governmentHld: holdingIdx: indexIM: initial marginIR: interest rateIRD: interest rate derivativesIRTS: interest rate term structureISIN: International Securities Identification NumberLIBID: London Interbank bid rateLIBOR: London Interbank Offered RateLT: lattice tree (i.e binomial, trinomial, …)MA: margin account; moving averageMC: margin callMC: Monte Carlo simulationMgt: managementMkt: marketMM: maintenance marginMP: Markov processMTM: marking to marketMtge: mortgageMV: multivariateOFOD: Options, Futures, and Other DerivativesOFOD9e: Options, Futures, and Other Derivatives, 9th editionOIS: overnight index SWAP rateOOP: object oriented programmingp.a.: per annumPD: probability of defaultPDE: partial differential equationPM: portfolio managerPORTIA: portfolio accounting system by Thomson FinancialPts: pointsPV: present valuePVCF: present value of cash flowsQFRM: quantitative financial risk managementREPO: Repurchase agreement rateRFR: risk free rateRN: risk-neutralRNW: risk-neutral worldRoI: return on investmentRoR: rate of returnr.v.: random variables.a.: semi-annualSA: semi-annualSAC: semi-annual compoundingSP: stochastic processSQL: sequel query languageSQP: standard Wiener processSURF: step up recovery floaters (floating rate notes)TBA: to be announcedTBD: To be determinedTOMS: Trade Order Management Solution (or System)Trx: transactionTS: time seriesTSA: time series analysisTTCF: time to cash flowsTTM: time to maturityTVM: time value of moneyUDF: user defined functionURL: universe resource locatorVaR: value at riskVar: varianceVB: Visual Basic (by Microsoft)VBA: Visual Basic for ApplicationsVol: volatilityWAC: weighted-average couponWAM: weighted-average maturityWP: Wiener process (aka Brownian motion)YC: yield curveYld: yieldZCB: zero coupon bond