博文

2019/08 美国股市风险分析

图片
Cyclically adjusted price-to-earnings ratio CAPE p/e 这几天看了诺贝尔经济学奖得主Robert Shiller《非理性繁荣》,其中谈到了通过price earnings ratio衡量市场价格的方法[3]。 他的方法比较特殊,拿s&p 500 的价格除以过去10年窗口的inflation adjusted earnings 平均值,而不是去年的earnings。 https://www.multpl.com/shiller-pe ,  http://www.econ.yale.edu/~shiller/data.htm   为什么要看10 year average 不看去年的呢? 根据席勒的feedback理论,泡沫发生过程中会有一个正反馈,earnings也顺势增长,但其实只是一种错误的信号。比如2007年7月泡沫顶端,p/e 只有1520/82 ~= 18.5[8]。同理下跌的时候有一个负反馈,2009年六月,p/e到了123[8],earnings只有7。 看10year average,可以average out这种spike date s&p 500 index dividend earnings 2007.07 1520.71 26.44 82.81 那么是否是earnings真的下降的如此剧烈呢? 两年间earnings下降了大约90%。 看几个例子, 微软,2009年较2008年net income, 从17b下降到了14b, 下降了20%[9]。 Ford 2008 年 loss 14b[10], 2007年loss 2b,但是2009年又扭亏为盈了。这种公司和经济形式关系最为密切 At&t 只下降了不到2% [11] 首当其冲的银行股, boa, net income 从14b下降到4b, [12] 普通p/e 2014 年他在纽约时报[1]中提到了25以上就已经高了,但2019/08 已经到了30左右。如果不看席勒的p/e 分析,s&p 500 现在p/e 只有21[2]。 21是否高呢,相比其他市场日经指数p/...

中国城市房地产分析

简介 到2018年中国房地产似乎出了大问题,有的地方开始调控政策,海南的限购,西安却开始吸引人才计划,2018年一个季度人口增加30万,3%,房价也随之猛烈上涨。 有的人说房地产要崩盘了,不是政府压着早就破了; 有的人说中国的房地产泡沫不是全局现象,泡沫不大,而且政府控制着不可能破灭,如果政府不控制,涨的更厉害。 政府主流媒体的认为现在买房都是刚需,政府不能让房价迅速上涨。 那么这么多观点究竟谁说的对? 先分析以下是否是刚需,如果是的话为什么要调控呢? 刚需指的是需求大,但是供应少。按照市场规律,这时候价格会上涨,供应会随之增加,供应增加以后价格会下降,最终达到一个平衡的状态。所以如果是刚需的话,政府采取的方式应该是提高供应,方法是地方政府批更多,更便宜的地给开发商。但是,政府现在批的地没有增加很多(全国的开工面积是增加的2017 年1.7B平米, 2010年1.6B平米;北京2017年新开工12M平米,2008年11M平米),主要采取的方式是限制贷款,限制购买,和限制价格的三限制政策。 为什么会这样?一种可能是刚需是假的。造成需求大的原因有:人口增长(中国城市化不可避免的,城市人口从10%到60%;资源分配集中在大城市,更多的医疗,学校,工作,基础设施,北京2010年大约20M,现在21M,2000只有13M);收入增长(收入在过去二十几年里面翻了十倍,有些地方房价也涨了10倍,有的地方涨的更多);租房价格增长(alternative)(北京租金2016大约71每平米,2018年88每平米, 2008年大约53每平米)。 注意中国的平均数据不能反应各地的实际情况。 拿全国的数据来说,先分析以下需求,首先是人数增长,2013年城镇人口731M, 2017年813M,增长了11%。房地产竣工面积非常稳定大约每年0.7B平米,按照每个城市人均30平米计算,80M的新增人口需要2.4B平米的住房。销售面积每年都超过1B平米,并且统计局表明销售面积不包括二手房,因为期房预售的情况比较普遍,房子还没竣工就卖了。所以等于说这五年卖了超过5B平米的房子,但是需求只有2.4B。 原因之一应该是已有住房的人,想要更多的人均住房面积,住更大的房子。平均到2013年731M的城市人口上每个人增加了3平米,似乎也是合理的。目前城市人均住房面积大约是36平米,2012年32平米,基本和之前估...

如何提高员工的积极性

