Open your PDF side-by-side with RStudio. Never copy-paste; type every command. Muscle memory is crucial.
This is the go-to PDF for risk managers. Danielsson provides the complete R code to calculate: