# 资产组合与市场机制

Online course from Coursera & Udacity

## Portfolio Management

• Expense ratio
• Used by mutual funds & ETFs
• Usually less than 1%
• “Two and twenty”
• Classic structure for hedge funds.
• 2% of assets under management + 20% of the returns.
• 1M with 20% per year = 60k per year
• How/Why different?
• 共同基金或者ETF基金经理目标是增大基金数额来赚取管理费
• 私募基金或者对冲基金经理目标是提高基金收益

### How to Attract Investors

• 资金来源
• Individuals
• 个人投资者，资金占比较少
• Institusions
• 机构投资者
• Harvard Foundation
• CalPERS
• Funds of Funds
• 来自其他基金的投资
• Two Main Types of Fund Goals
• Reference to a benchmark
• 有指标参考，比如跑赢S&P500等
• Absolute return
• 低风险策略，只关注收益回报

### Metrics for Assessing Fund Performance

• Common Metrics
• Annual Return
• metric:
• (value[end] / value[star])) -1
• (value[end] - value[start])/value[start]
• Example: $100 to$110
• (110/100) -1 = 0.1 = 10%
• (110-100)/100 = 0.1 = 10%
• Risk
• 定义风险：Standard deviation of return
• daily return
  //日回报保准差
daily_rets[i] = (value[i]/value[i-1]) -1
std_metrics = stdev(daily_rets)

• Draw down
• 最大跌幅
• 平均跌幅
• Reward/Risk
• 收益风险比，How much reward you are getting for your risk?
• Sharpe Ratio
• Most “important” measure of asset performance.
• How well does the return of an asset compensate the investor for the risk taken
• The higher the Sharpe ratio the better.
• When comparing two assets each with the same return, higher ratio gives more return for the same risk.
$S = E [ R-Rf ] σ = E [ R-Rf ] var E [ R-Rf ] = K* dailyRet std(dailyret)$
• seudo code

  metric = k * mean(daily_rets)/stdev(daily_rets)
# k = sqrt(250) for daily returns
# 250: days in a trading year

• Sortino Ratio
• Sortino ratio only penalizes for negative volatility in the calculation of risk.
• Sharpe ratio penalizes for both positive and negative volatility.
• Jensen’s Alpha
• Example

Return Sharpe STDEV D-down Corr
xxFund 33% .94 0.58% -8.67% 0.89
$DJI 43% .63 1.23% -27.38% 1.00 1. 该基金没有收益率没有跑赢大盘，但是Sharpe指数高于大盘，说明它的整体波动率较低，相对于收益的风险更小 2. 同样，STDEV，D-down 数据也偏低，说明日均波动较小 ## Market Mechanics • Types of Orders • But,Sell • Market, Limit • Shares • Price(if Limit) • Additional possibilities: • Sell short • More complex orders • The Order Book(买盘与卖盘) • Ask (Buy) • Bid (Sell) • Mechanics of Short Selling 1. Borrow the shares 像券商融券 2. 立刻卖掉融到的券 • 拿到现金 • 需要在未来归还券商融到的股票 3. 如果价格未来价格下跌 • 只需要支付较低价格来买回股票还给券商 • 差价即是利润 ### Computing Inside a Hedge Fund ### Company Worth • Key Terms • 使用贴现率 假设我们今天有 • 使用折现率 假设我们投资一家公司，这个公司每年一股能产生1美金的利润(dividend)，那么我们现在应该以每股多少钱购入它的股票？换句话说，这个公司现在每股的价值该怎么计算，或者说这个公司的固执该怎么计算呢？为了比较，假设我们也可以把买这家公司股票的前钱存到银行，同样每年能赚取1美金。假设银行的利息是1分钱，那么我们需要向银行存入0.99美元，一年后能拿到1块钱。对于公司来说，它承担的风险比银行高，因此它的收益也比银行高，假设我们只需要投资0.95美元一年后即可得到1块钱收益。这意味着 一年后1美元利润，现在只值0.95美元。而0.95/1这个比例值也叫做这个折现率（discount rate） |now |year1 |year2 |year3 Company ---->$1.00 ----> $1.00 ---->$1.00 --->...
$0.95 Bank ----->$1.00 ----> $1.00 ---->$1.00 --->...

## 附 Install QSTK on MacOS

• Install Pip
brew install python

• Install virtualenv
pip install nose
pip install virtualenv

• Install Numpy, Scipy and Matplotlib

brew install gcc


brew tap brewsci/homebrew-science
brew tap brewsci/bio


brew install numpy
brew install scipy
brew install matplotlib

• 创建一个QSTK的测试目录
mkdir ~/QSTK
cd ~/QSTK

• 使用virtualenv进行环境隔离
virtualenv env --distribute --system-site-packages
source ~/QSTK/env/bin/activate


activate之后的安装都将与全局环境隔离，这里要先check一下env/lib/下的python版本， 如果误使用了python3，要还原回来，需要重新指定python版本

virtualenv --python=/usr/bin/python2.7 ~/QSTK/env

• 安装QSTK及其依赖
pip install pandas
pip install scikits.statsmodels
pip install scikit-learn
pip install cvxopt
pip install QSTK


• 测试QSTK demo
curl -O https://spark-public.s3.amazonaws.com/compinvesting1/QSTK-Setups/Examples.zip
unzip Examples.zip


2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/QSTK/qstkutil/qsdateutil.py", line 36, in _cache_dates
return pd.TimeSeries(index=dates, data=dates)
AttributeError: 'module' object has no attribute 'TimeSeries'


pip install pandas==0.7.3

• 测试Basic下的一系列tutorial.py
python tutorial1.py


numpy TypeError: The numpy boolean negative, the - operator, is not supported, use the ~ operator or the logical_not function instead.


• 退出virtutalen环境
/bin/deactive

• 卸载QSTK
rm -rf ~/QSTK