Title: A Financial Calculator
Version: 0.1.4
Maintainer: Xianying Tan <shrektan@126.com>
Description: 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.
URL: https://github.com/shrektan/fcl, https://shrektan.github.io/fcl/
BugReports: https://github.com/shrektan/fcl/issues
SystemRequirements: Cargo (Rust's package manager), rustc
Biarch: true
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
Suggests: testthat (≥ 3.0.0)
Imports: xts, ymd
Config/testthat/edition: 3
Config/rextendr/version: 0.3.1.9001
Depends: R (≥ 4.2)
NeedsCompilation: yes
Packaged: 2025-04-15 08:10:12 UTC; shrektan
Author: Xianying Tan ORCID iD [aut, cre], Raymon Mina [ctb] (find_root.rs, xirr.rs), The authors of the dependency Rust crates [ctb] (see inst/AUTHORS file for details)
Repository: CRAN
Date/Publication: 2025-04-15 08:20:02 UTC

Create Fixed Bond Object

Description

Create Fixed Bond Object

Usage

fixed_bond(value_date, mty_date, redem_value, cpn_rate, cpn_freq)

Arguments

value_date, mty_date

the value and maturity date of the bond

redem_value, cpn_rate, cpn_freq

the redemption value, coupon rate and coupon frequency of the bond. Note that the frequency can only be one of 1, 2, 4, 0 (pay at mature)

Value

it returns an environment containing the following objects:

Note

Examples

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
)
bond$cf(
  ref_date = c(220101, 220131)
)

Create a Return Object

Description

By providing a "group" (ids) of dates, mvs and pls, calucating the Time-weighted Rate of Return (TWRR) or Modified Dietz Rate of Return (DIETZ).

Usage

make_rtn(date, mv, pl, id = 1L)

Arguments

date

a Date vector, the reference date of each row

mv, pl

a double vector, the market value and the 'PnL' (Profit and Loss) of each day

id

an integer vector, the ID of each row belongs to

Value

A list of functions, with signature of from, to and id, all of which are only allowed to accept a scalar. They all return an xts object with one column.

Cash flow handling

Note

All the input vector must be 1 or the same length.

References

Modified Dietz Method: https://en.wikipedia.org/wiki/Modified_Dietz_method

Time weighed Return: https://en.wikipedia.org/wiki/Time-weighted_return

Examples

rtn <- make_rtn(date = c(210101, 210105, 210110), mv = c(100, 123, 140), pl = c(0, 3, 7))
rtn$twrr_cr(210102, 210110)
rtn$twrr_dr(210102, 210110)
rtn$dietz(210102, 210110)
rtn$dietz_avc(210102, 210110)