记得小时候学过,中国采取的是按劳分配,多劳多得,少劳少得。但是作为社会主义国家,如果多劳动的人赚到的钱多了,不能用来购置资本,所以只能用来消费,可以租更大的房子,买更好的汽车,吃更好的食物。 一开始在大公司上班,公司采取的是年薪加奖金制度。年薪部分是固定的,干多干少都是一样的钱,奖金部分是根据每个人的贡献多少决定的。但是有意思的是,干的多的人奖金有15%,干的少的人也有10%,如果非常差的人会被开除。这样就打击了有能力多付出员工的积极性,所有的人都会趋向于平庸。其实评价一个人付出多少是很难的,尤其是技术性,创造性的工作。对于一个普通生产工人来说,可以用他生产产品的数量来发工资,比如富土康张全蛋一天组装一个手机10块钱,这样就促进了他的积极性。 对于创造性的工作怎样衡量呢?一种方法是同级评价,让同事之间互相匿名打分。这样也不是完全公平,有可能平时比较活跃的员工会得到跟高的评价,但是并不一定干的最多。这种奖励需要有明显的区分才有效果,比如Netflix,奖金差别非常大,不然大家就会趋向于平均。也可以通过非金钱的奖励,比如更员工评级,并且让干的好的员工做管理上或者技术上的领导。当前不需要任何奖励,可以画饼充饥。聪明的员工应该衡量这张饼画的有多大,实现的可能性,以及自己当前的损失做一个对比。比如阿里的蔡崇信选择阿里放弃500万年薪。

4/21/18

美国正式开始7年制裁中兴。 一个月前,中美贸易站刚刚打响。中国对美国猪肉等产品征收关税。国人拍手称快,说中国已经站起来了,可以和美国公开叫板了。 现在对ZTE的制裁,大家又普遍说中国科技实力还是不行。Trump的制裁让我们认识到这一点。 都是政府主导的舆论,感觉有些奇怪。中兴在两年前就曾经被暂停与美国的一切交易。如果敲响警钟,当时不久应该敲响了? 今天朝鲜宣布“改革开发”,努力发展科技,教育,停止核武器研究。一个月前金正恩刚访问了北京,同时trump说五月要访问朝鲜。

Python 去除中文标点

import re s = "好多标点,。!?【】" punctuation = "[|•·゜:》《\[\]\-\d+\s+\.\!\/_,$%^*(+\"\')]+|[+——()?【】“”!,。?、~@#¥%……&*()]+" print(re.sub(punctuation, "", s))

How to make Xinjiang Dingding chow mien and dough

图片
如何制作新疆丁丁炒面?

五分钟学会做新疆拌面

图片

五分钟搞定 Tensorflow

图片
四十行代码,用tensorflow 识别图片中的数字

什么是Recurrent Neural Network

图片
什么是Recurrent Neural Network? 循环神经网络 / 递归神经网络 ( Recurrent Neural Network ),主要解决的是 序列 类的问题,有时候顺序非常关键。比如,我喜欢苍老师的电影,和苍老师喜欢我的电影,意思完全不同;我想和马云爸爸一样有钱和马云爸爸想和我一样有钱,意思也完全不同。 那么RNN是如何工作的呢? 最重要的就是这个公式,当前状态由,上一个状态和当前输入而决定 ht 带表当前时刻的隐藏状态hidden state, ht-1就是上一个状态的hidden state, xt, 是当前时刻的输入 我    喜欢    星球大战 举个例子,我喜欢星球大战,把这句话,分成三个词,x0 是我,x1是喜欢,x2是星球大战 h0 由初始状态,和x0, "我" 来决定 h1  就由h0和x1"喜欢"来决定 h2 由h1, 和x2 "星球大战"来决定 ht-1 乘以它的weight Wh 加上 Xt 乘以它的weight Wx 两个相加, 经过激活函数tanh, 最后就得到ht了 Wh, Wx, 都没有下角标t, 所以这两个weight 是由各个时刻共享的 训练的过程就是更新这两个weight的过程,把它们优化成最佳值 刚才讲的是最基础的RNN模型,下面看一下encoder/decoder 模型是如何利用RNN 来对诗的 Encoder/Decoder 顾名思义,由两个部分组成 encoder 部分的输入是已知诗的第一句,举个例子,床 前 明 月 光,五个字, decoder 部分的输入是encoder 的输出,加上自己的上一次输出。 比如说,预测第一个字,因为decoder 自己还没有输出,所以用起始符,来表示自己上一次的输出,加上encoder 处理床前明月光的输出,这样decoder 就输出了,疑这个词 预测第二个字的时候,疑这个字就变成了输入 假设刚才输出不是疑这个字,输出了低这个字,那么预测第二个字的时候,低就变成了输入 假设预测第五个字输出是霜,预测第六个字的时候,霜变成了输入,输出是终止符,表示不用...

