股市狙擊手的自白讀後感
趁著四月初這波長假看了這個幾個台灣股市幾個知名人物推薦的書,在心路歷程記錄類的算是不錯的,個人是覺得比 MGK 那一本寫得要好多了。書裡面並沒有著墨於什麼技巧,比較特別的是他是在有小兒科醫生本職的情況下發展出一套靠槓桿,單壓一支股票,一年最多做五隻波段的方式讓資產在過去幾年翻了 500%。在 PTT 也有看到在台股用單壓的方法在過去幾年翻了數倍的人,一個我知道的是 mytropicfish,另一個企鵝。只是兩位似乎都沒有用槓桿只是壓很重。而企鵝在 2022 年繼續單壓但獲利大幅回吐。其實不確定這樣的方法是不是在過去幾年比較容易回下來,所以要複製可能要小心近因偏誤就是。我個人比較相信 mytropicfish 重壓台股冷門股的方式比較有可能被複製,只是台股相對歐美法律在公司治理上還是比較不規範,在台股重壓冷門股可能都要對老闆做好盡職調查,而且最好是偏生活類股你可以用 side channel 去驗證減低詐騙的機率就是,而且台灣的利率還是相對低的。在低利率又容易借到錢的環境下公司都不太容易爆掉,所以重壓很可能 make sense,連各種騙錢的 stonks 都可以飛天了,只是不是經營太差的理論上更不可能爆掉,只要等到題材然後飛天就可以了。在 2023 年美國利率已經升到近 5% 又加上中小銀行的 credit crunch,在美國鐵定是最好不要這樣複製。台灣也許還有機會,不過 2% 可能對於槓桿槓太多的公司還是一大逆風。邏輯思考下這樣的作法有可能有它時代背景的限制在,除非確定在選股上有異於常人的優勢,不然實在不推薦在 2023 年複製用這樣的作法。不過把這個做法擺在心中,也許十年二十年後,另一波潮流來臨時,可以記得這樣的做法在那個時候把握時代的優勢。
另一點有趣的是作者是在另有本職的情況下辦到的,在另一本社畜的財務自由計畫的作者也是如此。兩個作者在韓國股市都是用 Swing Trade。不確定韓國股市有多 efficient,有鑑於台灣產業跟韓國產業組成沒有差太多的情況下 (週期強的半導體產業組成為重),台股應該也辦得到吧。mytropicfish 分享的也是在他有本職的情況下做到的,在他文章中也說到其實在有本職,特別是管理職的情況下,對於生意本職有敏感度反而對於產業的趨勢有把握,能夠做得不錯。變成全職之後雖然自由但也有各種不方便 (像是不易貸款,要擔心生活的現金流,失去產業敏感度,失去社交圈)。對於做美股這麼有效率的市場是否能辦到我就不確定了。不過有本職且操作不錯的這種生活型態很接近我理想中的狀態,有了工作的現金流對於心態上也會比較穩定。希望我有朝一日也能辦到。
書的後段著墨於心理面,特別強調當低潮的時候如何改善,還有當不順的時候可以對股票失去信心但不能對於自己失去信心。這其實跟我這幾年的摸索很像。而且這也不僅僅是股票市場而已。其實人生各方面都是如此。文字寫得精煉但也許只有走過一遭的人才能體會箇中深意,如果沒有經驗的話可能並不會對於他的文字有所共鳴。我特別喜歡一個段落就是把目標設定過高而躁進反而讓自己操作亂掉的經驗,當失望而沒有想太多去操作的時候,反而一切開始改善。這也跟快樂操盤人講得慢慢來比較快一樣。當有了貪念而心態亂掉的時候,反而讓自己的步調亂掉。把眼前的事情做好不要想太多,慢慢累積並且當時機來臨的時候自然會水到渠成。書本的這段章節看起來是對於內心是特別療愈就是。
zw-fast-quantile: Approximate Quantile for high-speed data stream in Rust
A couple of weeks ago I exchanged messages with ljw1004, where he was surveying fast quantiles implementation in rust. He conducted a thorough benchmark against the GK01 and CKMS algorithms in the postmates/quantiles crate, in order to understand the tradeoffs among the error rate, memory usage and the update/query time. He mentioned the Zhang Wang algorithm in a literature review, where I later found that it was actually adopted in the boosted tree implementation in Tensorflow. I got intrigued and decided to roll my sleeves and give it a shot to implement the algorithm in rust
I spent a few days to read the paper and read the reference implementation done by jasonge27 in C++. The C++ implementation only implemented the fixed size approach in the paper but lack the generalized approach to support the online streaming update. I read the paper carefully and implement the generalized algorithm and then we have zw-fast-quantile crate.
The naive benchmark with criterion shows that the update operation is 2.6x faster than GK01 implementation in postmates/quantiles
zw unbound quantile update
time: [60.780 us 60.855 us 60.936 us]
change: [-1.4032% -0.9510% -0.5005%] (p = 0.00 < 0.05)
Change within noise threshold.
Found 8 outliers among 100 measurements (8.00%)
2 (2.00%) high mild
6 (6.00%) high severe
gk quantile update time: [156.84 us 157.02 us 157.24 us]
change: [-0.1907% -0.0503% +0.0969%] (p = 0.50 > 0.05)
No change in performance detected.
Found 11 outliers among 100 measurements (11.00%)
6 (6.00%) high mild
5 (5.00%) high severe
and query operation is 1.5x faster than GK01
zw unbound quantile query
time: [229.62 ns 230.16 ns 230.77 ns]
change: [+1.3422% +1.8105% +2.2504%] (p = 0.00 < 0.05)
Performance has regressed.
Found 11 outliers among 100 measurements (11.00%)
3 (3.00%) high mild
8 (8.00%) high severe
gk quantile query time: [350.21 ns 350.48 ns 350.76 ns]
change: [-0.4638% -0.3109% -0.1670%] (p = 0.00 < 0.05)
Change within noise threshold.
Found 8 outliers among 100 measurements (8.00%)
1 (1.00%) low severe
2 (2.00%) high mild
5 (5.00%) high severe
It matches with the emprical study from the paper that it is able to achieve 200-300x speedup over GK01.
To benchmark the memory usage, by storing complete 100M values in the Vec
and calculating the quantiles is using up 7812k
of heap, and with the error rate set to 0.01
the zw-fast-quantile
is only using up 1947k
of heap. It looks like it fulfills the goal of approximate quantile by saving the storage size without sacrificing the precision too much.
Implementing zw-fast-quantile
is a lot of fun and I learned a lot. By reading the review paper now I understand we can categorize the approximate quantile algorithm by different use cases. They could be
- Streaming Model: Your data would arrive one by one and you might not know the size of your stream beforehand. You should be able to calculate the result in one pass without blowing up the memory. You might also improve the algorithm complexity if you know that you just gonna query the quantiles for the trailing N values.
- Distributed Model: where you have a network of nodes, each of them have some values. However, the communication cost is high and you would like to avoid the communication cost as much as possible.
- Update Time: In the real-time application like video/audio streaming, your data update would be very fast and it requires you the low latency on your update time. You would like to strike a balance between update time and the space complexity and accuracy.
- Data Skewness: The famous t-digest would leverage on the fact where the error percentage is more imporatnt to the 99th percentile than 50th percentile. By leveraging the data skewness you can invent another set of algorithms.
zw-fast-quantile
is falling on the category 3, and it is good to know that it influenced the implementation in Tensorflow’s boosted trees. It could be another handy algorithm put in your toolbox and use it when the use case is right.