[問題] Shiny上做平行運算(rugarch)

看板R_Language作者 (日日夜夜)時間10年前 (2015/12/19 11:42), 10年前編輯推噓2(2036)
留言38則, 2人參與, 最新討論串1/1
[問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) 效能諮詢(我想讓R 跑更快) [軟體熟悉度]: 入門(寫過其他程式,只是對語法不熟悉) [問題敘述]: 最近在用rugarch pkg中的ugarchroll做模型回測 是用過去1000天的time window為建模樣本 預測隔天(t+1)的波動度 每天都會重新fit一個新的模型 圖示如下 T daily returns: |---------|--|--------| 1 t t+1 T 1000 daily returns to fit AR(1)-GARCH(1,1): |-----------| t-999 t 1-step forecast: |---| t t+1 圖如果不好理解我再做修改 假設某指數有10000天日報酬率 每天用過去1000天的moving window做1-step forecast 就會有9900筆預測值 但可能是因為這樣就要重新fit 9900次AR(1)-GARCH(1,1) 所以跑很慢 但ugarchroll裡有一個參數可以設cluster 所以我參考這個網站裡的方法: http://unstarched.net/2012/12/26/rolling-garch-forecasts/ 在本機上跑是ok的 用RStudio runApp也沒問題 速度大概快了3~4倍 但一發布到Shiny Server上就直接斷掉(網頁變成灰色) 想請問是什麼原因 或是有沒有什麼建議的替代方法 現在沒加cluster的情況下 要跑快5分鐘... [程式範例]: Server部分比較精簡 :http://pastie.org/10641054 cluster部分在server的backtest最後幾行 目前是可執行狀況 只是因為server有省略一些 所以基本上跑不出圖 若需要完整版code我再提供 沒有加cluster部分會如下網址的輸出 http://naturalsmen.shinyapps.io/shinyTry 加了cluster後 切到Backtesting頁籤會直接灰屏... 現在只是跑比較久 問題主要是「在shiny上加快ugarchroll的處理速度」 怕講太多背景會模糊掉焦點@@ 如果有需要補充什麼再請告知 謝謝各位大大<(_ _)> PS. 我一個禮拜後可能會把shiny先關掉 因為免費帳戶一個月有時數限制... 怕直接被耗光囧 [環境敘述]: R version 3.2.1 (2015-06-18) Platform: i386-w64-mingw32/i386 (32-bit) Running under: Windows 8 x64 (build 9200) locale: [1] LC_COLLATE=Chinese (Traditional)_Taiwan.950 LC_CTYPE=Chinese (Traditional )_ [3] LC_MONETARY=Chinese (Traditional)_Taiwan.950 LC_NUMERIC=C [5] LC_TIME=Chinese (Traditional)_Taiwan.950 attached base packages: [1] parallel stats graphics grDevices utils datasets methods base other attached packages: [1] xtable_1.7-4 rugarch_1.3-6 fExtremes_3010.81 fTrading_3010.78 [5] fGarch_3010.82 fBasics_3011.87 timeSeries_3012.99 timeDate_3012.10 0 [9] quantmod_0.4-5 TTR_0.23-0 Quandl_2.7.0 xts_0.9-7 [13] zoo_1.7-12 shiny_0.12.2 loaded via a namespace (and not attached): [1] codetools_0.2-11 digest_0.6.8 htmltools_0.2.6 [4] R6_2.1.0 SkewHyperbolic_0.3-2 expm_0.999-0 [7] DistributionUtils_0.5-1 Rsolnp_1.15 grid_3.2.1 [10] stringr_1.0.0 numDeriv_2014.2-1 httr_1.0.0 [13] GeneralizedHyperbolic_0.8-1 rgl_0.95.1429 httpuv_1.3.3 [16] lattice_0.20-31 mime_0.3 Matrix_1.2-1 [19] KernSmooth_2.23-14 rstudioapi_0.3.1 jsonlite_0.9.16 [22] rsconnect_0.4.1.4 multicool_0.1-9 spd_2.0-1 [25] stringi_0.5-5 magrittr_1.5 tools_3.2.1 [28] mvtnorm_1.0-3 truncnorm_1.0-7 ks_1.10.0 [31] nloptr_1.0.4 Rcpp_0.12.2 misc3d_0.8-4 [關鍵字]: shiny, parallel, rugarch -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.136.217 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1450496557.A.FB5.html

