Friday, May 31, 2019

Case study: My portfolio idea - VFV, VDU, VAB (series 4 of 10)

May 31, 2019

Introduction


It is my portfolio idea just to borrow from the article Canada retirement guide using three ETF (VFU, VDU, VAB). The blog is related to CAD-Hedged vs Not Hedged. 

Case study


CAD-Hedged vs Not Hedged

Our portfolio invests in ETFs that are not CAD-Hedged because their returns are significantly higher and more stable than ETFs that are CAD-Hedged. The table below compares this historical performance on developed market stocks.

FTSE Developed All Cap Index = developed market stocks
Historical Returns
1 Year
5 Year
10 Year
FTSE Developed All Cap Index
(not CAD-Hedged)
–​1.5%    
9.8%    
10.8%    
FTSE Developed All Cap Index
(CAD-Hedged)
–7.9%    
6.5%    
10.4%    
(annualized returns as of December 31, 2018)
Note: All returns are in Canadian dollars.
Sources: FTSE Russell index fact sheets.


Actionable Items


I like to learn the concept called CAD-Hedged. 

Case study: My portfolio idea - VFV, VDU, VAB (series 3 of 10)

May 31, 2019

Introduction


It is my portfolio idea just to borrow from the article Canada retirement guide using three ETF (VFU, VDU, VAB). The blog is related to developed market vs emerging market. 


Case study



Developed Market vs Emerging Market

Our portfolio invests in developed market stocks because their returns are significantly higher and more stable than emerging market stocks. The table below compares the historical performance of those two stock indexes. Together they cover the entire global stock market.

FTSE Developed All Cap Index = developed market stocks
FTSE Emerging All Cap Index = emerging market stocks
Historical Returns
1 Year
5 Year
10 Year
FTSE Developed All Cap Index
–1.5%    
9.8%    
10.8%    
FTSE Emerging All Cap Index
–7.1%    
6.6%    
8.8%    


(annualized returns as of December 31, 2018)
Note: All returns are in Canadian dollars.
Sources: FTSE Russell index fact sheets.


Actionable Items


Please take some time to read FTSE Russell index fact sheets. 

Case study: My portfolio idea - VFV, VDU, VAB (series 2 of 10)

May 31, 2019

Introduction


It is my portfolio idea just to borrow from the article Canada retirement guide using three ETF (VFU, VDU, VAB).

Case study


It is best one. I like to read this argument based on the following analysis.

Outperform the World's Best Portfolios

Our ETF portfolio has outperformed Harvard University and Stanford University's endowments. Those endowments are considered the world's best portfolios in terms of their size and returns. They collectively hold over $60 billion in stocks, bonds, hedge funds, private equity, venture capital, leveraged buyouts, commodities, and real estate. Their investment performance are heavily followed on Wall Street.
Historical Returns
3 Year
5 Year
10 Year
       Our ETF Portfolio
7.0%    
10.9%    
7.1%    
       Harvard's Endowment
5.2%    
7.3%    
4.5%    
       Stanford's Endowment
7.8%    
9.4%    
6.3%    
(annualized returns as of June 30, 2018)
Sources: Vanguard Investments Canada, Harvard Management Company, and Stanford Management Company.

Actionable Items


I like to look into Harvard University and Stanford University's endowments. 

Case study: My portfolio idea - VFV, VDU, VAB (series 1 of 10)

May 31, 2019

Introduction


It is my personal finance research. I have to set up my portfolio on QuestTrade.com for my TFSA account,  I have $50,000 Canada dollars and I like to set up portfolio as soon as possible.

Case study


I spent half hour to read this portfolio seen in the article 2019 Top 3 Index ETF To Invest (Canadian Retirement Guide). I like to copy the idea and see what I should learn from.

Symbol
Description
VFV
Vanguard S&P 500 Index ETF
  • 0.08% Management Fee
  • 500 largest stocks in the United States
  • Example: Microsoft, Google, Visa, Disney, Walmart
VDU
Vanguard FTSE Developed All Cap ex U.S. Index ETF
  • 0.20% Management Fee
  • 3,900 stocks in developed countries (excluding US)
  • Example: RBC, Nestle, Adidas, Samsung, Toyota
VAB
Vanguard Canadian Aggregate Bond Index ETF
  • 0.08% Management Fee
  • 900 government and corporate bonds in Canada
  • Example: Federal, Provincial, Municipal bonds
Pie Chart:  30% VFV / 30% VDU / 40% VAB
ETF Portfolio Summary
  • 60% Stocks and 40% Bonds
  • 0.12% MER (Management Expense Ratio)
  • 4,400 companies in developed markets around the world
  • 900 investment-grade bonds in Canada

