Set Global Options
knitr::opts_chunk$set(
dpi = 200,
warning = FALSE,
message = FALSE
)
Set Colors
Hex_Google_Blue <- '#4285F4'
Hex_Google_Red <- '#EA4335'
Hex_Google_Yellow <- '#FBBC05'
Hex_Google_Green <- '#34A853'
Load Relevant Libraries
library(tidyverse)
library(lubridate)
library(scales)
library(ggthemes)
library(quantmod)
library(rmarkdown)
Load Data
FXNAX <- read_rds('FXNAX.rds')
VBILX <- read_rds('VBILX.rds')
VUSTX <- read_rds('VUSTX.rds')
VFIAX <- read_rds('VFIAX.rds')
VIMAX <- read_rds('VIMAX.rds')
VSMAX <- read_rds('VSMAX.rds')
VGSLX <- read_rds('VGSLX.rds')
VBTLX <- read_rds('VBTLX.rds')
SP500 <- read_rds('SP500.rds')
Wrangle Data
Seven_Fund_Data <-
VBILX %>%
left_join(
FXNAX,
by = 'Date'
) %>%
left_join(
VUSTX,
by = 'Date'
) %>%
left_join(
VFIAX,
by = 'Date'
) %>%
left_join(
VIMAX,
by = 'Date'
) %>%
left_join(
VSMAX,
by = 'Date'
) %>%
left_join(
VGSLX,
by = 'Date'
) %>%
select(
Date,
FXNAX.Open,
VBILX.Open,
VUSTX.Open,
VFIAX.Open,
VIMAX.Open,
VSMAX.Open,
VGSLX.Open
) %>%
rename(
FXNAX_Price = FXNAX.Open,
VBILX_Price = VBILX.Open,
VUSTX_Price = VUSTX.Open,
VFIAX_Price = VFIAX.Open,
VIMAX_Price = VIMAX.Open,
VSMAX_Price = VSMAX.Open,
VGSLX_Price = VGSLX.Open
) %>%
filter(Date >= '2007-01-01') %>%
mutate(
Day = day(Date),
Month = month(Date),
Year = year(Date)
) %>%
group_by(Year, Month) %>%
slice(which.min(Day)) %>%
ungroup() %>%
select(
-Day,
-Month,
-Year
)
Seven_Fund_Data %>%
paged_table()
Two_Fund_Data <-
VFIAX %>%
left_join(
VBTLX,
by = 'Date'
) %>%
select(
Date,
VFIAX.Open,
VBTLX.Open
) %>%
rename(
VFIAX_Price = VFIAX.Open,
VBTLX_Price = VBTLX.Open
) %>%
mutate(
Day = day(Date),
Month = month(Date),
Year = year(Date)
) %>%
group_by(Year, Month) %>%
slice(which.min(Day)) %>%
ungroup() %>%
select(
-Day,
-Month,
-Year
)
Two_Fund_Data %>%
paged_table()
SP500_Data <-
SP500 %>%
select(
Date,
GSPC.Close
) %>%
rename(
SP500_Price = GSPC.Close
) %>%
mutate(
Day = day(Date),
Month = month(Date),
Year = year(Date)
) %>%
group_by(Year, Month) %>%
slice(which.min(Day)) %>%
ungroup() %>%
select(
-Day,
-Month,
-Year
)
SP500_Data %>%
paged_table()
Seven Fund No Rebalance
Start_Date_Input <- '2011-06-01'
End_Date_Input <- '2022-06-01'
Monthly_Contribution_Input <- 1000
FXNAX_Contribution <- Monthly_Contribution_Input * 0.15
VBILX_Contribution <- Monthly_Contribution_Input * 0.10
VUSTX_Contribution <- Monthly_Contribution_Input * 0.10
VFIAX_Contribution <- Monthly_Contribution_Input * 0.25
VIMAX_Contribution <- Monthly_Contribution_Input * 0.10
VSMAX_Contribution <- Monthly_Contribution_Input * 0.10
VGSLX_Contribution <- Monthly_Contribution_Input * 0.20
Seven_Fund_No_Rebalance <-
Seven_Fund_Data %>%
filter(
Date >= Start_Date_Input,
Date <= End_Date_Input
) %>%
mutate(
FXNAX_Shares_Bought = FXNAX_Contribution / FXNAX_Price,
FXNAX_Shares_Owned = cumsum(FXNAX_Shares_Bought),
FXNAX_Value = FXNAX_Price * FXNAX_Shares_Owned,
FXNAX_Profit = FXNAX_Value - (row_number() * FXNAX_Contribution),
VBILX_Shares_Bought = VBILX_Contribution / VBILX_Price,
VBILX_Shares_Owned = cumsum(VBILX_Shares_Bought),
VBILX_Value = VBILX_Price * VBILX_Shares_Owned,
VBILX_Profit = VBILX_Value - (row_number() * VBILX_Contribution),
VUSTX_Shares_Bought = VUSTX_Contribution / VUSTX_Price,
VUSTX_Shares_Owned = cumsum(VUSTX_Shares_Bought),
VUSTX_Value = VUSTX_Price * VUSTX_Shares_Owned,
VUSTX_Profit = VUSTX_Value - (row_number() * VUSTX_Contribution),
VFIAX_Shares_Bought = VFIAX_Contribution / VFIAX_Price,
VFIAX_Shares_Owned = cumsum(VFIAX_Shares_Bought),
VFIAX_Value = VFIAX_Price * VFIAX_Shares_Owned,
VFIAX_Profit = VFIAX_Value - (row_number() * VFIAX_Contribution),
VIMAX_Shares_Bought = VIMAX_Contribution / VIMAX_Price,
VIMAX_Shares_Owned = cumsum(VIMAX_Shares_Bought),
VIMAX_Value = VIMAX_Price * VIMAX_Shares_Owned,
VIMAX_Profit = VIMAX_Value - (row_number() * VIMAX_Contribution),
VSMAX_Shares_Bought = VSMAX_Contribution / VSMAX_Price,
VSMAX_Shares_Owned = cumsum(VSMAX_Shares_Bought),
VSMAX_Value = VSMAX_Price * VSMAX_Shares_Owned,
VSMAX_Profit = VSMAX_Value - (row_number() * VSMAX_Contribution),
VGSLX_Shares_Bought = VGSLX_Contribution / VGSLX_Price,
VGSLX_Shares_Owned = cumsum(VGSLX_Shares_Bought),
VGSLX_Value = VGSLX_Price * VGSLX_Shares_Owned,
VGSLX_Profit = VGSLX_Value - (row_number() * VGSLX_Contribution),
Total_Investment = row_number() * Monthly_Contribution_Input
) %>%
rowwise() %>%
mutate(
Total_Profit =
sum(FXNAX_Profit, VBILX_Profit ,VUSTX_Profit, VFIAX_Profit, VIMAX_Profit, VSMAX_Profit, VGSLX_Profit),
FXNAX_Allocation =
FXNAX_Value / sum(FXNAX_Value, VBILX_Value, VUSTX_Value, VFIAX_Value, VIMAX_Value, VSMAX_Value, VGSLX_Value),
VBILX_Allocation =
VBILX_Value / sum(FXNAX_Value, VBILX_Value, VUSTX_Value, VFIAX_Value, VIMAX_Value, VSMAX_Value, VGSLX_Value),
VUSTX_Allocation =
VUSTX_Value / sum(FXNAX_Value, VBILX_Value, VUSTX_Value, VFIAX_Value, VIMAX_Value, VSMAX_Value, VGSLX_Value),
VFIAX_Allocation =
VFIAX_Value / sum(FXNAX_Value, VBILX_Value, VUSTX_Value, VFIAX_Value, VIMAX_Value, VSMAX_Value, VGSLX_Value),
VIMAX_Allocation =
VIMAX_Value / sum(FXNAX_Value, VBILX_Value, VUSTX_Value, VFIAX_Value, VIMAX_Value, VSMAX_Value, VGSLX_Value),
VSMAX_Allocation =
VSMAX_Value / sum(FXNAX_Value, VBILX_Value, VUSTX_Value, VFIAX_Value, VIMAX_Value, VSMAX_Value, VGSLX_Value),
VGSLX_Allocation =
VGSLX_Value / sum(FXNAX_Value, VBILX_Value, VUSTX_Value, VFIAX_Value, VIMAX_Value, VSMAX_Value, VGSLX_Value)
)
Seven_Fund_No_Rebalance %>%
paged_table()
Seven Fund No Rebalance
Monthly_Contribution_Input <- 1000
FXNAX_Target_Allocation <- 0.15
VBILX_Target_Allocation <- 0.10
VUSTX_Target_Allocation <- 0.10
VFIAX_Target_Allocation <- 0.25
VIMAX_Target_Allocation <- 0.10
VSMAX_Target_Allocation <- 0.10
VGSLX_Target_Allocation <- 0.20
Seven_Fund_Rebalance <-
Seven_Fund_Data %>%
filter(
Date >= Start_Date_Input,
Date <= End_Date_Input
) %>%
mutate(
FXNAX_Shares_Bought = NA,
VBILX_Shares_Bought = NA,
VUSTX_Shares_Bought = NA,
VFIAX_Shares_Bought = NA,
VIMAX_Shares_Bought = NA,
VSMAX_Shares_Bought = NA,
VGSLX_Shares_Bought = NA,
FXNAX_Shares_Owned = NA,
VBILX_Shares_Owned = NA,
VUSTX_Shares_Owned = NA,
VFIAX_Shares_Owned = NA,
VIMAX_Shares_Owned = NA,
VSMAX_Shares_Owned = NA,
VGSLX_Shares_Owned = NA,
FXNAX_Value = NA,
VBILX_Value = NA,
VUSTX_Value = NA,
VFIAX_Value = NA,
VIMAX_Value = NA,
VSMAX_Value = NA,
VGSLX_Value = NA,
FXNAX_Allocation = NA,
VBILX_Allocation = NA,
VUSTX_Allocation = NA,
VFIAX_Allocation = NA,
VIMAX_Allocation = NA,
VSMAX_Allocation = NA,
VGSLX_Allocation = NA,
Low_Allocation = NA
)
# Shares Bought #
Seven_Fund_Rebalance$FXNAX_Shares_Bought[1] <-
(Monthly_Contribution_Input * FXNAX_Target_Allocation) / Seven_Fund_Rebalance$FXNAX_Price[1]
Seven_Fund_Rebalance$VBILX_Shares_Bought[1] <-
(Monthly_Contribution_Input * VBILX_Target_Allocation) / Seven_Fund_Rebalance$VBILX_Price[1]
Seven_Fund_Rebalance$VUSTX_Shares_Bought[1] <-
(Monthly_Contribution_Input * VUSTX_Target_Allocation) / Seven_Fund_Rebalance$VUSTX_Price[1]
Seven_Fund_Rebalance$VFIAX_Shares_Bought[1] <-
(Monthly_Contribution_Input * VFIAX_Target_Allocation) / Seven_Fund_Rebalance$VFIAX_Price[1]
Seven_Fund_Rebalance$VIMAX_Shares_Bought[1] <-
(Monthly_Contribution_Input * VIMAX_Target_Allocation) / Seven_Fund_Rebalance$VIMAX_Price[1]
Seven_Fund_Rebalance$VSMAX_Shares_Bought[1] <-
(Monthly_Contribution_Input * VSMAX_Target_Allocation) / Seven_Fund_Rebalance$VSMAX_Price[1]
Seven_Fund_Rebalance$VGSLX_Shares_Bought[1] <-
(Monthly_Contribution_Input * VGSLX_Target_Allocation) / Seven_Fund_Rebalance$VGSLX_Price[1]
# Shares Owned #
Seven_Fund_Rebalance$FXNAX_Shares_Owned[1] <- Seven_Fund_Rebalance$FXNAX_Shares_Bought[1]
Seven_Fund_Rebalance$VBILX_Shares_Owned[1] <- Seven_Fund_Rebalance$VBILX_Shares_Bought[1]
Seven_Fund_Rebalance$VUSTX_Shares_Owned[1] <- Seven_Fund_Rebalance$VUSTX_Shares_Bought[1]
Seven_Fund_Rebalance$VFIAX_Shares_Owned[1] <- Seven_Fund_Rebalance$VFIAX_Shares_Bought[1]
Seven_Fund_Rebalance$VIMAX_Shares_Owned[1] <- Seven_Fund_Rebalance$VIMAX_Shares_Bought[1]
Seven_Fund_Rebalance$VSMAX_Shares_Owned[1] <- Seven_Fund_Rebalance$VSMAX_Shares_Bought[1]
Seven_Fund_Rebalance$VGSLX_Shares_Owned[1] <- Seven_Fund_Rebalance$VGSLX_Shares_Bought[1]
# Value #
Seven_Fund_Rebalance$FXNAX_Value[1] <- Seven_Fund_Rebalance$FXNAX_Price[1] * Seven_Fund_Rebalance$FXNAX_Shares_Owned[1]
Seven_Fund_Rebalance$VBILX_Value[1] <- Seven_Fund_Rebalance$VBILX_Price[1] * Seven_Fund_Rebalance$VBILX_Shares_Owned[1]
Seven_Fund_Rebalance$VUSTX_Value[1] <- Seven_Fund_Rebalance$VUSTX_Price[1] * Seven_Fund_Rebalance$VUSTX_Shares_Owned[1]
Seven_Fund_Rebalance$VFIAX_Value[1] <- Seven_Fund_Rebalance$VFIAX_Price[1] * Seven_Fund_Rebalance$VFIAX_Shares_Owned[1]
Seven_Fund_Rebalance$VIMAX_Value[1] <- Seven_Fund_Rebalance$VIMAX_Price[1] * Seven_Fund_Rebalance$VIMAX_Shares_Owned[1]
Seven_Fund_Rebalance$VSMAX_Value[1] <- Seven_Fund_Rebalance$VSMAX_Price[1] * Seven_Fund_Rebalance$VSMAX_Shares_Owned[1]
Seven_Fund_Rebalance$VGSLX_Value[1] <- Seven_Fund_Rebalance$VGSLX_Price[1] * Seven_Fund_Rebalance$VGSLX_Shares_Owned[1]
# Allocation #
Seven_Fund_Rebalance$FXNAX_Allocation[1] <-
Seven_Fund_Rebalance$FXNAX_Value[1] /
sum(
Seven_Fund_Rebalance$FXNAX_Value[1],
Seven_Fund_Rebalance$VBILX_Value[1],
Seven_Fund_Rebalance$VUSTX_Value[1],
Seven_Fund_Rebalance$VFIAX_Value[1],
Seven_Fund_Rebalance$VIMAX_Value[1],
Seven_Fund_Rebalance$VSMAX_Value[1],
Seven_Fund_Rebalance$VGSLX_Value[1]
)
Seven_Fund_Rebalance$VBILX_Allocation[1] <-
Seven_Fund_Rebalance$VBILX_Value[1] /
sum(
Seven_Fund_Rebalance$FXNAX_Value[1],
Seven_Fund_Rebalance$VBILX_Value[1],
Seven_Fund_Rebalance$VUSTX_Value[1],
Seven_Fund_Rebalance$VFIAX_Value[1],
Seven_Fund_Rebalance$VIMAX_Value[1],
Seven_Fund_Rebalance$VSMAX_Value[1],
Seven_Fund_Rebalance$VGSLX_Value[1]
)
Seven_Fund_Rebalance$VUSTX_Allocation[1] <-
Seven_Fund_Rebalance$VUSTX_Value[1] /
sum(
Seven_Fund_Rebalance$FXNAX_Value[1],
Seven_Fund_Rebalance$VBILX_Value[1],
Seven_Fund_Rebalance$VUSTX_Value[1],
Seven_Fund_Rebalance$VFIAX_Value[1],
Seven_Fund_Rebalance$VIMAX_Value[1],
Seven_Fund_Rebalance$VSMAX_Value[1],
Seven_Fund_Rebalance$VGSLX_Value[1]
)
Seven_Fund_Rebalance$VFIAX_Allocation[1] <-
Seven_Fund_Rebalance$VFIAX_Value[1] /
sum(
Seven_Fund_Rebalance$FXNAX_Value[1],
Seven_Fund_Rebalance$VBILX_Value[1],
Seven_Fund_Rebalance$VUSTX_Value[1],
Seven_Fund_Rebalance$VFIAX_Value[1],
Seven_Fund_Rebalance$VIMAX_Value[1],
Seven_Fund_Rebalance$VSMAX_Value[1],
Seven_Fund_Rebalance$VGSLX_Value[1]
)
Seven_Fund_Rebalance$VIMAX_Allocation[1] <-
Seven_Fund_Rebalance$VIMAX_Value[1] /
sum(
Seven_Fund_Rebalance$FXNAX_Value[1],
Seven_Fund_Rebalance$VBILX_Value[1],
Seven_Fund_Rebalance$VUSTX_Value[1],
Seven_Fund_Rebalance$VFIAX_Value[1],
Seven_Fund_Rebalance$VIMAX_Value[1],
Seven_Fund_Rebalance$VSMAX_Value[1],
Seven_Fund_Rebalance$VGSLX_Value[1]
)
Seven_Fund_Rebalance$VSMAX_Allocation[1] <-
Seven_Fund_Rebalance$VSMAX_Value[1] /
sum(
Seven_Fund_Rebalance$FXNAX_Value[1],
Seven_Fund_Rebalance$VBILX_Value[1],
Seven_Fund_Rebalance$VUSTX_Value[1],
Seven_Fund_Rebalance$VFIAX_Value[1],
Seven_Fund_Rebalance$VIMAX_Value[1],
Seven_Fund_Rebalance$VSMAX_Value[1],
Seven_Fund_Rebalance$VGSLX_Value[1]
)
Seven_Fund_Rebalance$VGSLX_Allocation[1] <-
Seven_Fund_Rebalance$VGSLX_Value[1] /
sum(
Seven_Fund_Rebalance$FXNAX_Value[1],
Seven_Fund_Rebalance$VBILX_Value[1],
Seven_Fund_Rebalance$VUSTX_Value[1],
Seven_Fund_Rebalance$VFIAX_Value[1],
Seven_Fund_Rebalance$VIMAX_Value[1],
Seven_Fund_Rebalance$VSMAX_Value[1],
Seven_Fund_Rebalance$VGSLX_Value[1]
)
Seven_Fund_Rebalance$Low_Allocation[1] <- 7
for(i in 2:nrow(Seven_Fund_Rebalance)) {
# Shares Bought #
Seven_Fund_Rebalance[i, 'FXNAX_Shares_Bought'] <-
ifelse(
Seven_Fund_Rebalance[i - 1, 'FXNAX_Allocation'] <= FXNAX_Target_Allocation,
Monthly_Contribution_Input / Seven_Fund_Rebalance[i - 1, 'Low_Allocation'] / Seven_Fund_Rebalance[i, 'FXNAX_Price'],
0
)
Seven_Fund_Rebalance[i, 'VBILX_Shares_Bought'] <-
ifelse(
Seven_Fund_Rebalance[i - 1, 'VBILX_Allocation'] <= VBILX_Target_Allocation,
Monthly_Contribution_Input / Seven_Fund_Rebalance[i - 1, 'Low_Allocation'] / Seven_Fund_Rebalance[i, 'VBILX_Price'],
0
)
Seven_Fund_Rebalance[i, 'VUSTX_Shares_Bought'] <-
ifelse(
Seven_Fund_Rebalance[i - 1, 'VUSTX_Allocation'] <= VUSTX_Target_Allocation,
Monthly_Contribution_Input / Seven_Fund_Rebalance[i - 1, 'Low_Allocation'] / Seven_Fund_Rebalance[i, 'VUSTX_Price'],
0
)
Seven_Fund_Rebalance[i, 'VFIAX_Shares_Bought'] <-
ifelse(
Seven_Fund_Rebalance[i - 1, 'VFIAX_Allocation'] <= VFIAX_Target_Allocation,
Monthly_Contribution_Input / Seven_Fund_Rebalance[i - 1, 'Low_Allocation'] / Seven_Fund_Rebalance[i, 'VFIAX_Price'],
0
)
Seven_Fund_Rebalance[i, 'VIMAX_Shares_Bought'] <-
ifelse(
Seven_Fund_Rebalance[i - 1, 'VIMAX_Allocation'] <= VIMAX_Target_Allocation,
Monthly_Contribution_Input / Seven_Fund_Rebalance[i - 1, 'Low_Allocation'] / Seven_Fund_Rebalance[i, 'VIMAX_Price'],
0
)
Seven_Fund_Rebalance[i, 'VSMAX_Shares_Bought'] <-
ifelse(
Seven_Fund_Rebalance[i - 1, 'VSMAX_Allocation'] <= VSMAX_Target_Allocation,
Monthly_Contribution_Input / Seven_Fund_Rebalance[i - 1, 'Low_Allocation'] / Seven_Fund_Rebalance[i, 'VSMAX_Price'],
0
)
Seven_Fund_Rebalance[i, 'VGSLX_Shares_Bought'] <-
ifelse(
Seven_Fund_Rebalance[i - 1, 'VGSLX_Allocation'] <= VGSLX_Target_Allocation,
Monthly_Contribution_Input / Seven_Fund_Rebalance[i - 1, 'Low_Allocation'] / Seven_Fund_Rebalance[i, 'VGSLX_Price'],
0
)
# Shares Owned #
Seven_Fund_Rebalance[i, 'FXNAX_Shares_Owned'] <-
Seven_Fund_Rebalance[i, 'FXNAX_Shares_Bought'] + Seven_Fund_Rebalance[i - 1, 'FXNAX_Shares_Owned']
Seven_Fund_Rebalance[i, 'VBILX_Shares_Owned'] <-
Seven_Fund_Rebalance[i, 'VBILX_Shares_Bought'] + Seven_Fund_Rebalance[i - 1, 'VBILX_Shares_Owned']
Seven_Fund_Rebalance[i, 'VUSTX_Shares_Owned'] <-
Seven_Fund_Rebalance[i, 'VUSTX_Shares_Bought'] + Seven_Fund_Rebalance[i - 1, 'VUSTX_Shares_Owned']
Seven_Fund_Rebalance[i, 'VFIAX_Shares_Owned'] <-
Seven_Fund_Rebalance[i, 'VFIAX_Shares_Bought'] + Seven_Fund_Rebalance[i - 1, 'VFIAX_Shares_Owned']
Seven_Fund_Rebalance[i, 'VIMAX_Shares_Owned'] <-
Seven_Fund_Rebalance[i, 'VIMAX_Shares_Bought'] + Seven_Fund_Rebalance[i - 1, 'VIMAX_Shares_Owned']
Seven_Fund_Rebalance[i, 'VSMAX_Shares_Owned'] <-
Seven_Fund_Rebalance[i, 'VSMAX_Shares_Bought'] + Seven_Fund_Rebalance[i - 1, 'VSMAX_Shares_Owned']
Seven_Fund_Rebalance[i, 'VGSLX_Shares_Owned'] <-
Seven_Fund_Rebalance[i, 'VGSLX_Shares_Bought'] + Seven_Fund_Rebalance[i - 1, 'VGSLX_Shares_Owned']
# Value #
Seven_Fund_Rebalance[i, 'FXNAX_Value'] <-
Seven_Fund_Rebalance[i, 'FXNAX_Shares_Owned'] * Seven_Fund_Rebalance[i, 'FXNAX_Price']
Seven_Fund_Rebalance[i, 'VBILX_Value'] <-
Seven_Fund_Rebalance[i, 'VBILX_Shares_Owned'] * Seven_Fund_Rebalance[i, 'VBILX_Price']
Seven_Fund_Rebalance[i, 'VUSTX_Value'] <-
Seven_Fund_Rebalance[i, 'VUSTX_Shares_Owned'] * Seven_Fund_Rebalance[i, 'VUSTX_Price']
Seven_Fund_Rebalance[i, 'VFIAX_Value'] <-
Seven_Fund_Rebalance[i, 'VFIAX_Shares_Owned'] * Seven_Fund_Rebalance[i, 'VFIAX_Price']
Seven_Fund_Rebalance[i, 'VIMAX_Value'] <-
Seven_Fund_Rebalance[i, 'VIMAX_Shares_Owned'] * Seven_Fund_Rebalance[i, 'VIMAX_Price']
Seven_Fund_Rebalance[i, 'VSMAX_Value'] <-
Seven_Fund_Rebalance[i, 'VSMAX_Shares_Owned'] * Seven_Fund_Rebalance[i, 'VSMAX_Price']
Seven_Fund_Rebalance[i, 'VGSLX_Value'] <-
Seven_Fund_Rebalance[i, 'VGSLX_Shares_Owned'] * Seven_Fund_Rebalance[i, 'VGSLX_Price']
# Allocation #
Seven_Fund_Rebalance[i, 'FXNAX_Allocation'] <-
Seven_Fund_Rebalance[i, 'FXNAX_Value'] /
sum(
Seven_Fund_Rebalance[i, 'FXNAX_Value'],
Seven_Fund_Rebalance[i, 'VBILX_Value'],
Seven_Fund_Rebalance[i, 'VUSTX_Value'],
Seven_Fund_Rebalance[i, 'VFIAX_Value'],
Seven_Fund_Rebalance[i, 'VIMAX_Value'],
Seven_Fund_Rebalance[i, 'VSMAX_Value'],
Seven_Fund_Rebalance[i, 'VGSLX_Value']
)
Seven_Fund_Rebalance[i, 'VBILX_Allocation'] <-
Seven_Fund_Rebalance[i, 'VBILX_Value'] /
sum(
Seven_Fund_Rebalance[i, 'FXNAX_Value'],
Seven_Fund_Rebalance[i, 'VBILX_Value'],
Seven_Fund_Rebalance[i, 'VUSTX_Value'],
Seven_Fund_Rebalance[i, 'VFIAX_Value'],
Seven_Fund_Rebalance[i, 'VIMAX_Value'],
Seven_Fund_Rebalance[i, 'VSMAX_Value'],
Seven_Fund_Rebalance[i, 'VGSLX_Value']
)
Seven_Fund_Rebalance[i, 'VUSTX_Allocation'] <-
Seven_Fund_Rebalance[i, 'VUSTX_Value'] /
sum(
Seven_Fund_Rebalance[i, 'FXNAX_Value'],
Seven_Fund_Rebalance[i, 'VBILX_Value'],
Seven_Fund_Rebalance[i, 'VUSTX_Value'],
Seven_Fund_Rebalance[i, 'VFIAX_Value'],
Seven_Fund_Rebalance[i, 'VIMAX_Value'],
Seven_Fund_Rebalance[i, 'VSMAX_Value'],
Seven_Fund_Rebalance[i, 'VGSLX_Value']
)
Seven_Fund_Rebalance[i, 'VFIAX_Allocation'] <-
Seven_Fund_Rebalance[i, 'VFIAX_Value'] /
sum(
Seven_Fund_Rebalance[i, 'FXNAX_Value'],
Seven_Fund_Rebalance[i, 'VBILX_Value'],
Seven_Fund_Rebalance[i, 'VUSTX_Value'],
Seven_Fund_Rebalance[i, 'VFIAX_Value'],
Seven_Fund_Rebalance[i, 'VIMAX_Value'],
Seven_Fund_Rebalance[i, 'VSMAX_Value'],
Seven_Fund_Rebalance[i, 'VGSLX_Value']
)
Seven_Fund_Rebalance[i, 'VIMAX_Allocation'] <-
Seven_Fund_Rebalance[i, 'VIMAX_Value'] /
sum(
Seven_Fund_Rebalance[i, 'FXNAX_Value'],
Seven_Fund_Rebalance[i, 'VBILX_Value'],
Seven_Fund_Rebalance[i, 'VUSTX_Value'],
Seven_Fund_Rebalance[i, 'VFIAX_Value'],
Seven_Fund_Rebalance[i, 'VIMAX_Value'],
Seven_Fund_Rebalance[i, 'VSMAX_Value'],
Seven_Fund_Rebalance[i, 'VGSLX_Value']
)
Seven_Fund_Rebalance[i, 'VSMAX_Allocation'] <-
Seven_Fund_Rebalance[i, 'VSMAX_Value'] /
sum(
Seven_Fund_Rebalance[i, 'FXNAX_Value'],
Seven_Fund_Rebalance[i, 'VBILX_Value'],
Seven_Fund_Rebalance[i, 'VUSTX_Value'],
Seven_Fund_Rebalance[i, 'VFIAX_Value'],
Seven_Fund_Rebalance[i, 'VIMAX_Value'],
Seven_Fund_Rebalance[i, 'VSMAX_Value'],
Seven_Fund_Rebalance[i, 'VGSLX_Value']
)
Seven_Fund_Rebalance[i, 'VGSLX_Allocation'] <-
Seven_Fund_Rebalance[i, 'VGSLX_Value'] /
sum(
Seven_Fund_Rebalance[i, 'FXNAX_Value'],
Seven_Fund_Rebalance[i, 'VBILX_Value'],
Seven_Fund_Rebalance[i, 'VUSTX_Value'],
Seven_Fund_Rebalance[i, 'VFIAX_Value'],
Seven_Fund_Rebalance[i, 'VIMAX_Value'],
Seven_Fund_Rebalance[i, 'VSMAX_Value'],
Seven_Fund_Rebalance[i, 'VGSLX_Value']
)
# Low Allocation #
Seven_Fund_Rebalance[i, 'Low_Allocation'] <-
sum(
Seven_Fund_Rebalance[i, 'FXNAX_Allocation'] < FXNAX_Target_Allocation,
Seven_Fund_Rebalance[i, 'VBILX_Allocation'] < VBILX_Target_Allocation,
Seven_Fund_Rebalance[i, 'VUSTX_Allocation'] < VUSTX_Target_Allocation,
Seven_Fund_Rebalance[i, 'VFIAX_Allocation'] < VFIAX_Target_Allocation,
Seven_Fund_Rebalance[i, 'VIMAX_Allocation'] < VIMAX_Target_Allocation,
Seven_Fund_Rebalance[i, 'VSMAX_Allocation'] < VSMAX_Target_Allocation,
Seven_Fund_Rebalance[i, 'VGSLX_Allocation'] < VGSLX_Target_Allocation
)
}
Seven_Fund_Rebalance <-
Seven_Fund_Rebalance %>%
mutate(
FXNAX_Spend = FXNAX_Shares_Bought * FXNAX_Price,
VBILX_Spend = VBILX_Shares_Bought * VBILX_Price,
VUSTX_Spend = VUSTX_Shares_Bought * VUSTX_Price,
VFIAX_Spend = VFIAX_Shares_Bought * VFIAX_Price,
VIMAX_Spend = VIMAX_Shares_Bought * VIMAX_Price,
VSMAX_Spend = VSMAX_Shares_Bought * VSMAX_Price,
VGSLX_Spend = VGSLX_Shares_Bought * VGSLX_Price,
FXNAX_Total_Spend = cumsum(FXNAX_Spend),
VBILX_Total_Spend = cumsum(VBILX_Spend),
VUSTX_Total_Spend = cumsum(VUSTX_Spend),
VFIAX_Total_Spend = cumsum(VFIAX_Spend),
VIMAX_Total_Spend = cumsum(VIMAX_Spend),
VSMAX_Total_Spend = cumsum(VSMAX_Spend),
VGSLX_Total_Spend = cumsum(VGSLX_Spend),
FXNAX_Profit = FXNAX_Value - FXNAX_Total_Spend,
VBILX_Profit = VBILX_Value - VBILX_Total_Spend,
VUSTX_Profit = VUSTX_Value - VUSTX_Total_Spend,
VFIAX_Profit = VFIAX_Value - VFIAX_Total_Spend,
VIMAX_Profit = VIMAX_Value - VIMAX_Total_Spend,
VSMAX_Profit = VSMAX_Value - VSMAX_Total_Spend,
VGSLX_Profit = VGSLX_Value - VGSLX_Total_Spend,
) %>%
rowwise() %>%
mutate(
Monthly_Spend =
sum(
FXNAX_Spend,
VBILX_Spend,
VUSTX_Spend,
VFIAX_Spend,
VIMAX_Spend,
VSMAX_Spend,
VGSLX_Spend
),
Total_Investment =
sum(
FXNAX_Total_Spend,
VBILX_Total_Spend,
VUSTX_Total_Spend,
VFIAX_Total_Spend,
VIMAX_Total_Spend,
VSMAX_Total_Spend,
VGSLX_Total_Spend
),
Total_Profit =
sum(
FXNAX_Profit,
VBILX_Profit,
VUSTX_Profit,
VFIAX_Profit,
VIMAX_Profit,
VSMAX_Profit,
VGSLX_Profit
)
)
Seven_Fund_Rebalance %>%
paged_table()
Seven_Fund_No_Rebalance %>%
ggplot(aes(x = Date)) +
geom_line(aes(y = FXNAX_Allocation, color = 'FXNAX')) +
geom_line(aes(y = VBILX_Allocation, color = 'VBILX')) +
geom_line(aes(y = VUSTX_Allocation, color = 'VUSTX')) +
geom_line(aes(y = VFIAX_Allocation, color = 'VFIAX')) +
geom_line(aes(y = VIMAX_Allocation, color = 'VIMAX')) +
geom_line(aes(y = VSMAX_Allocation, color = 'VSMAX')) +
geom_line(aes(y = VGSLX_Allocation, color = 'VGSLX')) +
theme_bw() +
scale_y_continuous(labels = comma) +
scale_color_gdocs(' ') +
ggtitle('Seven Fund No Rebalance Asset Allocation') +
xlab(paste('\n', 'Date')) +
ylab(paste('Allocation', '\n'))
Seven_Fund_Rebalance %>%
ggplot(aes(x = Date)) +
geom_line(aes(y = FXNAX_Allocation, color = 'FXNAX')) +
geom_line(aes(y = VBILX_Allocation, color = 'VBILX')) +
geom_line(aes(y = VUSTX_Allocation, color = 'VUSTX')) +
geom_line(aes(y = VFIAX_Allocation, color = 'VFIAX')) +
geom_line(aes(y = VIMAX_Allocation, color = 'VIMAX')) +
geom_line(aes(y = VSMAX_Allocation, color = 'VSMAX')) +
geom_line(aes(y = VGSLX_Allocation, color = 'VGSLX')) +
theme_bw() +
scale_y_continuous(labels = comma) +
scale_color_gdocs(' ') +
ggtitle('Seven Fund Rebalance Asset Allocation') +
xlab(paste('\n', 'Date')) +
ylab(paste('Allocation', '\n'))
Seven_Fund_No_Rebalance %>%
ggplot(aes(x = Date)) +
geom_line(aes(y = FXNAX_Profit, color = 'FXNAX Profit')) +
geom_line(aes(y = VBILX_Profit, color = 'VBILX Profit')) +
geom_line(aes(y = VUSTX_Profit, color = 'VUSTX Profit')) +
geom_line(aes(y = VFIAX_Profit, color = 'VFIAX Profit')) +
geom_line(aes(y = VIMAX_Profit, color = 'VIMAX Profit')) +
geom_line(aes(y = VSMAX_Profit, color = 'VSMAX Profit')) +
geom_line(aes(y = VGSLX_Profit, color = 'VGSLX Profit')) +
theme_bw() +
scale_y_continuous(labels = comma) +
scale_color_gdocs(' ') +
ggtitle('Seven Fund No Rebalance Profit') +
xlab(paste('\n', 'Date')) +
ylab(paste('Profit ($)', '\n'))
Seven_Fund_Rebalance %>%
ggplot(aes(x = Date)) +
geom_line(aes(y = FXNAX_Profit, color = 'FXNAX')) +
geom_line(aes(y = VBILX_Profit, color = 'VBILX')) +
geom_line(aes(y = VUSTX_Profit, color = 'VUSTX')) +
geom_line(aes(y = VFIAX_Profit, color = 'VFIAX')) +
geom_line(aes(y = VIMAX_Profit, color = 'VIMAX')) +
geom_line(aes(y = VSMAX_Profit, color = 'VSMAX')) +
geom_line(aes(y = VGSLX_Profit, color = 'VGSLX')) +
theme_bw() +
scale_y_continuous(labels = comma) +
scale_color_gdocs(' ') +
ggtitle('Seven Fund Rebalance Profit') +
xlab(paste('\n', 'Date')) +
ylab(paste('Profit ($)', '\n'))
Seven_Fund_Profit <-
Seven_Fund_No_Rebalance %>%
select(
Date,
Total_Profit
) %>%
rename(
No_Rebalance_Total_Profit = Total_Profit
) %>%
left_join(
Seven_Fund_Rebalance %>%
select(
Date,
Total_Profit,
Total_Investment
) %>%
rename(
Rebalance_Total_Profit = Total_Profit
),
by = c('Date')
)
Seven_Fund_Profit %>%
ggplot(aes(x = Date)) +
geom_line(aes(y = Rebalance_Total_Profit, color = 'Rebalance Total Profit')) +
geom_line(aes(y = No_Rebalance_Total_Profit, color = 'No Rebalance Total Profit')) +
geom_line(aes(y = Total_Investment, color = 'Total Investment')) +
theme_bw() +
scale_y_continuous(labels = comma) +
scale_color_manual(' ', values = c(Hex_Google_Red, Hex_Google_Green, Hex_Google_Blue)) +
ggtitle('Seven Fund Total Profit') +
xlab(paste('\n', 'Date')) +
ylab(paste('Dollars ($)', '\n'))
Two Fund No Rebalance
Start_Date_Input <- '2002-01-01'
End_Date_Input <- '2022-01-01'
Monthly_Contribution_Input <- 1000
VFIAX_Contribution <- Monthly_Contribution_Input * 0.70
VBTLX_Contribution <- Monthly_Contribution_Input * 0.30
Two_Fund_No_Rebalance <-
Two_Fund_Data %>%
filter(
Date >= Start_Date_Input,
Date <= End_Date_Input
) %>%
mutate(
VFIAX_Shares_Bought = VFIAX_Contribution / VFIAX_Price,
VFIAX_Shares_Owned = cumsum(VFIAX_Shares_Bought),
VFIAX_Value = VFIAX_Price * VFIAX_Shares_Owned,
VFIAX_Profit = VFIAX_Value - (row_number() * VFIAX_Contribution),
VBTLX_Shares_Bought = VBTLX_Contribution / VBTLX_Price,
VBTLX_Shares_Owned = cumsum(VBTLX_Shares_Bought),
VBTLX_Value = VBTLX_Price * VBTLX_Shares_Owned,
VBTLX_Profit = VBTLX_Value - (row_number() * VBTLX_Contribution),
Total_Investment = row_number() * Monthly_Contribution_Input
) %>%
rowwise() %>%
mutate(
VFIAX_Allocation =
VFIAX_Value / sum(VFIAX_Value, VBTLX_Value),
VBTLX_Allocation =
VBTLX_Value / sum(VFIAX_Value, VBTLX_Value),
Total_Profit =
sum(VFIAX_Profit, VBTLX_Profit),
)
Two_Fund_No_Rebalance %>%
paged_table()
Two Fund Rebalance
Start_Date_Input <- '2002-01-01'
End_Date_Input <- '2022-01-01'
Monthly_Contribution_Input <- 1000
VFIAX_Target_Allocation <- 0.70
VBTLX_Target_Allocation <- 0.30
Adjustment_Input <- 0.05
Two_Fund_Rebalance <-
Two_Fund_Data %>%
filter(
Date >= Start_Date_Input,
Date <= End_Date_Input
) %>%
mutate(
VFIAX_Shares_Bought = NA,
VBTLX_Shares_Bought = NA,
VFIAX_Shares_Owned = NA,
VBTLX_Shares_Owned = NA,
VFIAX_Value = NA,
VBTLX_Value = NA,
VFIAX_Allocation = NA,
VBTLX_Allocation = NA
)
# Shares Bought #
Two_Fund_Rebalance$VFIAX_Shares_Bought[1] <-
(Monthly_Contribution_Input * VFIAX_Target_Allocation) / Two_Fund_Rebalance$VFIAX_Price[1]
Two_Fund_Rebalance$VBTLX_Shares_Bought[1] <-
(Monthly_Contribution_Input * VBTLX_Target_Allocation) / Two_Fund_Rebalance$VBTLX_Price[1]
# Shares Owned #
Two_Fund_Rebalance$VFIAX_Shares_Owned[1] <- Two_Fund_Rebalance$VFIAX_Shares_Bought[1]
Two_Fund_Rebalance$VBTLX_Shares_Owned[1] <- Two_Fund_Rebalance$VBTLX_Shares_Bought[1]
# Value #
Two_Fund_Rebalance$VFIAX_Value[1] <- Two_Fund_Rebalance$VFIAX_Price[1] * Two_Fund_Rebalance$VFIAX_Shares_Owned[1]
Two_Fund_Rebalance$VBTLX_Value[1] <- Two_Fund_Rebalance$VBTLX_Price[1] * Two_Fund_Rebalance$VBTLX_Shares_Owned[1]
# Allocation #
Two_Fund_Rebalance$VFIAX_Allocation[1] <-
Two_Fund_Rebalance$VFIAX_Value[1] /
sum(
Two_Fund_Rebalance$VFIAX_Value[1],
Two_Fund_Rebalance$VBTLX_Value[1]
)
Two_Fund_Rebalance$VBTLX_Allocation[1] <-
Two_Fund_Rebalance$VBTLX_Value[1] /
sum(
Two_Fund_Rebalance$VFIAX_Value[1],
Two_Fund_Rebalance$VBTLX_Value[1]
)
for(i in 2:nrow(Two_Fund_Rebalance)) {
# Shares Bought #
Two_Fund_Rebalance[i, 'VFIAX_Shares_Bought'] <-
ifelse(
Two_Fund_Rebalance[i - 1, 'VFIAX_Allocation'] <= VFIAX_Target_Allocation,
Monthly_Contribution_Input * (VFIAX_Target_Allocation + Adjustment_Input) /
Two_Fund_Rebalance[i, 'VFIAX_Price'],
Monthly_Contribution_Input * (VFIAX_Target_Allocation - Adjustment_Input) /
Two_Fund_Rebalance[i, 'VFIAX_Price']
)
Two_Fund_Rebalance[i, 'VBTLX_Shares_Bought'] <-
ifelse(
Two_Fund_Rebalance[i - 1, 'VBTLX_Allocation'] <= VBTLX_Target_Allocation,
Monthly_Contribution_Input * (VBTLX_Target_Allocation + Adjustment_Input) /
Two_Fund_Rebalance[i, 'VBTLX_Price'],
Monthly_Contribution_Input * (VBTLX_Target_Allocation - Adjustment_Input) /
Two_Fund_Rebalance[i, 'VBTLX_Price']
)
# Shares Owned #
Two_Fund_Rebalance[i, 'VFIAX_Shares_Owned'] <-
Two_Fund_Rebalance[i, 'VFIAX_Shares_Bought'] + Two_Fund_Rebalance[i - 1, 'VFIAX_Shares_Owned']
Two_Fund_Rebalance[i, 'VBTLX_Shares_Owned'] <-
Two_Fund_Rebalance[i, 'VBTLX_Shares_Bought'] + Two_Fund_Rebalance[i - 1, 'VBTLX_Shares_Owned']
# Value #
Two_Fund_Rebalance[i, 'VFIAX_Value'] <-
Two_Fund_Rebalance[i, 'VFIAX_Shares_Owned'] * Two_Fund_Rebalance[i, 'VFIAX_Price']
Two_Fund_Rebalance[i, 'VBTLX_Value'] <-
Two_Fund_Rebalance[i, 'VBTLX_Shares_Owned'] * Two_Fund_Rebalance[i, 'VBTLX_Price']
# Allocation #
Two_Fund_Rebalance[i, 'VFIAX_Allocation'] <-
Two_Fund_Rebalance[i, 'VFIAX_Value'] /
sum(
Two_Fund_Rebalance[i, 'VFIAX_Value'],
Two_Fund_Rebalance[i, 'VBTLX_Value']
)
Two_Fund_Rebalance[i, 'VBTLX_Allocation'] <-
Two_Fund_Rebalance[i, 'VBTLX_Value'] /
sum(
Two_Fund_Rebalance[i, 'VFIAX_Value'],
Two_Fund_Rebalance[i, 'VBTLX_Value']
)
}
Two_Fund_Rebalance <-
Two_Fund_Rebalance %>%
mutate(
VFIAX_Spend = VFIAX_Shares_Bought * VFIAX_Price,
VBTLX_Spend = VBTLX_Shares_Bought * VBTLX_Price,
VFIAX_Total_Spend = cumsum(VFIAX_Spend),
VBTLX_Total_Spend = cumsum(VBTLX_Spend),
VFIAX_Profit = VFIAX_Value - VFIAX_Total_Spend,
VBTLX_Profit = VBTLX_Value - VBTLX_Total_Spend
) %>%
rowwise() %>%
mutate(
Monthly_Spend =
sum(
VFIAX_Spend,
VBTLX_Spend
),
Total_Investment =
sum(
VFIAX_Total_Spend,
VBTLX_Total_Spend
),
Total_Profit =
sum(
VFIAX_Profit,
VBTLX_Profit
)
)
Two_Fund_Rebalance %>%
paged_table()
Two_Fund_Profit <-
Two_Fund_No_Rebalance %>%
select(
Date,
Total_Profit
) %>%
rename(
No_Rebalance_Total_Profit = Total_Profit
) %>%
left_join(
Two_Fund_Rebalance %>%
select(
Date,
Total_Profit,
Total_Investment
) %>%
rename(
Rebalance_Total_Profit = Total_Profit
),
by = c('Date')
)
Two_Fund_Profit %>%
ggplot(aes(x = Date)) +
geom_line(aes(y = Rebalance_Total_Profit, color = 'Rebalance_Total_Profit')) +
geom_line(aes(y = No_Rebalance_Total_Profit, color = 'No_Rebalance_Total_Profit')) +
geom_line(aes(y = Total_Investment, color = 'Total Investment')) +
theme_bw() +
scale_y_continuous(labels = comma) +
scale_color_manual(' ', values = c(Hex_Google_Red, Hex_Google_Green, Hex_Google_Blue)) +
ggtitle('Two Fund Profit') +
xlab(paste('\n', 'Date')) +
ylab(paste('Dollars ($)', '\n'))
One Fund No Rebalance
Start_Date_Input <- '1982-01-01'
End_Date_Input <- '2022-01-01'
Monthly_Contribution_Input <- 1000
SP500_Contribution <- Monthly_Contribution_Input * 1.0
One_Fund_No_Rebalance <-
SP500_Data %>%
filter(
Date >= Start_Date_Input,
Date <= End_Date_Input
) %>%
mutate(
SP500_Shares_Bought = SP500_Contribution / SP500_Price,
SP500_Shares_Owned = cumsum(SP500_Shares_Bought),
SP500_Value = SP500_Price * SP500_Shares_Owned,
SP500_Profit = SP500_Value - (row_number() * SP500_Contribution),
Total_Investment = row_number() * Monthly_Contribution_Input
) %>%
rowwise() %>%
mutate(
Total_Profit =
sum(SP500_Profit),
)
One_Fund_No_Rebalance %>%
paged_table()
One_Fund_No_Rebalance %>%
ggplot(aes(x = Date)) +
geom_line(aes(y = Total_Profit, color = 'Total Profit')) +
geom_line(aes(y = Total_Investment, color = 'Total Investment')) +
theme_bw() +
scale_y_continuous(labels = comma) +
scale_color_gdocs(' ') +
ggtitle('One Fund Total Profit') +
xlab(paste('\n', 'Date')) +
ylab(paste('Dollars ($)', '\n'))