Thursday, 25 June 2020

shell script

1. sha-bang #!

#!/bin/bash
# Proper header for a Bash script.


2. define all variables (UpperCase) at top at refer them later using $


3. command line argument
  • $0: command itself
  • $1: 1st argument

4. `pwd`.    //everything between `` is evaluated first


5. $?           //the exit code of previous command is stored in it


6. $(command)      //run command and return value as variable


7. i/o redirection
  • 0, 1, 2                    //stdin, stdout, stderr
  • 1>filename            //redirect stdout to file
  • 2>&1                     //redirect stderr to stdout
  • >                            //redirect, overwrite
  • >>                          //redirect append

8. sed (stream editor)

sed -n           //don't print input, always use
sed -i            //modify file in-place

echo "hello sed" | sed 's/sed/world/'                                       //hello world
sed 's+http://+https://www.cyberciti.biz+g' input.txt             //sed allow delimiter other than /
sed -i -e '/FOO/s/love/sick/' input.txt.                                    //if the line contain FOO
sed -i 's/foo/bar/gI' hello.txt                                                   //'I' to match all cases of foo
sed -n -e 's/^.*ch\([a-zA-Z0-9-]\{1,\}\).*$/\1/p' input.txt.     //+ does not work in sed, use \{1,\}


9. special character
  • $                                              //access variable
  • ${HOME}                              //return value of HOME
  • $(command)                           //return output of command, maybe separated by space !!!  
  • "$(command)"                        //return output of command as a whole
  • [   ]                                          //condition, !!! need space after [ and before ], i.e. [ 1 -lt 2 ] 
  • [ -z "$var" ]                             //$var is empty

10. awk
  • program structure

    BEGIN {awk-commands}
    /pattern/ {awk-commands}      // body
    END {awk-commands}

  • variable
    $0: a special variable in awk that represents the entire line

  • command
    awk -f command.awk marks.txt
    awk '/a/{++cnt} END {print "Count = ", cnt}' marks.txt

reference
1. special char in shell scripting
2. tldp sed
3. tutorialspoint regex with sed
4. how-to-use-sed-to-find-and-replace-text-in-files

Saturday, 30 May 2020

symbol



