我在R中安装了一个名为fExoticOptions
使用该软件包中的函数,我发现S的值(现货价格)的StandardBarrierOption
值为90到110
> S = 90:110
> S
[1] 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
这就是我得到的......但是我无法使用
制作图表plot(Value, S)
据我所知,Value和S的长度不同。值的长度为1,而S的长度为20.
如何解决此问题以制作值与S的图表
library(fExoticOptions)
Value <- StandardBarrierOption ('cuo', S, 0, 120, 90, 1, 0.01, 0.02, 0.1, title = NULL, description = NULL)
> plot(Value, S)
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
> Value
Title:
Standard Barrier Option
Call:
StandardBarrierOption(TypeFlag = "cuo", S = 90:120, X = 0, H = 120,
K = 90, Time = 1, r = 0.01, b = 0.02, sigma = 0.1, title = NULL,
description = NULL)
Parameters:
Value:
TypeFlag cuo
S1 90
S2 91
S3 92
S4 93
S5 94
S6 95
S7 96
S8 97
S9 98
S10 99
S11 100
S12 101
S13 102
S14 103
S15 104
S16 105
S17 106
S18 107
S19 108
S20 109
S21 110
S22 111
S23 112
S24 113
S25 114
S26 115
S27 116
S28 117
S29 118
S30 119
S31 120
X 0
H 120
K 90
Time 1
r 0.01
b 0.02
sigma 0.1
Option Price:
90.72108 91.6598 92.57593 93.46411 94.31832 95.13186 95.89745 96.60739 97.25371 97.82838 98.32356 98.73186 99.0466 99.26214 99.37406 99.37948 99.2772 99.06784 98.75399 98.34013 97.83269 97.23984 96.57139 95.83852 95.05354 94.22956 93.38018 92.51917 91.66016 90.8163 90
答案 0 :(得分:0)
我宁愿使用循环或lapply / sapply函数。给定每次迭代,我将存储价格,最后绘制期权价格与现货价格。
S_seq <- 80:120
Value_f <- function(S) StandardBarrierOption ('cuo', S, 0, 120, 90, 1, 0.01,
0.02, 0.1, title = NULL, description = NULL)
Value_seq <- lapply(S_seq,Value_f)
Value_seq <- sapply(Value_seq, function(x) x@price)
plot(Value_seq~S_seq,pch = 20)
lines(predict(loess(Value_seq~S_seq))~S_seq,col = 2)