Index Investing: From Theory to Practice · Dr MAI Huu Minh, TRAN Phan Bao Ngoc & HUYNH Nguyen Quoc BuuChapter 15 of 37 · Module 4: Build and test
CHAPTER 15

An Index Engine in R

From data frames to a reusable, tested index calculator
Opening question

“My Excel index works for five stocks and ten days. What happens when I need fifty stocks, eight years and eight indexes — and a colleague asks me to prove the numbers are right?”

In this chapter
🔒

This chapter is in the full book

Chapter 1 is free to read online. The full text of chapter 15 — with its tables, figures, worked examples and practice lab — is available in the complete edition of Index Investing: From Theory to Practice (Volume 1, NXW Investment Library).

Read Chapter 1 freeGet the full book — [email protected]

Sections of this chapter

15.1 From spreadsheet to script
15.2 The engine at a glance
15.3 Data structures: think long, calculate wide
15.4 Weights and index shares
15.5 The rebalancing schedule
15.6 calc_index(): divisor, price and total return
15.7 Performance and risk statistics
15.8 Testing the engine with testthat
15.9 From numbers to charts and a dashboard
← Chapter 14: Building Your First Index in ExcelChapter 16: Back-Testing Without Fooling Yourself →