class: center, middle, inverse, title-slide .title[ # 量化金融与金融编程 ] .subtitle[ ## L01 开课啦 📅 ] .author[ ###
曾永艺 ] .institute[ ### 厦门大学管理学院 ] .date[ ### 2022-09-16 ] --- class: hide_logo
.pull-left.center.font300[ <br> .font300[📚] ] -- .pull-right[ <br> - ## 课程简介 - ### 量化金融与金融编程 📈 - ### 学好这门课的正确方式 🎯 - ### 谁该选这门课?🙋 <br> - ## **RStudio** 概览 <br> - ## 😱 🆘 🤩 ] --- class: inverse, center, middle # 1. 课程简介 --- background-image: url(imgs/zhihu.png) background-size: 15em background-position: 10% 50% ### [{{知乎神回复}}](https://www.leiphone.com/news/201811/MQyVoVQS6ldoil0o.html) -- .pull-right[ ## **Q:**考上好大学学 IT 是不是当今中国穷人家孩子晋级中产唯一的出路? ] -- .pull-right[ ## .red[**A:**对,就4条路:写代码;搞金融;在代码圈搞金融;在金融圈写代码] ] --- ### 😍 [{{清华大学计算机与金融双学士学位}}](https://www.admissions.tsinghua.edu.cn/info/1005/107) .pull-left[ <img src="imgs/THU+.jpg" height="580" style="display: block; margin: auto;" /> ] -- .pull-right.font200[ <br><br><br><br> [{{“状元收割神器”}}](https://www.zhihu.com/question/407565500) 😱 ] --- background-image: url(imgs/QF.jpg) background-size: 15em background-position: 92% 92% ## 1.1 .red.bold[量化金融 ].gray[与 金融编程] .Large[ - Paul Wilmott著,郑振龙 等译,机械工业出版社,2015年 ] -- .Large.red[ - 83章,1200+页! - .bold[第一部分] 数理与金融基础、衍生品基本理论、风险与收益 - .bold[第二部分] 奇异合约及路径依赖 - .bold[第三部分] 固定收益的建模和衍生品 - .bold[第四部分] 信用风险 - .bold[第五部分] 进阶主题 ] -- .font200[🚀 🚪] --- ## 1.1 .gray[量化金融 与 ].red.bold[~~金融编程~~ R 语言编程] -- .pull-left.red.bold.large[ <a href="https://www.r-project.org/" target="_blank"> <img src="imgs/logo-R.svg" width=125 style="display:block; margin:auto; float:left"> </a> <br><br><br> - _"free software environment for ..."_ - _"... statistical computing and graphics"_ ] -- .pull-right.bold.large[ - 支持 Windows、MacOS、Unix 等众多主流操作系统 - 功能强大,“几乎”应有尽有 - [{{CRAN}}](https://cran.r-project.org/web/packages/index.html) 上现有 18648 个扩展 R 包! - [{{github}}](https://www.github.com) 上也托管着大量的 R 包 - 学习曲线适中 - 良好的编程社区支持 - 免费、开源! ] --- <img src="imgs/ds4b_rating.png" width="60%" style="display: block; margin: auto;" /> .footnote.right.font80.bold[[{{_Six Reasons To Learn R For Business_}}](https://www.business-science.io/business/2020/12/17/six-reasons-to-use-R-for-business-2021.html)] --- <a href="https://tiobe.com/tiobe-index/" target="_blank"> <img src="imgs/logo-tiobe.svg" width="15%" style="display:block; margin:auto; float:left"> </a> <img src="imgs/R_tiobe.png" width="70%" style="display: block; margin: auto;" /> --- layout: true ## 1.2 学好这门课的正确方式 --- -- .pull-left-70[ <img src="L01_Introduction_files/figure-html/unnamed-chunk-4-1.png" width="72%" style="display: block; margin: auto;" /> ] .pull-right-30.left.font500[ <br> 🤔 ] --- ### .red[ ☑ 掌握科学的**workflow**,提升效率] <br> <img src="imgs/workflow.png" width="90%" style="display: block; margin: auto;" /> .pull-right.center.font80.red[ [{{Workflow from _" R for Data Science"_}}](http://r4ds.had.co.nz/introduction.html) ] --- -- .pull-left[ ### .red[ ☑ Start with `tidyverse`] <img src="imgs/logo-tidyverse.svg" width="50%" style="display: block; margin: auto;" /> <img src="imgs/tidyverse.png" width="100%" style="display: block; margin: auto;" /> ] .pull-right[ ### .red[ ☑ [{{R Markdown}}](https://rmarkdown.rstudio.com/) | [{{Quarto}}](https://quarto.org/)] .font140[ - 将(
、
...)代码(及其动态计算结果,如图表等)和
文字汇编成文档,并可转化为多种格式的输出 <br> -> efficient and _reproducible research_ ] <br> ### .red[ ☑ Stay in <img src="imgs/RStudio-Logo-flat.svg" width="50%" style="display:inline; vertical-align:middle;">] ] --- -- ### .red[ ☑ **task**导向,掌握核心
📦] -- .pull-left.Large[ - .bold[专题任务] - 数据搜集-整理-可视化 - 投资组合优化 - 资产定价模型 - 衍生品定价 - 量化交易策略 - 实证研究文献复刻 ... ] -- .pull-right.Large[ - .bold[[{{CRAN Task views}}](https://cran.r-project.org/web/views/)] - Econometrics - Finance - TimeSeries - Optimization - MachineLearning - Graphics - ReproducibleResearch ... ] --- ### .red[ ☑ **practice** makes perfect!]  🏋 ➡️ 💯! .font130[ > .font110[纸上得来终觉浅,绝知此事要躬行。] > >       ——陆游·冬夜读书示子律 ] -- .pull-left.font120[ - 课上 2 学时/周 - 我:围绕工作流程讲解核心 R 包 - 同学:听讲 + 练习 + 反馈 - .red.bold[课后 4 小时/周 .font60[起]] - 同学:课前预习 + 课后作业 - 我:(在线)答疑解惑 ] -- .pull-right.font120[ .content-box-yellow.bold[ - 课程的成绩构成: - 考勤+课堂参与:10% - 个人作业/随堂小测:50% - 小组研究项目:40% <sup>.red[*]</sup> .font80.right.red[\* 每个小组 ~ 4 名同学 ] ] ] --- layout: false background-image: url(imgs/hands-up.jpg) background-size: cover ## 1.3 谁该选这门课? -- .content-box-yellow[ .red.font140.bold[☑ 想继续读研深造的同学] ] -- .content-box-yellow[ .red.font140.bold[☑ 毕业后想和金融(🤑)、数据打交道的同学] ] -- .content-box-yellow[ .red.font140.bold[☑ 想更好理解金工、固收、金融数学、风险管理等专业课程的同学] ] -- .content-box-yellow[ .red.font140.bold[☑ 希望能学习并掌握酷炫好玩新工具和新“姿势”的同学] ] -- .content-box-yellow[ .red.font140.bold[☑ 其他 ……] ] --- class: inverse, center, middle # 2. **RStudio** 概览 ### .bold.red[< R 语言的赋能工具!>] --- layout: false background-image: url(imgs/RGui-RS.png) background-size: 48em background-position: 50% 70% ### >> RStudio 为 R 赋能 .tiny[[{{rstudio-IDE-cheatsheet}}](https://www.rstudio.com/resources/cheatsheets/) [{{本地pdf版本}}](docs/rstudio-IDE-cheatsheet.pdf)] --- ### >> RStudio 快捷键 .code110.bold[ ``` - Search command history Ctrl+↑ - Interrupt current command Esc - Clear console Ctrl+L - Restart R Session Ctrl+Shift+F10 - Run current line/selection Ctrl+Enter - Attempt completion Tab or Ctrl+Space - Insert <- Alt+- - Insert %>% Ctrl+Shift+M - (Un)Comment lines Ctrl+Shift+C - Knit document (knitr) Ctrl+Shift+K - Insert chunk Ctrl+Alt+I - Run the current chunk Ctrl+Alt+C - Search shortcuts Ctrl+Shift+P - Keyboard shortcuts help Alt+Shift+K ``` ] --- ### >> RStudio's <br><br> <img src="imgs/showtime.jpg" width="72%" style="display: block; margin: auto;" /> --- class: inverse, center, middle # 3. SOS .font150[(_getting help_)] --- ### >> `help()` .code100[ ```r help(topic, package = NULL, lib.loc = NULL, verbose = getOption("verbose"), try.all.packages = getOption("help.try.all.packages"), help_type = getOption("help_type")) ``` ] -- .pull-left.code90[ ```r help(mean) # ?mean help("for") # ?"for" help(files) # ?files help(package = "fs") # package?fs #----------------------------------- example(topic, package = NULL, lib.loc = NULL, ...) vignette(topic, package = NULL, lib.loc = NULL, all = TRUE) browseVignettes(package = NULL, lib.loc = NULL, all = TRUE) ``` ] -- .pull-right[ <img src="imgs/help.png" width="85%" style="display: block; margin: auto;" /> ] --- ### >> `help.search()` & `RSiteSearch()` .code100[ ```r help.search(pattern, fields = c("alias", "concept", "title"), apropos, keyword, whatis, ignore.case = TRUE, package = NULL, lib.loc = NULL, help.db = getOption("help.db"), verbose = getOption("verbose"), rebuild = FALSE, agrep = NULL, use_UTF8 = FALSE, types = getOption("help.search.types")) ``` ] -- .code90[ ```r # Search for key words or phrases in help pages, vignettes or task views, # using the search engine at http://search.r-project.org and view them # in a web browser. RSiteSearch(string, restrict = c("functions", "descriptions", "news", "Rfunctions", "Rmanuals", "READMEs", "views", "vignettes"), format, sortby = c("score", "date:late", "date:early", "subject", "subject:descending", "size", "size:descending"), matchesPerPage = 20, words = c("all", "any")) ``` ] --- ### >> `sos::findFn()` & `packagefinder::fp()` .code90[ ```r # Search Contributed R Packages, Sort by Package # install.packages("sos") help(package = "sos") sos::findFn(string, maxPages = 100, sortby = NULL, verbose = 1, ...) ## ???string(maxPages) # Returns a data.frame from RSiteSearch(string, "functions") which can be # sorted and subsetted by user specifications and viewed in an HTML table. ``` ] -- .code90[ ```r # Comfortable Search for R Packages on CRAN # remotes::install_github("jsugarelli/packagefinder") help(package = "packagefinder") ``` ```r findPackage(keywords = NULL, query = NULL, mode = "or", case.sensitive = FALSE, always.sensitive = NULL, weights = c(2, 2, 1, 2), display = "viewer", results.longdesc = FALSE, limit.results = 15, silent = FALSE, index = NULL, advanced.ranking = TRUE, return.df = FALSE, clipboard = FALSE) ``` ] --- ### >> [{{CRAN Task views}}](https://cran.r-project.org/web/views/) .code100[ ```r # install.packages("ctv") ctv::available.views(repos = "https://cran.r-project.org")[[14]] ``` ``` #> CRAN Task View #> -------------- #> Name: Finance #> Topic: Empirical Finance #> Maintainer: Dirk Eddelbuettel #> Contact: Dirk.Eddelbuettel@R-project.org #> Version: 2022-08-26 #> Repository: https://cran.r-project.org #> Source: https://github.com/cran-task-views/Finance/ #> Packages: actuar, AmericanCallOpt, AssetCorr, backtest, bayesGARCH, #> BCC1997, BenfordTests, betategarch, bidask, bizdays, #> BLModel, bmgarch, bondAnalyst, BurStFin, BurStMisc, #> CADFtest, car, ChainLadder, copula, copulaData, credule, #> crseEventStudy, cvar, data.table, derivmkts, dlm, #> DOSPortfolio, Dowd, DriftBurstHypothesis, dse, DtD, dyn, #> dynlm, ESG, etrm, factorstochvol, fame, fAssets*, #> FatTailsR, fBasics*, fBonds*, fCopulae*, fExtremes*, #> FFdownload, fGarch*, fImport*, FinancialMath, FinAsym, #> finreportr, fixedincome, fmdates, fMultivar*, #> fNonlinear*, forecast, fPortfolio*, fracdiff, FRAPO, #> fRegression*, frenchdata, fTrading*, GARCHSK, garchx, #> GCPM, gets, GetTDData, ghyp, gmm, gogarch, greeks, GUIDE, #> HDShOP, highfrequency, IBrokers, ichimoku, InfoTrad, #> lgarch, lifecontingencies, lmForc, lmtest, longmemo, #> LSMonteCarlo, LSMRealOptions, markovchain, MarkowitzR, #> matchingMarkets, monobin, MSGARCH, mvtnorm, #> NetworkRiskMeasures, NFCP, nlme, NMOF, nvmix, #> obAnalytics, OptHedging, OptionPricing, pa, parma, pbo, #> PeerPerformance, PerformanceAnalytics*, #> PortfolioEffectHFT, PortfolioOptim, PortRisk, qrmdata, #> qrmtools, quantmod, ragtop, Rblpapi, Rcmdr, #> RcppQuantuccia, reinsureR, restimizeapi, Risk, #> riskParityPortfolio, RiskPortfolios, riskSimul, RM2006, #> rmgarch, RND, RQuantLib, RTL, rugarch*, sandwich, sde, #> SharpeR, Sim.DiffProc, simfinapi, stochvol, strand, #> strucchange, TAQMNGR, tidyquant, timeDate*, timeSeries*, #> timsac, tis, tsDyn, tseries*, tseriesChaos, TTR, tvm, #> ufRisk, urca*, vars, vrtest, wavelets, waveslim, #> wavethresh, XBRL, xts*, zoo* #> (* = core package) ``` ] --- ### >> 网络社区 -- - .font130.bold[有问题就问 [](https://cn.bing.com/) 或者直接上 [](https://stackoverflow.com/questions/tagged/r)] -- - .font130.bold[登录 [](https://www.rstudio.com/),关注] + Productions 栏目下的 [{{R Packages}}](https://rstudio.com/products/rpackages/) + Resources 栏目下的 [{{Webinas & Video}}](https://rstudio.com/resources/webinars/)、[{{Cheatsheets}}](https://rstudio.com/resources/cheatsheets/) 和 [{{R Views Blog}}](https://rviews.rstudio.com/) + 主页右上角链接 [{{Community}}](https://community.rstudio.com/) -- - .font130.bold[订阅 [](https://www.r-bloggers.com/),和 R 圈保持同步!.font120[👬]] -- <br> - .font130.bold[登录 [](https://cosx.org/categories/r语言)] --- ### >> QQ课程群 <br> <img src="imgs/TA.png" width="40%" style="display: block; margin: auto;" /> --- class: hide_logo background-image: url(imgs/logo-reprex.svg) background-size: 6% background-position: 95% 5% ### >> [{{**reprex** 包:Help Me Help You}}](https://reprex.tidyverse.org/) > .red[_Prepare Reproducible Example Code via the Clipboard_] <img src="imgs/reprex.gif" width="80%" style="display: block; margin: auto;" /> --- ### >> 领域 + R 书籍 <img src="imgs/r_books.png" width="98%" style="display: block; margin: auto;" /> --- class: inverse, center, middle # 课后作业 与 课前预习 --- <br> .font130[ 🕐 明确是否选修这门课程——若不选修,请于今天下午2点前在 .bold[[{{厦门大学教学服务平台}}](https://jw.xmu.edu.cn/new/index.html)] 上提出退课申请,我会在3点前完成审核 ] -- <hr> .font130[ 🕑 初步了解 RStudio 的工作界面,并大致浏览下 .bold[[{{rstudio-IDE-cheatsheet}}](docs/rstudio-IDE-cheatsheet.pdf)] 🕒 在 RStudio 命令窗口中键入 `help(mean)` 和 `help(files)`,了解 R 帮助文档的整体结构 🕓 到前面课件中提到的那些 .bold[[{{网络社区}}](L01_Introduction.html#53)] 随意逛逛 🕔 2022年9月18日22:00前通过 .bold[[{{坚果云链接}}](https://workspace.jianguoyun.com/inbox/collect/0d73b361ad7246849ea58ef2918c152b/submitv2)] 回答几道问题 ] -- <hr> .font130[ 🕔 完成课前预习(具体任务下周三前我会在 QQ 课程群上通知) ] --- class: center, middle, hide_logo background-image: url(imgs/xaringan.png) background-size: 12% background-position: 50% 40% <br><br><br><br><br><br><br> <hr color='#f00' size='2px' width='80%'> [//]: # (红色横线制作参考自https://github.com/pat-s/xaringan-metropolis) <!--- remark的两种注释方法参考自https://github.com/gnab/remark/wiki/Markdown#Comments --> <br> .Large.red[_**本网页版讲义的制作由 R 包 [{{`xaringan`}}](https://github.com/yihui/xaringan) 赋能!**_]