注册    登录
 公众号主要介绍关于量化投资和机器学习的知识和应用。通过研报，论坛，博客，程序等途径全面的为大家带来知识食粮。版块语言分为：Python、Matlab、R，涉及领域有：量化投资、机器学习、深度学习、综合应用、干货分享等。

# 一位数据科学PhD眼中的算法交易

↑↑点我

“All models are wrong but some are useful” -George Box

``````import pandas as pdimport numpy as np# daily exchange rate# https://open.canada.ca/data/en/dataset/1bc25b1e-0e02-4a5e-afd7-7b96d6728aac# Load the CSV filerates = pd.read_csv('https://lemay.ai/forex/10100008.csv')# Decide what columns we wantrates_cols=['REF_DATE', 'VALUE']# Only keep the closing spot price for our currency pair

# Graph the datarates.drop(['yesterday'], axis=1, inplace=True)rates.plot()rates.tail()``````

``````import pandas as pd# Industrial Product Price Index (IPPI) data# https://open.canada.ca/data/en/dataset/39a39c7c-24f1-4789-8f20-a04bcbf635b0# Load the CSV filedf = pd.read_csv('https://lemay.ai/forex/18100030.csv')# Decide what columns we wantcategories=list(df[list(df)[3]].drop_duplicates())df_cols=['REF_DATE', 'North American Product Classification System (NAPCS)', 'VALUE']# Prepare an empty dataframe to fill with properly indexed economic datanew_df = pd.DataFrame(columns=df_cols)# Toss out the columns we don't wantdf=df[df_cols]# Set the date as the index using the same format as the USD_CAD datadf.index = df['REF_DATE']new_df.index = new_df['REF_DATE']# Dump out the date column now that we applied it to the dataframe indexdf.drop(['REF_DATE'

], axis=1, inplace=True)new_df.drop(['REF_DATE'], axis=1, inplace=True)# Spot check the dataframe so fardisplay(df.head())# Loop through the economic indicators and put each one in a dedicated columnfor cat in categories:    # Data can have problems, and not all indicators will make it through    try:      new_df[cat]=df[df[list(df)[0]]==cat]['VALUE']    except Exception as e:      print("failed on",cat,e)# Spot check the output dataframedisplay(new_df.head())# Graph the datanew_df.plot()# Save the dataframe with the economic indicators to a filenew_df.to_csv("forex_signals.csv")``````

``````import pandas as pdimport matplotlib.pyplot as pltfrom sklearn.preprocessing import MinMaxScalerdef makeFig(plt, title, xlabel, ylabel, fName):  plt.xlabel(xlabel)  plt.ylabel(ylabel)  plt.title(title)  plt.tight_layout()  plt.savefig(fName, dpi=100)  #plt.show()  return# Observe the whole data range and then specific data rangesfor

startYear,endYear in [[1949,2019],[1990,2000],[2000,2010],[2010,2019]]:  df_new = pd.read_csv('forex_signals.csv',index_col=0)  # Keep only the data for the time range that we care about  if startYear>=1950:    df_new = df_new[df_new.index>=str(startYear)+'-01']    df_new = df_new[df_new.index'-01']  # Use the same date format we used for the exchange rate  df_new.index=pd.to_datetime(df_new.index)  #df_new.plot(legend=False)  # Scale the IPPI data  scaler = MinMaxScaler()  df_new[list(df_new)] = scaler.fit_transform(df_new[list(df_new)])  # Join the exchange rate data with the IPPI data  m=df_new[list(df_new)[:]].join(rates, how='inner').fillna(0)  correlations = m.corr()['USD_CAD'].sort_values(ascending=False).dropna()    plt.figure(figsize=(20, 8))  correlations[1:26].plot.barh()  title="Correlation of Industrial Product Prices and USD_CAD strength ("+str(startYear)+" to "+str(endYear)+")"  xlabel="Correlation with USD_CAD"  ylabel="Price of Industrial Product"  fName=str(startYear)+'s_corr_high.png'  makeFig(plt, title, xlabel, ylabel, fName)    plt.figure(figsize=(20, 8))  correlations[-25:].plot.barh()  fName=str(startYear)+'s_corr_low.png'  makeFig(plt, title, xlabel, ylabel, fName)    plt.figure(figsize=(20, 8))  correlations[1:].plot.bar()  plt.xticks([])

fName=str(startYear)+'s_histogram_correlations.png'  makeFig(plt, title, ylabel, xlabel, fName)    # Tomorrow minus today's exchange rate gives the rate delta  # Intuition: When tomorrow's USD_CAD exchange rate is higher than today's, the result is positive  p=m.copy(deep=True)  p['dUSD_CAD']= m['USD_CAD'].shift(-1) - m['USD_CAD']  causations = p.corr()['dUSD_CAD'].sort_values(ascending=False).dropna()    plt.figure(figsize=(20, 8))  causations[1:].plot.bar()  plt.xticks([])  xlabel="Price of Industrial Product"  ylabel="Correlation with change in USD_CAD next month"  title="Correlation with change in USD_CAD next month("+str(startYear)+" to "+str(endYear)+")"  fName=str(startYear)+'s_histogram_predictions.png'  makeFig(plt, title, xlabel, ylabel, fName)``````

20世纪50年代到现在

21世纪头十年，一个不断变化的世界

2010年代是历史上最长的经济扩张时期

Before Tuning: Model performance for 10 simulation runs before tuning the network and massaging the training data. Results are pretty random.

After some effort, but before fees: Model performance for 10 simulation runs. These simulations did not include fees. Results look promising.

A trading algorithm is born: These are the results with fees included. We make a bit less money, but have a bit more consistent performance. Fees are only paid when we buy in or change position. All 9 of 10 simulations eventually ended in profit.

02、监督学习标签在股市中的应用（代码+书籍）

04、使用Tensorflow预测股票市场变动

05、使用LSTM预测股票市场基于Tensorflow

06、美丽的回测——教你定量计算过拟合概率

07、利用动态深度学习预测金融时间序列基于Python

11、实战交易策略的精髓（公众号深度呈现）

12、Markowitz有效边界和投资组合优化基于Python

13、使用LSTM模型预测股价基于Keras

14、量化金融导论1：资产收益的程式化介绍基于Python

15、预测股市崩盘基于统计机器学习与神经网络（Python+文档）

16、实现最优投资组合有效前沿基于Python（附代码）

17、精心为大家整理了一些超级棒的机器学习资料（附链接）

18、海量Wind数据，与全网用户零距离邂逅！

19、机器学习、深度学习、量化金融、Python等最新书籍汇总下载

20、各大卖方2019年A股策略报告，都是有故事的人！

 18 小时前
 昨天
 昨天
 昨天
 昨天
 2 天前
 2 天前
 4 天前
 4 天前
 4 天前