![](/img/trans.png)
[英]How to find the second derivative in R and while using newton's method with numerical derivation
[英]R - how do I find the second derivative of a numeric array
我有一個數字數據數組(發生時,按行使價組織的看漲期權價格)。
我想計算R中的第二個導數。
我能夠擬合平滑的曲線,例如
call.lo <- loess(mid ~ strike, df.x, model=T)
但是從那一刻開始到分化。
任何幫助表示贊賞,謝謝。
您是否需要離散的二階導數 ?
mid <- 1:100; strike <- (1:100)^3 + 2*(1:100)^2 + 1:100 + 5
deriv <- function(x, y) diff(y) / diff(x)
middle_pts <- function(x) x[-1] - diff(x) / 2
second_d <- deriv(middle_pts(mid), deriv(mid, strike))
smooth_second_d <- loess(second_d ~ midpts,
data.frame(second_d = second_d, midpts = middle_pts(middle_pts(mid))), model = T)
例:
plot(middle_pts(middle_pts(mid)), deriv(middle_pts(mid), deriv(mid, strike)))
我看到6x + 4
像預期的那樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.