Machine Learning For Trading - penny4860/study-note GitHub Wiki
1. ์ ๋ฆฌ
์์ฝ
์ง๋ฌธ
- adjust close ๋ ์ข
๊ฐ์์ ์ด๋ค๊ฑธ ๋ณด์ ํ๊ฑฐ์ง?
2. ๋ด์ฉ
Lesson 1-2. Working with multiple stocks
- ๋ ์ง๋ฅผ index๋กํ๋ df ์์ฑํ๊ธฐ :
pd.date_range(s, e)
- read / join / slicing / plotting
Lesson 1-4. Statistical Analysis of Time Series
- Global Stat.
- Rolling Stat.
- ํน์ ๊ธฐ๊ฐ(์ผ์ฃผ์ผ) ๋์ window๋ฅผ ์์์ ํ๊ท ์๋ธ๋ค.
- window์ value๋ก ํต๊ณ์น๋ฅผ ๊ณ์ฐ
- ๋
ธ์ด์ฆ๋ฅผ ์์ ๋ ํจ๊ณผ
- smooth / lag
- global mean์ ๋นํด์ laggingํ ์ปค๋ธ๊ฐ ๊ทธ๋ ค์ง๋ค.
- Trade signal๋ก ํ์ฉ๊ฐ๋ฅ.
- global mean๊ณผ rolling mean์ ๊ต์ฐจ์
(global mean - rolling mean) > 2 * ํ์คํธ
- Daily Returns
- ํ๋ฃจ ์์ต๋ฅ
daily_ret[t] = (price[t] / price[t-1]) - 1
- Cumulative Returns
- ํน์ ๊ธฐ๊ฐ๋์์ ๋์ ์์ต๋ฅ
cum_ret[t] = (price[t] / price[o]) - 1
Lesson 1-5. Incomplete Data
- ๋ฐ์ดํฐ ์์ค์ด ์๋ ์ด์
- single price๊ฐ ์๋
- ์ฌ๋ฌ๊ฐ์ ๊ฑฐ๋์๊ฐ ์์.
- ํ์ค์ ์ผ๋ก 1๊ฐ์ ๊ฐ๊ฒฉ์ ์๋ค.
- ๋ชจ๋ ์ฃผ์์ด ๋งค์ผ ๊ฑฐ๋๊ฐ ์ผ์ด๋๋ ๊ฒ์ ์๋๋ค
df.fillna()
๋ก ์๋ ๋ฐ์ดํฐ๋ฅผ ์ฑ์ฐ์.
Lesson 1-7. Histograms and Scatter Plots
- Histograms of Daily Returns
- ๊ฐ๋ก์ถ : ํ๋ฃจ ์์ต๋ฅ (์์:
-1.0% ~ +1.0%
)
- ์ธ๋ก์ถ : count
- Correlation
- Measure of how tightly dots fit the line
- linear fitting์ slop์ correlation์ด ์๋๋ค.
- ๊ตฌํ๋ฐฉ๋ฒ
- ์์ฐ๋ณ csvํ์ผ ๋ค์ด๋ก๋
- ํน์ ๊ธฐ๊ฐ ๋์ df๋ก ์ฝ์ด์ค๊ธฐ
- daily return ๊ณ์ฐ
- correlation ๊ณ์ฐ
returns.corr(method="pearson")
Lesson 1-7. Portpolio Statistics
- Daily Portpolio value ๊ณ์ฐ
- Input
- start_val
- start_date
- end_date
- symbols
- allocs
=[0.4, 0.4, 0.1, 0.1]
- Flow
- prices(์์ฐ๋ณ historical df) ๋ฅผ ์ ๊ทํํ๋ค.
normed = prices / prices[0]
- ๋ถ๋ฐฐ๋น์จ์ ๊ณฑํ๋ค.
alloced = normed * allocs
- ์ด๊ธฐ์์ฐ์ ๊ณฑํ๋ค.
pos_vals = alloced * start_val
- Portpolio value ๊ณ์ฐ
port_val = pos_vals.sum(axis=1)
- Porpolio Statitics
- Daily Returns
- Cum. Returns :
(port_val[-1] / port_val[0]) - 1.0
- avg. daily returns :
daily_returns.mean()
- std. daily returns
- sharp ratio :
K * daily_returns.mean()/daily_returns.std()
- K :
sqrt(number of samples per year)
- 1์ผ๋ง๋ค sampling : sqrt(252)
- 1์ฃผ๋ง๋ค sampling : sqrt(52)
- 1๋ฌ๋ง๋ค sampling : sqrt(12)
- sampling ์ฃผ๊ธฐ๋ฅผ ์งง๊ฒ ํ๋ฉด ํ์คํธ์ฐจ๊ฐ ๋์์ ธ์ SR๊ฐ์ด ์์์ง๋ค. ์ด๊ฒ์ K๊ฐ์ผ๋ก ๋ณด์