目前正在使用以下行:
library(quantmod)
library(pedquant)
option_chain<-function(ticker,exp){
view_window <- function(dfr, var, x, pm){
idx <- which(abs(dfr[, var]-x) == min(abs(dfr[, var] - x)))
return(dfr[(idx - pm) : (idx + pm), ])
}
options<-getOptionChain(ticker,exp)
call_filter<-options$calls[,c("Strike","Last","Vol")]
put_filter<-options$puts[,c("Strike","Last","Vol")]
ticker_price<-md_stock(ticker,type="real")
price<-ticker_price$close
call<-view_window(dfr=call_filter,
var="Strike",
x=price,
pm=5)
put<-view_window(dfr=put_filter,
var="Strike",
x=price,
pm=5)
colnames(call)<-c('Option Strike',"Call Price","Call Volume")
colnames(put)<-c('Option Strike',"Put Price","Put Volume")
print(ticker_price$symbol)
print(ticker_price$time)
print(price)
print(call)
print(put)
}
ticker<-"BABA"
exp="2023-06-30"
option_chain(ticker,exp)
Option Strike Call Price Call Volume
18 81 5.40 3
19 82 4.56 13
20 83 3.47 131
21 84 2.81 251
22 85 2.16 1243
23 86 1.67 4837
24 87 1.23 3685
25 88 0.90 3885
26 89 0.63 4531
27 90 0.47 13354
28 91 0.33 1061
Option Strike Put Price Put Volume
25 81 0.16 412
26 82 0.30 996
27 83 0.45 1353
28 84 0.71 723
29 85 1.06 809
30 86 1.60 806
31 87 2.18 142
32 88 2.83 58
33 89 3.60 119
34 90 4.65 29
35 91 5.35 6
想问一下,如果我想把格式改成附件中的图片,有没有办法?万分感谢。
我想做的只是重新排列该栏,并删除其中一栏,即期权执行栏。
1条答案
按热度按时间tkclm6bt1#
您可以在代码末尾使用select
非法列名需要反勾(列名中有空格)