Thursday, May 30, 2019

One good news from a friend who just joined Facebook

May 30, 2019

Introduction


I have a good news through the email. One of my friends just shared me through the mail that she joined Facebook recently.

Things to do


I like to find those blogs and algorithms we worked together, and then mark them. I learn so many things from her.

Here is one discussion session we had together in June 2018.


Tips shared by my friend


1. Get a master degree from computer science major from top 10 university;
2. Have more than 20 onsite interview in less than six months in Sillicon Valley;
3. Finish all easy, medium level algorithms on Leetcode.com;
4. Get offer from Microsoft Seattle first;
5. Have work experience more than five years in top 20 software companies.
6. Really work hard to practice, mock interview, a small group discussion with others at least one year. Apply Facebook and Google last, try all other companies first.

Work together


I met the friend in Nov. 2017 twice on pramp.com;
Later she reached out to me through linkedin early 2018, she suggested to me that we can work together a few times, one time a week;
We met again on interviewing.io once again after I failed Microsoft online assessment in July 2018;



Canada investment products

Here is the link.

I like to start to put all $50,000 Canadian dollars into different Vanguard Canada investment products. I like to build a portfolio, so that I can reblance if the market goes up or down.

Bond short term - less than three years

Canadian Aggregate Bond Index ETF  - VAB  - $20,000 dollars

3 years - 5 years


More than 5 - 10 years

VFV - $10,000
VGG - $10,000
VUN - S10,000



ETFs that invest in US Companies

ETFs that invest in US Companies

The top five ETFs (ordered by assets under management, or AUM) that invest in American companies are listed below.
NAMEISSUERDESCRIPTIONAUM (IN BILLIONS CAD)MERTSX SYMBOLMARKET CAPITALIZATION OF INDEXED COMPANIES
BMO S&P 500 Index ETF (CAD)BMO Asset ManagementSeeks to mimic the performance of the entire stock market by tracking the S&P Total Market Index50.09ZSPlarge
Vanguard S&P 500 Index ETFVanguard Investments CanadaSeeks to track large-capitalization U.S. stocks by mimicking the S&P 500 index1.90.08VFVlarge
U.S. Total Market Index ETFVanguard Investments CanadaSeeks to mimic the performance of the entire stock market by tracking the CRSP US Total Market Index1.40.16VUNsmall, mid, large
iShares Core S&P U.S. Total Market Index ETFBlackRockSeeks to mimic the performance of the entire stock market by tracking the S&P Total Market Index1.30.07XUUsmall, mid, large
Vanguard S&P 500 Index ETF (CAD-hedged)Vanguard Investments CanadaSeeks to track large-capitalization U.S. stocks by mimicking the S&P 500 Index and employing currency hedging to protect you from losses if the U.S. dollar declines0.760.08VSPlarge

Which S&P500 ETF is the Best? [SPY vs. VOO vs. IVV]

Here is the link.


Vanguard S&P 500 ETF (VOO)

Here is the link.


Fed and China are driving the market, says chief market strategist

Here is the link.


Vanguard S&P 500 Index ETF

Here is the pdf file to read.

I am thinking about how to purchase VFV ETF and use dollar cost average method to do the work.


VFV and VSP: Two ways to invest in U.S. stocks

U.S. stocks represent roughly 48% of the global equity market and are essential for a diversified portfolio.1 Vanguard S&P 500 Index ETF (VFV) and Vanguard S&P 500 Index ETF (CAD-hedged) (VSP) provide exposure to 500 of the largest U.S. companies.
“A well-balanced portfolio invested for the long term should be diversified across geographical regions as well as sectors,” says Dean Allen, head of product management for Vanguard Investments Canada Inc. “That includes exposure to U.S. equities and abroad, as Canada is highly concentrated in three main sectors.”
Both VFV and VSP seek to track the S&P 500 Index by investing primarily in the U.S.-domiciled Vanguard S&P 500 ETF, which holds every stock in the index. The only difference between VFV and VSP is that VSP hedges its currency exposure to the Canadian dollar.

2019 Top 3 Index ETFs To Buy (Canadian Retirement Guide)

Here is the link.

Symbol
Description
VFV
Vanguard S&P 500 Index ETF
  • 0.08% Management Fee
  • 500 largest stocks in the United States
  • Example: Microsoft, Google, Visa, Disney, Walmart
VDU
Vanguard FTSE Developed All Cap ex U.S. Index ETF
  • 0.20% Management Fee
  • 3,900 stocks in developed countries (excluding US)
  • Example: RBC, Nestle, Adidas, Samsung, Toyota
