Thursday, July 16, 2020

Personal capital: Daily finance monitor - My lesson of speculation

July 16, 2020

Introduction

It is so exciting to learn the mistake I made on July 15, 2020. Let me write down the story.

Personal capital


I  have opportunity on July 15, 2020 to purchase 1000 share of SABR, what I did is to purchase only 50 shares. The return is over 13.46%.

I had 500 shares and my loss is over $600 dollars.




Actionable Items


I should evaluate the risk on July 16, 2020. It was best opportunity for me to invest on SABR stock at price of 7.50, I should use available cash $9000 dollars to purchase SABR stock. It only takes one day to have over 10% gains, and then I can sell all of those shares of SABR stock.

It does not help if I like to purchase more shares. If I sell ENBL shares, the fund will be available in one business day at least.

So it is important for me to prepare $10,000 dollars in Key largo IRA account. If there is chance for me to invest short term, the fund can be available right away. Otherwise, I should make a 2 or 3 day plan, sell ENBL stocks and then plan to invest a short term.


Wednesday, July 15, 2020

Mock interview: 1080 Insufficient Nodes in Root to Leaf Paths

July 15, 2020

Introduction


The interviewee is Microsoft SDE II with two years experience, his performance on this algorithm is super talent level. It took him less than 20 minutes, and I ran through Leetcode online judge. It passed all test cases.

Case study


Here is the gist including source code. I will write a short case study on Leetcode discuss post.


Continue

Comparison


It is so challenge for me to accept the truth. The interviewee is SDE II with two years experience. He did share his experience to work on books cracking coding interview and also elements of programming. 

His idea is very creative, and efficient. The recursive function design is to meet the requirement directly. Do not work around the problem. 

The interviewee works on preparation of so many interviews. It is true that they all get so many experience on interviews. The companies are Amazon, Facebook, Tik Tot, Square, Box.

Mock interview:

The blog is created for one mock interview - the algorithm. Here is the gist file. 

Growth stock portfolio: 10 stocks

Here is the article. 

Goldman’s growth playbook

For investors who still want to bet on growth stocks, Goldman came up with a list of names with strong growth and high margins but less risk from regulation and high valuations.
The bank screened for Russell 3000 stocks with over $1 billion market cap and with the following features:
  • Positive sales growth in each of the past three years, averaging at least 10%
  • Consensus 10%+ sales growth in each of the next two years
  • Consensus 2019 net profit margins greater than 10%
  • Forward EV/sales ratios below 6 times
  • Low regulatory risk based on share of industry U.S. sales
The list of 21 stocks is concentrated in tech and health care, and contains credit card service company Euronet Worldwide, software firm Ebix, Supernus Pharmaceuticals, athletic apparel maker Lululemon Athletica and chipmaker Advanced Micro Devices.

7月份财报

Here is the link.


BA - Bank of America
Netflix stock
SAVE stock - Spirit
Facebook stock


Why Carnival, Royal Caribbean, and Norwegian Cruise Line Stocks Soared Today

Here is the article.

Cruise ship stocks surged on Wednesday after investors received exciting news about an experimental COVID-19 vaccine.
By the close of trading, shares of Carnival (NYSE:CCL) (NYSE:CUK), Royal Caribbean (NYSE:RCL), and Norwegian Cruise Line Holdings (NASDAQ:NCLH) were up 16%, 21%, and 20%, respectively.

So what

Surging COVID-19 case counts have weighed heavily on the cruise industry. Royal Caribbean, Carnival, and Norwegian have had their ships stuck at port for months, following a string of coronavirus-related outbreaks aboard their vessels. With little revenue coming in, they've been bleeding cash and forced to incur massive amounts of debt to stay afloat.

Sabr.To stock: July 10 crash and July 15 2020 rebound 10%

July 15, 2020

Introduction

It is important for me to discipline myself, buy low and sell high; I should discipline myself, take some risk, and then purchase $500 shares back in lowest price. 

Sabr.To stock


Sabr stock 13.46% return 


HSE.TO stock: July 10 crash and rebound July 15 - 4 business day

July 15, 2020

Introduction

I like to make plans to invest more than $40,000 dollars when market crashes like the one on July 10, and then I like to get gains on rebound in less than 5 business days. 

HSE.TO stock



AC.TO stock: Will Air Canada (TSX:AC) Stock Turn $20,000 Into $1 Million? The Motley Fool Ryan Vanzo

Here is the article.

Air Canada (TSX:AC) is a millionaire-maker stock. Or at least it was. In 2012, shares were priced at $1. Eight years later, they surpassed $50. To make $1 million, you needed to invest just $20,000.

But there’s a catch here. Stock prices are a reflection of expectations, not reality. If Air Canada shares are priced for an extremely terrible few years, and the reality is simply a challenging few quarters, the stock could rise considerably. The only question left is, what expectations are currently baked into AC stock?