12/19 11:47, , 1F
補充:灰屏沒有顯示任何警告或錯誤訊息
12/19 11:47, 1F

12/19 11:57, , 2F
啊範例程式的ugarchroll忘了加cluster進去 晚點修改
12/19 11:57, 2F

12/19 11:57, , 3F
抱歉
12/19 11:57, 3F

12/19 13:18, , 4F
and what you mean "data = -data()$r" ?
12/19 13:18, 4F

12/19 13:19, , 5F
Igot "Error in -data()$r : invalid argument to unary"
12/19 13:19, 5F

12/19 14:10, , 6F
cywhale: data is the DAX index loaded from 'quand
12/19 14:10, 6F

12/19 14:10, , 7F
l' and r is the daily log return calculated from
12/19 14:10, 7F

12/19 14:10, , 8F
the DAX data, containing Date, Open Price, Close
12/19 14:10, 8F

12/19 14:10, , 9F
Price, and so on. i put them in the reactive var
12/19 14:10, 9F

12/19 14:10, , 10F
iable 'data', i.e., i make a list to contain the
12/19 14:10, 10F

12/19 14:10, , 11F
variables i need in 'data'. In my computer, i ca
12/19 14:10, 11F

12/19 14:10, , 12F
n use data()$r to call the log return in the reac
12/19 14:10, 12F

12/19 14:10, , 13F
tive variable 'data'. The negative sign represent
12/19 14:10, 13F

12/19 14:10, , 14F
s the 'negative' log return. i'll check it later,
12/19 14:10, 14F

12/19 14:10, , 15F
and thanks for replying:)
12/19 14:10, 15F
※ 編輯: naturalsmen (42.70.107.229), 12/19/2015 15:00:33

12/19 16:36, , 16F
I have just checked the problem and the data()$r
12/19 16:36, 16F

12/19 16:36, , 17F
works fine as usual. Maybe u can re-confirm if t
12/19 16:36, 17F

12/19 16:36, , 18F
he quandl function works. Many thanks:)
12/19 16:36, 18F

12/19 17:30, , 19F
ya.. the issue is my fault when try and
12/19 17:30, 19F

12/19 17:31, , 20F
It' ok to use cluster and get result on shiny-server
12/19 17:31, 20F

12/19 17:32, , 21F
on linux, but I got troubles to deploy shinyapps.io
12/19 17:32, 21F

12/19 17:32, , 22F
At least, I have no error runing code on shiny-server
12/19 17:32, 22F

12/19 17:34, , 23F
(and also no error on local computer). What message
12/19 17:34, 23F

12/19 17:35, , 24F
when your app crash and press F-12 & select "console"
12/19 17:35, 24F

12/19 21:02, , 25F
Maybe I mixed up the definition of the "shiny ser
12/19 21:02, 25F

12/19 21:02, , 26F
ver" and the "shiny apps.io", sorry about that. W
12/19 21:02, 26F

12/19 21:02, , 27F
hat I mean "shiny server" in the article is the "
12/19 21:02, 27F

12/19 21:02, , 28F
shiny apps.io". I'll fix it as soon as possible.
12/19 21:02, 28F

12/19 21:02, , 29F
I can run my app locally but run into trouble on
12/19 21:02, 29F

12/19 21:02, , 30F
shinyapps.io. Anyways, thanks a lot:)
12/19 21:02, 30F

12/19 21:04, , 31F
I may give it a shot using your method to see if
12/19 21:04, 31F

12/19 21:04, , 32F
I can get any warning message.
12/19 21:04, 32F
hey, thanks for the advice. i just got these messages: http://imgur.com/8zYVcMo
※ 編輯: naturalsmen (114.43.220.140), 12/19/2015 22:13:29

12/19 23:17, , 33F
12/19 23:17, 33F

12/19 23:18, , 34F
but only no error if I change code to:
12/19 23:18, 34F

12/19 23:20, , 35F
cluster = makePSOCKcluster(4). If using (10),it crash
12/19 23:20, 35F

12/19 23:26, , 36F
and got error: server responded with a status of 500
12/19 23:26, 36F

12/20 00:03, , 37F
so maybe it's due to the constraints as a free
12/20 00:03, 37F

12/20 00:04, , 38F
user?
12/20 00:04, 38F
文章代碼(AID): #1MTD8j-r (R_Language)
文章代碼(AID): #1MTD8j-r (R_Language)