2020 再一次清零

今年2月股灾 在最高点冲进去买了石油股、部分科技股。股票大跌,很慌,想回本,于是把股票的钱换成了做多的option, 亏到快清零。3月接近最低点割肉后至今,中间试图重新进去操作option,都无果而终。最近下定决心不再搞option,专心工作。

工作7年,股市里一共亏了前后有38万美金了。去年做空3倍黄金 还额外加了杠杆 亏了·12万;今年亏了16万。2013-2018年一共亏了10万。巨额亏损,给我的心里留下巨大的阴影。痛哭了几天,消沉了几个月之后,我相信自己可以重新站起来。

这一次下定决心再也不碰高风险。反思自己的金钱观有重大的问题。钱,亏了就亏了,不要再去想赚回来。从今往后好好赚钱好好做稳定的理财、长期股票投资,投资不能牺牲自己、家庭的生活质量,所以要做稳当、风险防抗好的投资。不去嫉妒、悔恨自己没有做的交易。不要相信有什么方法可以保证预测股票走向。

2020年,从头开始。不要妄自菲薄,不要苛求别人。

Counting sort, bucket sort, radix sort

We comparing counting sort, bucket sort and radix sort, i realized it’s all about trade off between memory, time, and simplicity of data structure.

Radix sort: n log_r(k). Essentially radix sort performs bucket sort log_r(K) times. It can deal with larger key range (than bucket sort).    r is the base here. the larger is r the better time complexity we got.  but it also means more memory. remember the bucket   array in radix sort is of length r (shorten than n or maximum value of K)  If we use n as the base, it becomes a normal bucket sort. why?   cuz now we have only one ‘digit’, so we only do one bucket sort/counting sort.

Bucket sort: is a generalization of counting sort. The number of bucket sort used  is n. and range can be larger than n. thus we saved some space than in counting sort. but it loses the worse case of O(n+K).  the data has to be uniformly distributed.

Counting sort: O(n+k) time and O(K) space

重新来过

来美6年半了,读书3年,工作3年半。

从去年开始到现在,所有的积蓄在股市亏光了,玩短期option进入了赌博模式,前后大概亏了12万美金。去年亏了7万,当时想收手了,说要把钱交给老婆管,复习了几个月刷题跳槽成功,今年年初老婆在复习考NY Bar,没空管理家里财务,我又鬼使神差的重新进去想回本,结果一把我又亏了5万。银行里现在一共也只有1万不到。

自己平时生活节约,结果到头来全部输给了股市。

赌徒的日子,太痛。哭了好几天,于事无补。生活还得继续。

对不起自己刚结婚的老婆,对不起父母,工作几年,没给家里寄过几次钱。

恍惚了很多天了。28岁的我,现在清零,从头开始。

San Francisco City Hall Wedding Guide

http://www.redeyecollection.com/san-francisco-city-hall-wedding-photography/how-to-get-married-at-san-francisco-city-hall/

You can either get the marriage license on the same day or beforehand. you should at least get the marriage license 30 minutes before the ceremony.

you can get the marriage license in other city hall within California.

Santa Clara City Hall:  https://www.sccgov.org/sites/rec/Marriage%20Licenses/Pages/Applying-for-a-Marriage-License.aspx

 

Everything about Python Dict

This is a  great post I found on stackoverflow.

http://stackoverflow.com/questions/327311/how-are-pythons-built-in-dictionaries-implemented

 

Here is everything about Python dicts that I was able to put together (probably more than anyone would like to know; but the answer is comprehensive).

  • Python dictionaries are implemented as hash tables.
  • Hash tables must allow for hash collisions i.e. even if two distinct keys have the same hash value, the table’s implementation must have a strategy to insert and retrieve the key and value pairs unambiguously.
  • Python dict uses open addressing to resolve hash collisions (explained below) (see dictobject.c:296-297).
  • Python hash table is just a contiguous block of memory (sort of like an array, so you can do an O(1) lookup by index).
  • Each slot in the table can store one and only one entry. This is important.
  • Each entry in the table actually a combination of the three values: < hash, key, value >. This is implemented as a C struct (see dictobject.h:51-56).
  • The figure below is a logical representation of a Python hash table. In the figure below, 0, 1, ..., i, ... on the left are indices of the slots in the hash table (they are just for illustrative purposes and are not stored along with the table obviously!).
    # Logical model of Python Hash table
    -+-----------------+
    0| <hash|key|value>|
    -+-----------------+
    1|      ...        |
    -+-----------------+
    .|      ...        |
    -+-----------------+
    i|      ...        |
    -+-----------------+
    .|      ...        |
    -+-----------------+
    n|      ...        |
    -+-----------------+
  • When a new dict is initialized it starts with 8 slots. (see dictobject.h:49)
  • When adding entries to the table, we start with some slot, i, that is based on the hash of the key. CPython initially uses i = hash(key) & mask (where mask = PyDictMINSIZE - 1, but that’s not really important). Just note that the initial slot, i, that is checked depends on the hash of the key.
  • If that slot is empty, the entry is added to the slot (by entry, I mean, <hash|key|value>). But what if that slot is occupied!? Most likely because another entry has the same hash (hash collision!)
  • If the slot is occupied, CPython (and even PyPy) compares the the hash AND the key (by compare I mean == comparison not the is comparison) of the entry in the slot against the key of the current entry to be inserted (dictobject.c:337,344-345). If both match, then it thinks the entry already exists, gives up and moves on to the next entry to be inserted. If either hash or the key don’t match, it starts probing.
  • Probing just means it searches the slots by slot to find an empty slot. Technically we could just go one by one, i+1, i+2, ... and use the first available one (that’s linear probing). But for reasons explained beautifully in the comments (see dictobject.c:33-126), CPython uses random probing. In random probing, the next slot is picked in a pseudo random order. The entry is added to the first empty slot. For this discussion, the actual algorithm used to pick the next slot is not really important (see dictobject.c:33-126 for the algorithm for probing). What is important is that the slots are probed until first empty slot is found.
  • The same thing happens for lookups, just starts with the initial slot i (where i depends on the hash of the key). If the hash and the key both don’t match the entry in the slot, it starts probing, until it finds a slot with a match. If all slots are exhausted, it reports a fail.
  • BTW, the dict will be resized if it is two-thirds full. This avoids slowing down lookups. (see dictobject.h:64-65)

NOTE: I did the research on Python Dict implementation in response to my own question about how multiple entries in a dict can have same hash values. I posted a slightly edited version of the response here because all the research is very relevant for this question as well.