A Financial Calculator

A financial calculator that provides very fast implementations of common financial indicators using 'Rust' code. It includes functions for bond-related indicators, such as yield to maturity ('YTM'), modified duration, and Macaulay duration, as well as functions for calculating time-weighted and money-weighted rates of return (using 'Modified Dietz' method) for multiple portfolios, given their market values and profit and loss ('PnL') data. 'fcl' is designed to be efficient and accurate for financial analysis and computation. The methods used in this package are based on the following references: < https://en.wikipedia.org/wiki/Modified_Dietz_method>, < https://en.wikipedia.org/wiki/Time-weighted_return>.


fcl

R-CMD-check CRANstatus

A financial calculator written in Rust. It provides simple calculations for bond YTM, Duration, etc.

Installation

You’ll need the rust toolchain to compile this package from the source.

Example

library(fcl)
## basic example code
bond <- fixed_bond(
  value_date = 210101,
  mty_date = c(250101, 300201),
  redem_value = 100,
  cpn_rate = c(0.05, 0.03),
  cpn_freq = c(0, 1)
)
bond$ytm_dur(
  ref_date = c(220101, 220201),
  clean_price = 100
)
#>          YTM     MACD     MODD
#> 1 0.04552728 3.000000 2.869366
#> 2 0.02999755 7.212793 7.002728
bond$cf(
  ref_date = c(220101, 220131)
)
#>    ID       DATE     COUPON REDEM
#> 1   1 2025-01-01 20.0000000   100
#> 2   2 2023-01-01  3.0000000     0
#> 3   2 2024-01-01  3.0000000     0
#> 4   2 2025-01-01  3.0000000     0
#> 5   2 2026-01-01  3.0000000     0
#> 6   2 2027-01-01  3.0000000     0
#> 7   2 2028-01-01  3.0000000     0
#> 8   2 2029-01-01  3.0000000     0
#> 9   2 2030-01-01  3.0000000     0
#> 10  2 2030-02-01  0.2547945   100

rtn <- make_rtn(date = c(210101, 210105, 210110), mv = c(100, 123, 140), pl = c(0, 3, 7))
rtn$twrr_cr(210102, 210110)
#>               TWRR_CR
#> 2021-01-02 0.00000000
#> 2021-01-03 0.00000000
#> 2021-01-04 0.00000000
#> 2021-01-05 0.02500000
#> 2021-01-06 0.02500000
#> 2021-01-07 0.02500000
#> 2021-01-08 0.02500000
#> 2021-01-09 0.02500000
#> 2021-01-10 0.07894737
rtn$twrr_dr(210102, 210110)
#>               TWRR_DR
#> 2021-01-02 0.00000000
#> 2021-01-03 0.00000000
#> 2021-01-04 0.00000000
#> 2021-01-05 0.02500000
#> 2021-01-06 0.00000000
#> 2021-01-07 0.00000000
#> 2021-01-08 0.00000000
#> 2021-01-09 0.00000000
#> 2021-01-10 0.05263158
rtn$dietz(210102, 210110)
#>                 DIETZ
#> 2021-01-02 0.00000000
#> 2021-01-03 0.00000000
#> 2021-01-04 0.00000000
#> 2021-01-05 0.02857143
#> 2021-01-06 0.02777778
#> 2021-01-07 0.02727273
#> 2021-01-08 0.02692308
#> 2021-01-09 0.02666667
#> 2021-01-10 0.08737864
rtn$dietz_avc(210102, 210110)
#>            DIETZ_AVC
#> 2021-01-02  100.0000
#> 2021-01-03  100.0000
#> 2021-01-04  100.0000
#> 2021-01-05  105.0000
#> 2021-01-06  108.0000
#> 2021-01-07  110.0000
#> 2021-01-08  111.4286
#> 2021-01-09  112.5000
#> 2021-01-10  114.4444

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("fcl")

0.1.6 by Xianying Tan, 2 days ago


https://github.com/shrektan/fcl, https://shrektan.github.io/fcl/


Report a bug at https://github.com/shrektan/fcl/issues


Browse source code at https://github.com/cran/fcl


Authors: Xianying Tan [aut, cre] (ORCID: , Raymon Mina [ctb] (find_root.rs , xirr.rs) , The authors of the dependency Rust crates [ctb] (see inst/AUTHORS file for details)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports xts, ymd

Suggests testthat

System requirements: Cargo (Rust's package manager), rustc (>= 1.71.0)


See at CRAN