
通过机器学习预测市场动向
|
149
In [15]: reg = np.linalg.lstsq(m[:lags].T, m[lags], rcond=None)[0]
In [16]: reg
Out[16]: array([-0.66666667, 0.33333333, 1.33333333])
In [17]: np.dot(m[:lags].T, reg)
Out[17]: array([ 3., 4., 5., 6., 7., 8., 9., 10., 11.])
实现线性
OLS
回归。
打印出最佳参数。
点积产生预测结果。
这个基本思想很容易转移到现实世界的金融时间序列数据中。
5.1.3
预测指数水平
下一步是将基本方法转换为真实金融工具的时间序列数据,例如
EUR/USD
汇率:
In [18]: import pandas as pd
In [19]: raw = pd.read_csv('http://hilpisch.com/pyalgo_eikon_eod_data.csv',
index_col=0, parse_dates=True).dropna()
In [20]: raw.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 2516 entries, 2010-01-04 to 2019-12-31