Should you buy Air Canada stock?

The current crisis is unprecedented. That makes it extremely difficult to put a value on the company. Right now, the business generates multi-million-dollar losses on a daily basis. No company can survive this cash burn forever. If it doesn’t stop, shares theoretically have zero value.
Last quarter, the company had $5.7 billion in cash and reserves. Factoring recent cash burn and new financing likely pegs the sum at a similar figure. That means the business should have roughly two years of runway if conditions remain dire. That’s good news considering the IATA believes airlines will lose $450 billion in passenger revenue in 2020.
On a valuation basis, Air Canada trades at 0.6 times 2020 sales. Analysts predict a return to normal by 2021, forecasting a doubling in revenue, meaning shares trade at just 0.3 times forward sales. That’s two-thirds lower than the stock’s historical average.
The key here is timing. If the world returns to normal by next year, Air Canada is a clear buy. If it takes multiple years, that high upside could turn into 100% downside.
The post Will Air Canada (TSX:AC) Stock Turn $20,000 Into $1 Million? appeared first on The Motley Fool Canada.


HSE.TO stock: My speculation does not work



I tried to purchase HSE.TO at price 4.15 at the morning 6:45 AM on July 14, 2020. But I noticed that the price went up quickly in 20 minutes, went back to my original sold price 4.26. I should make judgement of the whole market, get back in. 

Now I should have recovered all my loss, 4.55 - 4.15 - 0.40/ share, total 2000 shares, $800 dollars. Also I understand that $4.15 is a low price and market will go up. I should invest more shares on this stock. At least I should consider to purchase extra 1000 share to catch up loss.  

Originally, it is better to purchase more shares when price is around $4.06 dollars on July 10, 2020. 

Actionable Items


I learned over $3000 US dollars loss lesson to purchase $15,000 on S & P 500 highest position 3300 on June 5, 2020. 

I have to write down every lesson I learn. So I will be humble and then learn how to take market risk, and then be a happy investor. 

Save all capital and invest when market crashes, and then everything is on sale again. 

Market volatility is the best friend of a long term and short term investor. Try to work hard on market, and enjoy the trade morning time, and then go to work and enjoy the work as well. 


Sabr stock: My speculation does not work

July 15, 2020

Introduction

It is so interesting to speculate the market go up or down. I learn a lesson today and I like to write down.

SABR stock position




I like to document this lesson, and tell myself that I should stay at the moment, and then it is not easy to be a speculator. The market takes a random walk.

Actionable Items


It is not easy to be patient and work hard on trading starting from early in the morning from 6:30 AM. I learn that it is important for me to get up early, so I can have time to read and learn more about how to invest as a 53 year old.

I should have got back in on July 14 and then purchase 500 share at price $7.5 dollar/ share, then I should have recovered a lot from my loss over $600 dollars.

I also should consider to purchase extra shares since it is lowest price I should get in. I should get in when the price was close to 7.0 when market crashed a few days ago.

Tuesday, July 14, 2020

Near-term uncertainty will make investors look past earnings: Expert

Here is the link.


Markets up because the Fed has filled system with liquidity: Barbara Doran

Here is the link.

Barbara Doran, BD8 Capital Partners, and David Ellison, Hennessy Funds portfolio manager join "Closing Bell" to talk about the broader markets. For access to live and exclusive video from CNBC subscribe to CNBC PRO: https://cnb.cx/2NGeIvi


TSLA stock: Tesla doesn't create big return for shareholders: Former GM vice chair

Here is the link.

Tesla had a volatile Monday session that saw its stock pop 16% only to finish lower. The stock has been on a tear, rising about 500% over the past year as investors pour money in electric vehicle stocks. With a market cap of $278 billion dollars, only 13 companies in the S&P 500 have a greater market value. Bob Lutz, former GM vice chairman, and CNBC's Phil LeBeau join "Squawk Box" to discuss the stocks wild ride. Subscribe to CNBC PRO for access to investor and analyst insights on Tesla and more: https://cnb.cx/2BT2E7y

MRNA stock: Moderna releases Covid-19 vaccine phase 1 interim results

Here is the link.




Leetcode discuss: 463. Island Perimeter

July 14, 2020

Here is the link.

C# using DFS and two hashset to remove duplicate edge count

July 14, 2020
  1. Island Perimeter
