class: center, middle, inverse, title-slide .title[ # 量化金融与金融编程 ] .subtitle[ ## L01 开课啦 📅 ] .author[ ###
曾永艺 ] .institute[ ### 厦门大学管理学院 ] .date[ ### 2023-09-15 ] --- 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/1033/1173.htm) .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> - _"a 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) 上现(2023-09-14)有 19877 个扩展 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, 2e"_}}](https://r4ds.hadley.nz/intro.html) ] --- -- .pull-left[ ### .red[ ☑ Start with [{{`tidyverse`}}](https://www.tidyverse.org/)] <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 学时/周 - 我:概要 + 出题 + 答疑 + 扩展 - 同学:听讲 + 练习 + 反馈 - .red.bold[课后 5 小时/周 .font60[起]] - 同学:预习 + 复习 + 作业 - 我:备课 + (在线)答疑解惑 ] -- .pull-right.font120[ .content-box-yellow.bold[ - 课程的成绩构成: - 考勤:5% - 课堂参与:15% - 个人作业/随堂小测:40% - 小组研究项目: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://posit.co/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 - Show command palette 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 # install.pacages("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: ExperimentalDesign #> Topic: Design of Experiments (DoE) & Analysis of Experimental Data #> Maintainer: Ulrike Groemping, Tyler Morgan-Wall #> Contact: ulrike.groemping@bht-berlin.de #> Version: 2023-04-05 #> Repository: https://cran.r-project.org #> Source: https://github.com/cran-task-views/ExperimentalDesign/ #> Packages: acebayes, agricolae*, agridat, AlgDesign*, ALTopt, asd, #> BatchExperiments, bcrm, BHH2, binseqtest, bioOED, #> blocksdesign, blockTools, BOIN, choiceDes, CombinS, #> conf.design*, crmPack, crossdes*, Crossover, dae, daewr, #> designmatch, desirability, desplot, dfcomb, dfcrm, dfmta, #> DiceDesign, DiceEval, DiceKriging, DiceView, docopulae, #> DoE.base*, DoE.MIParray, DoE.wrapper*, DoseFinding, #> dynaTree, easypower, EngrExpt, experiment, ez, FMC, #> FrF2*, FrF2.catlg128, GAD, geospt, GroupSeq, gsDesign, #> ibd, ICAOD, idefix, JMdesign, lhs, MAMS, MaxPro, #> MBHdesign, minimalRSD, minimaxdesign, mixexp, mkssd, #> mxkssd, OBsMD, odr, OPDOE, optbdmaeAT, OptimalDesign, #> OptimaRegion, optrcdmaeAT, osDesign, PBIBD, PGM2, #> ph2bayes, ph2bye, pid, pipe.design, plgp, PopED, #> powerbydesign, powerGWASinteraction, PwrGSD, #> RcmdrPlugin.DoE, rodd, RPPairwiseDesign, rsm*, rsurface, #> SensoMineR, seqDesign, sFFLHD, simrel, skpr*, SLHD, SOAs, #> soptdmaeA, sp23design, ssize.fdr, ssizeRNA, support.CEs, #> TEQR, tgp, ThreeArmedTrials, unrepx, vdg #> (* = core package) ``` ] --- ### >> 网络社区 -- - .font130.bold[有问题就问 [![](imgs/bing.png)](https://cn.bing.com/) 或者直接上 [![](imgs/StackOverflow.svg)](https://stackoverflow.com/questions/tagged/r)] -- - .font130.bold[登录 [![](imgs/logo-posit.svg)](https://www.posit.co/),关注] + .font110[Products 栏目下的 [{{Open Source}}](https://posit.co/products/open-source/),特别是其中的 [{{R Packages}}](https://posit.co/products/open-source/rpackages/)] + .font110[Learn & Support 栏目下的 [{{Resources}}](https://posit.co/resources/),包括 [{{Blogs}}](https://posit.co/blog/)、[{{Videos}}](https://posit.co/resources/videos/) 和 [{{Cheatsheets}}](https://posit.co/resources/cheatsheets/)] + .font110[[{{Posit Community}}](https://community.rstudio.com/)] -- - .font130.bold[订阅 [![](imgs/R-bloggers.svg)](https://www.r-bloggers.com/),和 R 圈保持同步!.font120[👬]] -- <br> <hr color='#f00' size='1px' width='92%' align='center'> - .font130.bold[登录 [![](imgs/cos.png)](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[ 🕐 明确是否选修这门课程 - 若确定不选,请尽快在 .bold[[{{厦门大学教学服务平台}}](https://jw.xmu.edu.cn/new/index.html)] 上提出退课(申请) - 若确定选修本门课程,请于2023年9月17日24:00前通过 .bold[[{{坚果云链接}}](https://send2me.cn/5hUS5QCM/T0yehXZAbqqzlw)] 回答几道问题 ] -- <hr> .font130[ 🕑 初步了解 RStudio 的工作界面,并大致浏览下 .bold[[{{rstudio-IDE-cheatsheet}}](docs/rstudio-IDE-cheatsheet.pdf)] 🕒 在 RStudio 命令窗口中键入 `help(mean)` 和 `help(files)`,了解 R 帮助文档的整体结构 🕓 到前面课件中提到的那些 .bold[[{{网络社区}}](L01_Introduction.html#53)] 随意逛逛 ] -- <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) 赋能!**_]