VAB
Vanguard Canadian Aggregate Bond Index ETF
  • 0.08% Management Fee
  • 900 government and corporate bonds in Canada
  • Example: Federal, Provincial, Municipal bonds
Pie Chart:  30% VFV / 30% VDU / 40% VAB
ETF Portfolio Summary
  • 60% Stocks and 40% Bonds
  • 0.12% MER (Management Expense Ratio)
  • 4,400 companies in developed markets around the world
  • 900 investment-grade bonds in Canada

SPDR S&P Regional Banking ETF (KRE)

Here is the link.


Dow plunges nearly 800 points on rising fears of an economic slowdown

Here is the article's link.

The Dow Jones Industrial Average fell 799.36 points, or 3.1 percent, to close at 25,027.07 and posted its worst day since Oct. 10. At its low of the day, the Dow had fallen more than 800 points.

The S&P 500 declined 3.2 percent to close at 2,700.06. The benchmark fell below its 200-day moving average, which triggered more selling from algorithmic funds. 

Financials were the worst performers in the S&P 500, plunging 4.4 percent. Utilities was the only positive sector in the S&P 500, rising 0.16 percent.

The Nasdaq Composite dropped 3.8 percent to close back in correction territory at 7,158.43. The Russell 2000, which tracks small-cap stocks, dropped 4.4 percent to 1,480.75, marking its worst day since 2011. Trading volume in U.S. stocks was also higher than usual on Wall Street.


Dow drops 800 points

Here is the link.

450. Delete Node in a BST 2019 practice

Here is the link.


It is my practice in 2019. I have to work on so many algorithms, one thing I can do is to share more content on this practice, and also work on my patience. One thing I can do is to go over example tree, and work on the example more carefully, so that next time I will not miss an edge case.

To be a good engineer, I have to learn how to work on the example tree, go over the tree at least once to show myself how to approach the problem. I am not afraid to implement any idea I may come out; only thing I have to work on is to pay attention to edge case, do not rely on online judge to remind me my mistakes.

Here is the copy of content in Leetcode discuss. 

It is one of mock interview algorithms. I spent first 10 minutes to draw a tree and then figure out the solution by myself.
To be a good problem solver, I have to work on my patience and draw some example tree, and work on the edge case carefully. Here is the tree I like to present and I explain how to solve the problem in multiple steps.
Given root node with value 6, and key 4, I need to find the node with value 4, and then search it's left subtree to find maximum value node first.
image
Given root node with value 6, and key 4, I worked on the above tree, go to node 4 left subtree and try to find maximum value in left subtree. I find node 3 and it's parent node, and then node 4's value will be updated to 3, and node 3's parent will have right child set as node's left child.
I ran the code against online judge, and then I found out that I missed another case. What if the node 4's left child is largest node in left subtree.
I need more patience and think about more carefully in order to solve the problem in shortest time.
Here are hightlights of my solution:
  1. Since the root node can be the node with key value, and the tree maybe is the one with one node. So I create a dummy node and make root node as its left child;
  2. Use binary search to search key value in binary search tree, either root node has the value key, or go to left or right to search the node;
  3. Use step 2 to find node with key value first, and work on the case if node with key value has left child;
  4. Write a while loop to find rightmost node in left subtree, and also keep parent node;
  5. Set key value node with rightmost node's value
  6. reconnect rightmost node's parent node's right child, remove rightmost node from the tree
  7. Work on the right subtree case
  8. Find out that I missed the edge case - step 4, left child of node value 4 is the largest node in left subtree
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     public int val;
 *     public TreeNode left;
 *     public TreeNode right;
 *     public TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    /// <summary>
        /// binary search the node
        /// binary search tree
        /// </summary>
        /// <param name="root"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public TreeNode DeleteNode(TreeNode root, int key)
        {
            if (root == null)
                return root;

            TreeNode parentNode = new TreeNode(1);
            parentNode.left = root; 
             
            traverseTree(root, parentNode, true, key);

            return parentNode.left; 
        }

        /// <summary>
        /// May 30, 2019
        /// </summary>
        /// <param name="root"></param>
        /// <param name="parentNode"></param>
        /// <param name="isLeft"></param>
        /// <param name="key"></param>
        private static void traverseTree(TreeNode root, TreeNode parentNode, bool isLeft, int key)
        {
            if (root == null)
                return;

            var value = root.val;
            if (value == key)
            {
                if (root.left == root.right)
                {
                    if (isLeft)
                        parentNode.left = null;
                    else
                        parentNode.right = null;

                    return;
                }

                //Find left
                if (root.left != null)
                {
                    // find rightmost node, which should not have right child
                    // make its parent node's right child to it's left child
                    var largestNode = root.left;
                    var parent = parentNode; 
                    while (largestNode.right != null)
                    {
                        parent = largestNode;
                        largestNode = largestNode.right;                        
                    }

                    var largestValue = largestNode.val;
                    root.val = largestValue;

                    if (largestNode != root.left)
                    {
                        parent.right = largestNode.left;                       
                    }
                    else 
                    {
                        root.left = largestNode.left;                       
                    }

                    largestNode = null; // set null
                }
                else if (root.right != null)
                {
                    // find leftmost node, which should not have left child
                    // make its parent node's left child to it's right child
                    var smallestNode = root.right;
                    var parent = parentNode;
                    while (smallestNode.left != null)
                    {
                        parent = smallestNode;
                        smallestNode = smallestNode.left;
                    }

                    var smallestValue = smallestNode.val;
                    root.val = smallestValue;

                    if (smallestNode != root.right)
                    {
                        parent.left = smallestNode.right;
                    }
                    else
                    {
                        root.right = smallestNode.right;
                    }

                    smallestNode = null; // set null 
                }

                return;
            }

            if (value < key)
            {
                traverseTree(root.right, root, false, key);
            }
            else
            {
                traverseTree(root.left, root, true, key);
            }
        }
}

