Title: | 'Rcpp' Bindings to 'FastAD' Auto-Differentiation |
---|---|

Description: | The header-only 'C++' template library 'FastAD' for automatic differentiation <https://github.com/JamesYang007/FastAD> is provided by this package, along with a few illustrative examples that can all be called from R. |

Authors: | Dirk Eddelbuettel [aut, cre] , James Yang [aut] |

Maintainer: | Dirk Eddelbuettel <[email protected]> |

License: | GPL (>= 2) |

Version: | 0.0.2 |

Built: | 2024-06-21 05:15:25 UTC |

Source: | https://github.com/eddelbuettel/rcppfastad |

- 'Rcpp' Bindings to 'FastAD' Auto-Differentiation
- Black-Scholes valuation and first derivatives via Automatic Differentiation
- Evaluate a squared-loss linear regression at a given parameter value
- Compute the value and derivate of a quadratic expression X' * Sigma * X

The header-only 'C++' template library 'FastAD' for automatic differentiation <https://github.com/JamesYang007/FastAD> is provided by this package, along with a few illustrative examples that can all be called from R.

Index of help topics:

RcppFastAD-package 'Rcpp' Bindings to 'FastAD' Auto-Differentiation black_scholes Black-Scholes valuation and first derivatives via Automatic Differentiation linear_regression Evaluate a squared-loss linear regression at a given parameter value quadratic_expression Compute the value and derivate of a quadratic expression X' * Sigma * X

Dirk Eddelbuettel <[email protected]>

Dirk Eddelbuettel [aut, cre] (<https://orcid.org/0000-0001-6419-907X>), James Yang [aut] (<https://orcid.org/0000-0002-0015-7812>)

This example illustrate how to use automatic differentiation to calculate the delte of a Black-Scholes call and put. It is based on the same example in the FastAD sources.

`black_scholes(spot = 105, strike = 100, vol = 5, r = 1.25/100, tau = 30/365)`

`black_scholes(spot = 105, strike = 100, vol = 5, r = 1.25/100, tau = 30/365)`

`spot` |
A double with the spot price, default is 105 as in Boost example |

`strike` |
A double with the strike price, default is 100 as in Boost example |

`vol` |
A double with the (annualized) volatility (in percent), default is 5 (for 500 per cent) as in Boost example |

`r` |
A double with the short-term risk-free rate, default is 0.0125 as in Boost example |

`tau` |
A double with the time to expiration (in fractional years), default is 30/365 as in Boost example |

A matrix with rows for the call and put variant, and columns for option value, delta and vega

`black_scholes()`

`black_scholes()`

Not that this function does not actually fit the model. Rather it evaluates the squared sum of residuals and ‘gradient’ of parameters.

`linear_regression(X, y, theta_hat, initial_lr = 1e-04, max_iter = 100L, tol = 1e-07)`

`linear_regression(X, y, theta_hat, initial_lr = 1e-04, max_iter = 100L, tol = 1e-07)`

`X` |
Matrix with independent explanatory variables |

`y` |
Vector with dependent variable |

`theta_hat` |
Vector with initial ‘guess’ of parameter values |

`initial_lr` |
[Optional] Scalar with initial step-size value, default is 1e-4 |

`max_iter` |
[Optional] Scalar with maximum number of iterations, default is 100 |

`tol` |
[Optional] Scalar with convergence tolerance, default is 1e-7 |

A list object with the ‘loss’, ‘theta’ (parameters), ‘gradient’ and ‘iter’ for iterations

`data(trees) # also used in help(lm) X <- as.matrix(cbind(const=1, trees[, c("Girth", "Height")])) y <- trees$Volume linear_regression(X, y, rep(0, 3), tol=1e-12) coef(lm(y ~ X - 1)) # for comparison`

`data(trees) # also used in help(lm) X <- as.matrix(cbind(const=1, trees[, c("Girth", "Height")])) y <- trees$Volume linear_regression(X, y, rep(0, 3), tol=1e-12) coef(lm(y ~ X - 1)) # for comparison`

Compute the value and derivate of a quadratic expression X' * Sigma * X

`quadratic_expression(X, Sigma)`

`quadratic_expression(X, Sigma)`

`X` |
A 2 element vector |

`Sigma` |
A 2 x 2 matrix |

A list with two elements for the expression evaluated for X and Sigma as well as

`X <- c(0.5, 0.6) S <- matrix(c(2, 3, 3, 6), 2, 2) quadratic_expression(X, S)`

`X <- c(0.5, 0.6) S <- matrix(c(2, 3, 3, 6), 2, 2) quadratic_expression(X, S)`