机器学习 梯度下降

图片
machine learning gradient descent

machine learning linear regression

图片

Paper reading: Efficient Estimation of Word Representations

图片
From google brain: https://arxiv.org/pdf/1301.3781.pdf projection layer : 投射层,maps word index to continuous vector space. ("hidden layer is removed") projection layer input 可能是一个one hot encoding 的 vector, 就是第i个word,除了位置i是1,其他全是0。这个层没有softmax, 只是单纯的投射过程。 http://mi.eng.cam.ac.uk/~gwb24/publications/mphil.thesis.pdf 之前的 forward neural network, 用前面的词来预测这个词w(t) Bag of words : 通过周围的词 (context),预测这个词 w(t)。不仅之前的词,被用到,之后的词也被用到。当然这个之前之后是有限制的 (time step)。 Skip gram : 通过这个词 w(t), 预测周围的词 最开始的input 应该都是one hot encoding value 最后的word vector 应该就是这个projection layer对应的weight, 每个词都会有一个N dimensional vector 表示,这个N可以是自定义的 比如2D result Library gensim https://radimrehurek.com/gensim/models/word2vec.html N 用size 来表示 sg=1 如果想用skip gram Tensorflow word2vec:  https://www.tensorflow.org/tutorials/word2vec

无为和有为

今天看费孝通的《乡土中国》,上面提到两种生活态度,阿波罗式的和浮士德式的。 阿波罗式的态度指遵循宇宙已有的规律,不做任何改变,我们需要做的只是生活在其中。有些像老子的 “大道无为”,最好的君主治理国家,就是什么也不做,做的越多就越有可能犯错误,同时也更加不满足现状,不光是治国,平时的生活也是如此。“五色令人目盲;五音令人耳聋;五味令人口爽;驰骋畋猎,令人心发狂;难得之货,令人行妨。是以圣人为腹不为目,故去彼取此。“ 记得第一次看到这个是在老子的千字文里面读到的,当时觉得玄的东西就很彰显个性,所以很喜欢,但是不是很懂其中的意思。人的心接触的越多,就越难以满足,所以不如从干脆克制自己内心出发。 我想起犬儒主义代表人第欧根尼,亚历山大拜访他的时候,他在晒太阳,所有财产只有一根棍子,斗篷,面包袋,木桶,亚历山大问他需要什么,他说我希望你闪到一边去,不要阻碍我晒太阳。他们不希望对社会做什么贡献,需求也极为简单,当然这个做法,有些极端。 另外就是叔本华的悲观主义哲学,他认为人类不断的追求,追求之后达到目标就是空虚,好像西西弗斯不断的往山顶推石头,推到了再掉下来重新推。 这几年流行的极简主义一部分也有这个意思,尽量精简生活所需。典型的设计有苹果,muji 另一方面浮士德式的生活态度,与极简主义截然不同,浮士德与魔鬼达成契约,说自己的追求是永远得不到满足的,如果满足了,魔鬼就可以把他带走,他则不停的向魔鬼提出各种愿望。变得年轻,富有,智慧,总是有许多新鲜想要的东西。尽管最终,浮士德帮助老百姓免受海浪侵袭,终于向魔鬼说满足了自己的心愿,但是他还是代表了一种不断追求的精神。 我很崇尚极简主义,生活上减少没有必要的愿望,但也不会走极端,还是有自己的追求,但是这个追求不应该是物质上的,更多应该注重在精神上。

WordNet BFS Shortest Path

图片
WordNet is a graph which represents a set of words,  Synset can be interpreted as a set of words, which have same/similar meaning,  For example AND_circuit AND_gate, have similar meaning "a circuit in a computer that fires only when all of its inputs fire" The Hypernym of a synset is a more general form of this synset, for example, "gate" is the hypernym of synset "AND_circuit AND_gate" and "OR_circuit OR_gate" (from priceton wordnet digraph) To find the distance between two synsets, we can use BFS,  First of all we need to build graph, after that we can run BFS 1. run BFS on synset1, Complexity (V+E), we can get distance from synset1 to each synset 2. run BFS on synset2, Complexity (V+E), we can get distance from synset2 to each synset 3. Iterate through all synset and calculate the minimum of distance_to_synset1 + distance_to_synset2 Complexity (V) Thus the total complexity is (V+E) In reality a word ma...

Increasing Triplet Subsequence LeetCode