227. Basic Calculator II

Here is the link.

It is easy for me to come out the idea using stack to store operator and operands, and it is always to calculate * and / arithmetic calculations first, and then work on + and - operands.
Here are highlights:
  1. Go over the input string once character by character, skip space, push operator into stack, mark * or / operator for immediate processing, parse integer and push into stack as well;
  2. In step 1, if number is pushed into stack, and also high operator is found, then pop three times to calculate the result, push back into stack;
  3. After iteration of input string, go over the stack, process + or - operator, do calculation;
  4. In step 3, I made the mistake on the edge case 1 - 1 + 2, the result should be 2, I calculated 1 - ( 1+ 2) = -2. I did extra checking for operator, if found, then it is popped out, '+' is pushed back in.
public class Solution {
    /// <summary>
        /// Implement the algorithm using data structure - stack 
        /// once *, / sign meet, calculate the value right away; 
        /// once the end of expression, go back to stack and then 
        /// pop one by one to calculate.
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public int Calculate(string s)
        {
            if (s == null || s.Length == 0)
                return 0;

            var length = s.Length;
            var stack = new Stack<string>();
            var digits = "0123456789";
            var operators = "+-*/";
            
            // "3+2*2"
            int index = 0;
            var highOperator = false;

            while (index < length)
            {
                var current = s[index];
               
                if (current == ' ')
                {
                    index++;
                    continue; 
                }

                if (operators.IndexOf(current) != -1)
                {
                    stack.Push(current.ToString());
                    index++;

                    if (current == '*' || current == '/')
                    {
                        highOperator = true; 
                    }
                }

                if(digits.IndexOf(current) != -1)
                {
                    int start = index;
                    int end = index;
                    while(index < length && digits.IndexOf(s[index]) != -1)
                    {
                        end = index;
                        index++;                        
                    }

                    var number = s.Substring(start, end - start + 1);

                    stack.Push(number);
                    if (highOperator)
                    {
                        var number2 = Convert.ToInt32(stack.Pop());
                        var operator1 = stack.Pop();
                        var number1 = Convert.ToInt32(stack.Pop());
                        if(operator1[0] == '*')
                        {
                            stack.Push((number1 * number2).ToString());
                        }
                        else 
                        {
                            stack.Push((number1 / number2).ToString());
                        }

                        highOperator = false;
                    }
                }
            }

            while (stack.Count > 0)
            {
                var unknown = stack.Pop();
                var isOperator = unknown.Length == 1 && operators.IndexOf(unknown[0]) != -1;
                if (!isOperator)
                {
                    var number2 = Convert.ToInt32(unknown);

                    if (stack.Count >= 2)
                    {
                        var operator1 = stack.Pop();
                        var number1 = Convert.ToInt32(stack.Pop());

                        //1-1+2
                        if (stack.Count > 0 && stack.Peek().Length == 1 && stack.Peek()[0] == '-')
                        {
                            stack.Pop();
                            stack.Push("+");
                            number1 *= -1; 
                        }

                        if (operator1[0] == '+')
                        {
                            stack.Push((number1 + number2).ToString());
                        }
                        else if (operator1[0] == '-')
                        {
                            stack.Push((number1 - number2).ToString());
                        }
                    }
                    else
                    {
                        return number2;
                    }
                }
            }      

            return 0; 
        }
}