Introduction
It is my first algorithm in Leetcode mock interivew phone screen. I spent over 40 minutes to write a solution, and then passed online judge.
Design issue
The challenge is to design unique key for each edge, in order for me to remove duplicate ones, I need to specify a key using integer to represent edges of rectangle.
The idea is to use left start point for horizontal edge, and top point for vertical edge.
Also map horizontal edges to integer values smaller than 100 * 200 + 100. Map vertical edges to integer values bigger than all horizontal edges, so there is no overlap, zero possibility to mix horizontal edge with vertical edge.
If the above issues are resolved, all others are standard BFS/ DFS solution with base case, range check, visited mark etc.
public class Solution {
    public int IslandPerimeter(int[][] grid) {
        // apply DFS to visit all connected nodes
        // use hashset<int> to add all unique edges first
        // use hashset<int> to record all duplicate edge next
        // all edges will have unique id - 
        // horizontal - row, col - start point
        // vertical - row, col - up point
        // 100 - map row * 100 + col -> unique value 
        // return difference between two hashset's count value - unique one and duplicate ones
        if(grid == null || grid[0] == null || grid[0].Length == 0)
        {
            return 0; 
        }
        
        var rows = grid.Length; 
        var columns = grid[0].Length; 
        
        var hashSet = new HashSet<int>(); 
        var duplicateSet = new HashSet<int>(); 
        
        for(int row = 0; row < rows; row++)
        {
            for(int col = 0; col < columns; col++)
            {
                var current = grid[row][col];
                if(current != 1)
                {
                    continue; 
                }                
                
                runDFSSearch(grid, hashSet, duplicateSet, row, col);
                break;
            }
        }
        
        return hashSet.Count - duplicateSet.Count; 
    }
    
    /// Run BFS algorithm
    private void runDFSSearch(int[][] grid, HashSet<int> set, HashSet<int> duplicate, int row, int col)
    {
        var rows = grid.Length; 
        var columns = grid[0].Length; 
        
        if(row < 0 || row >= rows || col < 0 || col >= columns || grid[row][col] != 1)
        {
            return; 
        }
        
        // starting from top-left corner, horizontal first, vertical next
        // horizontal left->right
        // vertical top->down
        var keyEdges = new int[]{
            getHorizontalNumber(row, col), 
            getHorizontalNumber(row + 1, col), 
            getVerticalNumber(row, col),             
            getVerticalNumber(row, col + 1)};
        
        foreach(var item in keyEdges)
        {
            if(set.Contains(item))
            {
                duplicate.Add(item);
            }
            
            set.Add(item); 
        }
        
        // mark visited
        grid[row][col] = 2;  
        
        runDFSSearch(grid, set, duplicate, row + 1, col); 
        runDFSSearch(grid, set, duplicate, row - 1, col); 
        runDFSSearch(grid, set, duplicate, row, col - 1); 
        runDFSSearch(grid, set, duplicate, row, col + 1);         
    }
    
    // Do not overlap vertical number
    // all < 100 * 200 + 100
    private int getHorizontalNumber(int row, int col)
    {
        return row * 200 + col; 
    }
    
    // Do not overlap horizontal number
    // all > maximum of horizontal number < 200 * 100 + 20000
    // 
    private int getVerticalNumber(int row, int col)
    {
        return 200 * 100 + 20000 + (row * 200 + col);
    }
}


Leetcode discuss: 143. Reorder List

Here is the link.

C# Slow and fast two runners and a stack story about linked list

July 14, 2020
  1. Reorder List
Introduction
It is the second algorithm in my Leetcode mock interview. I did not have time to write the code, there are three algorithms, 90 minutes. I spent near 40 minutes on the first algorithm. and I did not have enough time to complete the code. 463. Island Perimeter is the first algorithm.
My performance goal
I am preparing for July 20, 2020 Facebook phone screen. I like to write the code with bug free in less than 20 minutes.
I just finished two linkedlist practice, one is called find loop start in looped linked list, and then second one is to merge two linked list. So I learned the lesson how to avoid the bugs in the linked list problem solving. I wrote those two algorithms since those are my previous Leetcode mock interview phone screen algorithms in the same day.
How to solve the problem?
The idea is to run the slow and fast two runners to find second half start node in the linked list, and then iterate all nodes in the linked list into a stack.
Next is to merge node from first half and node from stack into a new linked list.
The challenge
I did not practice Leetcode very often from January to May 2020, so it takes me some time to figure out how to write basic things like linked list or other challenging solutions.
In order to push myself hard, I do think that I need to change my mindset. As a software programmer, I do not have to practice algorithms every day. But it is big risk since I do not have enough challenge and therefore I can say that I waste a lot of time.
My argument is this. In order to be a competitive programmer, I should think about building good habit to code every day.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _143_reorder_list
{
    class Program
    {
        static void Main(string[] args)
        {
        }

        public class ListNode {
            public int val;
            public ListNode next;
            public ListNode(int x) { val = x; }
        }

        /// <summary>
        /// 143 reorder list 
        /// 1 -> 2 ->3 ->4 ->5
        /// result 1 ->5 ->2 ->4 -> 3
        /// next half reversed and then mix with the first half
        /// </summary>
        /// <param name="head"></param>
        public void ReorderList(ListNode head)
        {
            if (head == null)
                return;            

            var slow = head;
            var fast = head;

            while (fast != null)
            {
                if (fast.next == null)
                {
                    break;
                }

                fast = fast.next.next;
                slow = slow.next;
            }

            var reserve = slow.next;
            slow.next = null;

            var reverse = reserve;
            var stack = new Stack<ListNode>(); 

            while (reverse != null)
            {
                var copy = reverse.next;
                reverse.next = null;  // break the link please

                stack.Push(reverse);

                reverse = copy; 
            }

            // mix linked list with the nodes in the stack
            var headCopy = head;

            while (headCopy != null && stack.Count > 0)
            {
                var copy = headCopy.next;
                headCopy.next = null;

                var pop = stack.Pop();
                headCopy.next = pop;

                pop.next = copy;

                // next iteration
                headCopy = copy; 
            }            
        }
    }
}