For the three increasing number, it’s quite easy, we just need to find a number which has one number smaller than it, and one number greater than it, so I used to arrays, one is used to keep the maximum number on the right, the other is used to keep the minum on the left, then loop the array again to find a number which is larger than left minum and smaller than right maxium class Solution(object): def increasingTriplet(self, nums): """ :type nums: List[int] :rtype: bool """ l = len(nums) if l < 3: return False less = [0] * l great = [0] * l minimum = nums[0] maximum = nums[-1] i = 0 while i < l: minimum = min(nums[i],minimum) less[i] = minimum i += 1 i = l - 1 while i > 0: maximum = max(nums[i],maximum) great[i] = maximum i -= 1 i = 0 while i < l: if nums[i] > less[i] and nums[i] < great[i]: return True i += 1 return False

Counting Bits Leetcode

Runtime:  791 ms We should divide it into even number and odd number, if the number is odd, then number of ones = ones of previous number + 1 if it's even number then the number of ones = number of ones of this number shift to right by 1, which is already known

Palindrome Pairs Leetcode

I used python hash table, first add all words to dictionary, then for each word partition it check if the reverse of first half/second half is in dictionary, if it is, add it to result. One tricky input is when word is empty, we have to consider it. The complexity is O(n*m) where m is the word length, and n is total number of words The method is not very efficient 134 / 134  test cases passed. Status: Accepted Runtime:  872 ms Submitted:  31 minutes ago class Solution(object): def isPalindrome(self,word): return word == word[::-1] def generatePairs(self,index1,index2): s = "{},{}".format(str(index1),str(index2)) return s def palindromePairs(self, words): """ :type words: List[str] :rtype: List[List[int]] """ ret = [] d = {} pairs = {} for i,word in enumerate(words): d[word] = i for word in words: for i in xrange(0,len(word)+1): first_rev = word[:i][::-1] if first_...

San Diego Real Estate Risk&Profit

I used the data from Federal Housing Financing Agency , and analyzed the house price index of San Diego Carlsbad Area over 25 years, from 1991 to the end of 2015 Using the first quarter of every year The standard deviation is about 7% and annualized return rate is about 4%, compared to S&P 500 standard deviation about 15% and 10% return (about 12% for large cap,  and 15% for small cap ) Considering this value, the sharp ratio is lower than investing the stock market, But it still outperforms some fund, for example this one ONECX , it has 11% stdev and 4% return over 15 years. However, if the home is bought as an investment, it will be lucrative. For example, if a house is 230K, we put 200K as downpayment we rent it for 1K per month, after three years, the house will worth about 260K,  we will make a profit of 380K, in three years, even if we want to sell it, and we pay the commission which costs 150K, we still make a profit of 230K, that's about 15% annual retu...

Count of Smaller Numbers After Self

Count of Smaller Numbers After Self First I thought start from the end, for each element look right and find the first number which is smaller than it, then c[current] = c[firstsmall]+1, it turns out to be wrong in case [2,0,1], the correct should be move from the end and keep the array on the right of current element to be sorted, My first solution is insertion sort, but it results in time limit exceeds error, the complexity is nlg(n), if we don't consider the time used in copy array, to find the index where current number will be inserted is easy, just use the binary search, since it's already an sorted array class Solution(object): def countSmaller(self, nums): """ :type nums: List[int] :rtype: List[int] """ l = len(nums) i = l-1 self.sorted = [] ret = [] while i>=0: num = nums[i] index = self.getindex(num) self.sorted = self.sorted[:index]+[num]+self.sorted[index:] ret.append(index) i-=1...

Ugly number II python

https://leetcode.com/problems/ugly-number-ii/ The idea is to keep three pointers, each pointer points to a position in the stack each number in the stack will be multiplied by 2,3,5 class Solution(object): def nthUglyNumber(self, n): """ :type n: int :rtype: int """ d = {} stack = [1] p1,p2,p3 = 0,0,0 i = 1 ret = 1 while i<n: u2,u3,u5 = [stack[p1]*2,stack[p2]*3,stack[p3]*5] cmin = min(u2,u3,u5) if cmin == u2: p1 +=1 if cmin == u3: p2+=1 if cmin == u5: p3+=1 i+=1 stack.append(cmin) return stack[-1] The same solution can be used for super ugly number def nthSuperUglyNumber(self, n, primes): stack = [1] l = len(primes) assert(l!=0) pointers = l*[0] while n>1: minnum = stack[pointers[0]]*primes[0] for i,p in enumerate(pointers): minnum = min(stack[p]*primes[i],minnum) for i,p in enumerate(pointers): if minnum == stack[p]*primes[i]:...