~   tilde
`   back quote, everything between ` ` is executed first
^  caret
*  star
(   left/right parenthesis
{  curly bracket
:   colon
;   semicolon
"  quote
'   single quote
<  angle bracket
|   pipe
#  hash
[   square bracket

Tuesday, 26 May 2020

stock

1. terminology
  • ttm: trailing twelve month
  • eps: earning per share
  • beta: volatility of stock, if a stock move less than market, beta < 1.0
  • earning date: last financial report date
  • ex-dividend date: if purchase the stock after the date, will not get the next dividend
  • peg ratio (<1.0 is good): pe ratio adjusted on growth
  • free cash flow = operating cash flow - capital expenditure
  • issuance of debt: 借债
  • stop-loss order: will turn into a market order once price is hit
  • short squeeze: stock price rise sharply to squeeze the shorters
  • short ratio: % of stocks that are being shorted
  • price/book ratio (<1.0 is good)
  • equity value/market cap: # of shares * share price
  • enterprise value: equity value + debt - cash
  • cagr: compound annual growth rate
  • operating/profit margin: profit margin only consider cost of production, operating margin consider operating expense

2. warren buffett income statement
  • net income
  • profit margin
 
3. 止损止盈抄底
  • 设止损
  • 最好不要抄底,抄底也要抄在support才有意义(1M或1Q均线)
  • 根据cis散户理论,第一次下跌可以ignore,第二次下跌要离场
  • 根据知乎理论,每次下跌5%要减仓一半
  • 盈利不好的公司出财报前减仓一半以防大跌
  • 6月份一般没有行情
  • 3 day rule: never buy for at least 3 days after bad news as it will fall for 3 days 90% chance

4. 投资策略
  • VIX > 30 price low考虑买,VIX < 20 price high 考虑卖
  • 30%长持,30%根据vix高抛低吸或做波段,30%大跌抄底

5. 短线指标




  • 下跌过程中出现锤头线或倒锤头线
  • 上涨过程中出现锤头线或倒锤头线
  • RSI顶背离:股价上升,RSI下降                 //RSI表示买方力量
  • RSI底背离,股价下降,RSI上升
  • BBI                                                                   //多空线

6. 日内指标
  • VWAP 1分/3分/5分/15分,主看3分
  • MAVOL

7. 均线
  • 5日均线:强庄线 。个股沿着5日均线运行,表明庄家正在拉升,不破均线不用担心。
  • 30日均线:庄家生命线 。个股沿着30日均线运行,表明庄家还在。
  • 不同分时图如出现同一个位置的均线点,基本可以确定其具有较大的强度。比如说在60分钟图某条均线形成支撑位,而30分钟的另一条均线的支撑位恰好一样,15分钟5分钟也是,这样这个支撑点就非常强,甚至有80%机率可获支撑。 这个对于短线操作或者买卖操作很重要,是如何买在最低,卖在最高的要诀

7. do/dont
  • try to buy industry leader
  • don't buy at 52 week high
  • don’t buy airline/cruise, be cautious with medical and telecom
  • when to buy dip (缩量下跌)
  • don‘t set a small amt trailing stop limit order (被恶意洗盘震荡卖出)
  • 试探盘要少量,否则很难cost average down
  • 盘前只高卖不买,开盘做超短线,收盘后正常操作

7. trailing stop loss sell 
  • trigger is set on a dollar or % drop of market price
  • example: bought a stock at $10, then set a trailing stop-loss order to 10% below market price
  • trailing amount: 最大下跌幅度
  • stop: 触发价
  • limit: 卖出价
  • limit offset: 从stop来算limit, limit = stop - limit offset, 不直接指定

8. others
  • check warren buffett, soros
  • check yahoo finance 'analysis' tab for rating and target price

9. leverage ETF
  • it is best to hold 1X bull ETF for long term saving
  • when the market corrects then convert to 2X or 3X bull until it recovers
  • the market corrections will kill you and leveraged ETF have decay

10. 澳洲持有股票12月以上获利按50%交税,为避税
  • 持有超过一年
  • 持有一个portfolio,财年前把亏钱的仓位全部realise



reference



Tuesday, 31 March 2020

powerpoint

1. menu -> design to choose popular themes

2. quick access toolbar
  • align objects
  • align text
  • distribute horizontally/vertically
  • group

3. slide master and sub-master slide
  • slide master: base class of all slide, change its style changes all

4. animation panel (to edit the sequence of animation)
  • fade
  • fly-in

5. add a grey book and send to back as background

6. smart art is useful to draw diagrams

Tuesday, 25 February 2020

deep learning


1. concepts
  • neuron (input -> output)
  • input, weight, bias      u=∑w*x+b
  • activation function     y = f(u)
  • cost/loss function
  • overfitting: statistically correspond too closely

2. type of activation functions
  • sigmoid
  • relu
  • softmax (convert to probabilities that sum up to 1)

3. tensorflow
  • tensor: n-dimension vector
  • inception v3, a neural network that's pretrained for image classification
  • top layer - right most output layer
  • bottleneck layer - layer just before the top layer


reference
1. 25 must know concepts
2. quickly setup google’s tensorflow image recognition
3. deep Learning with tensorflow: part 2 — image classification

Wednesday, 1 January 2020

useful javascript functions

1. spread operator ...

2. for ... of iterator

3. includes()

4. some()     //if some element in array pass the test

5. every()    //if every element in array pass the test

6. filter()     //filter the array that pass the test

7. map()     //convert the array

8. reduce()    //reduce to array, number, object

9. find()

ref
1. 7-javascript-methods-that-will-boost-your-skills
2. Most Useful JavaScript Array Functions
3. most-useful-javascript-methods