Leetcode discuss: 328 Odd Even Linked List

Here is the link.

C# LinkedList challenge

July 14, 2020
Introduction
  1. Odd Even Linked List
It is my mock interview second algorithm. I came cross the time limit exceeded bug, so I tried to fix the issue.
To simplify the maintenance of linked list, break the node's next, set it null first; Afterwards, process node to become one node in odd linked list or even linked list.
Argue that it is a good habit to keep the rule. It helps to prevent TLE error or deadloop issue.
Will add a case study why it is important to do that.
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     public int val;
 *     public ListNode next;
 *     public ListNode(int val=0, ListNode next=null) {
 *         this.val = val;
 *         this.next = next;
 *     }
 * }
 */
public class Solution {
    public ListNode OddEvenList(ListNode head) {
        if(head == null)
            return null;        
        
        var dummyHeadOdd = new ListNode();
        var dummyHeadEven = new ListNode(); 
        var startOdd = dummyHeadOdd;
        var startEven = dummyHeadEven;
        var lastNodeOdd = head;
        int count = 1;
        while(head != null)
        {
            var reserved = head.next; // caught by online judge - time limit exceeded
            
            head.next = null; // caught by online judge - time limit exceeded 
            
            var isOdd = count % 2 == 1; 
            if(isOdd)
            {
                startOdd.next = head;
                startOdd = startOdd.next; 
                
                // keep refreshing
                lastNodeOdd = head;
            }
            else 
            {
                startEven.next = head;
                startEven = startEven.next; 
            }                        
            
            // next iteration
            head = reserved;
            count++;
        }
        
        lastNodeOdd.next = dummyHeadEven.next;         
        
        return dummyHeadOdd.next; 
    }
}


Leetcode discuss: 142 Linked List Cycle II

Here is the link.

C# Fast and slow two runners practice on July 14, 2020

July 14, 2020
Introduction
  1. Linked List Cycle II
It is common practice to have two runners, one is slow to run one step a time, the fast one is to run two steps a time. If there is a loop in the linked list, then the two runners should meet.
The place to meet in the cycle
Let me mark two places in the linked list, first one is the node position where loop starts, the second one is the place for two runners to meet first time.
Arguments:
  1. Fast one and slow should meet definitely, since fast one is behind the slow one, then every unit time the distance will be shorten by one.
  2. Define n steps from start to position where loops start denoted LoopStart. Define k step in the loop away from LoopStart meets, LoopMeet. Circle length is denoted as Circle.
  3. More one step 2, formula: 2 (n + k) = n + k + Circle, so the distance from
    LoopMeet to LoopStart is same as from beginning to LoopMeet.
Once two runners meet, then move the fast runner to the beginning of linked list, run one step a time to meet the slow runner.
There are three positons, linked list start position, LoopStart, LoopMeet; Two runners, one fast one slow, and we need third runner after slow runner meets fast runner.
Tips
Three positions - three runners - different start time - two start times.
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     public int val;
 *     public ListNode next;
 *     public ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public ListNode DetectCycle(ListNode head) {
        if(head == null)
            return null;
        
        var slow = head; 
        var fast = head;
        bool startRace = true; 
        int count = 0; 
        
        while(startRace || slow != fast)
        {
            startRace = false;
            
            slow = slow.next; 
   
   // code is simplified after mock interview
   if(fast.next == null || fast.next.next == null)
   {
    return null;
   }
   
   fast = fast.next.next; 
   
   /*
            fast = fast.next;
            if(fast == null)
            {
                return null; 
            }
            
            fast = fast.next;                        
            
            // duplicate code
            if(fast == null)
            {
                return null; 
            }
            */
            count++; 
        }
        
        // new one starts from head of linked list again, step by step
        // slow one continue
        var newOne = head;
        while(newOne != slow)
        {
            newOne = newOne.next; 
            slow = slow.next; 
        }
        
        return newOne; 
    }
}