Skip to content

Instantly share code, notes, and snippets.

View huangt's full-sized avatar

Tong Huang huangt

  • Boston, MA, USA, Earth
View GitHub Profile
import ystockquote
import csv
#print ystockquote.get_price('GOOG')
#print ystockquote.get_all('MSFT')
#print ystockquote.get_book_value('GOOG')
csvfile = open('nasdaqlist.csv', 'rb')
reader = csv.reader(csvfile)
@huangt
huangt / nasdaqlist.csv.py
Last active May 25, 2016 07:30
list of stock symbol on Nasdaq
Symbol,Name,LastSale,MarketCap,ADR TSO,IPOyear,Sector,industry,Summary Quote
FLWS,"1-800 FLOWERS.COM, Inc.",5.27,336424668.5,n/a,1999,Consumer Services,Other Specialty Stores,http://www.nasdaq.com/symbol/flws
FCTY,"1st Century Bancshares, Inc",7.6,70281022.8,n/a,n/a,Finance,Major Banks,http://www.nasdaq.com/symbol/fcty
FCCY,1st Constitution Bancorp (NJ),10.13,60727141.66,n/a,n/a,Finance,Savings Institutions,http://www.nasdaq.com/symbol/fccy
SRCE,1st Source Corporation,26.8,653265946,n/a,n/a,Finance,Major Banks,http://www.nasdaq.com/symbol/srce
FUBC,"1st United Bancorp, Inc. (FL)",7.37,252695602.7,n/a,n/a,Finance,Major Banks,http://www.nasdaq.com/symbol/fubc
VNET,"21Vianet Group, Inc.",15.97,943028500,n/a,n/a,Technology,"Computer Software: Programming, Data Processing",http://www.nasdaq.com/symbol/vnet
JOBS,"51job, Inc.",66.49,1954129996,n/a,2004,Technology,Diversified Commercial Services,http://www.nasdaq.com/symbol/jobs
EGHT,8x8 Inc,9.805,713472326.3,n/a,n/a,Public Utilities,Telecommunications Equipment,http
@huangt
huangt / ystockquote.py
Created September 12, 2013 22:58
python library to retrieve stock data from Yahoo Finance
#
# ystockquote : Python module - retrieve stock quote data from Yahoo Finance
#
# Copyright (c) 2007,2008,2013 Corey Goldberg (cgoldberg@gmail.com)
#
# license: GNU LGPL
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
Buffett bought PetroChina from 2002 to 2003. The first time we see PetroChina shows up is in 2003 annual letter.
source: http://www.berkshirehathaway.com/letters/2003ltr.pdf
From the letter we know that Buffett paid $488 million dollars for 1.3% of PetroChina. We didn't see any discussion on this position until Buffett talked about its sale at 2007 letter. Buffett did something unusual, he gave us a glimpse of his valuation for PetroChina.
Source: http://www.berkshirehathaway.com/letters/2007ltr.pdf
Let's calculate the average price Buffett paid:
according to PetroChina's 2004 annual report: http://www.petrochina.com.cn/resource/EngPdf/2004ndyj_eng.pdf
There are 175.82 billion shares outstanding. 1.3% of that is 2,285,660,000 shares. Buffett probably bought the ADR (ticker PTR trading in US). One ADR = 100 HK share, so he paid $488 million for about 22.8566 million shares of PTR, or $21.35 per share.
Back then, Buffett and Charlie valued PetroChina's intrinsic value at $100 billion, or about $56.88 per sha
# Space Invaders clone
# by davebang
from scene import *
from time import sleep
from console import *
import sound
from random import randint
screen_size = Size()
import sys
import os
import math
"""
Black-Scholes-Merton method to calculate option premium for forward or futures contract
@param callPutFlag
@param F future price
@param X strike price
@huangt
huangt / gist:5502260
Last active December 16, 2015 21:49
R
sql <- "insert into mdl_report_exclude (isin,sedol,symbol,last_upd_user,last_upd_date,cusip) values ('%s','%s','%s','huangt',getdate(),'%s')"
function(row) {
sprintf(sql, row["ISIN"], row["Sedol"], row["Ticker"], row["Cusip"])
}