8,双均线策略
import tushare as ts import pandas as pd from pandas import DataFrame,Series df = pd.read_csv('maotai.csv',index_col='date',parse_dates=['date']) df.drop(labels='Unnamed: 0',axis=1,inplace=True) df ma5 = df['close'].rolling(5).mean() ma30 = df['close'].rolling(30).mean() df['ma5'] = ma5 df['ma30'] = ma30 s1 = ma5 < ma30 T->F金叉 F->T死叉 s2 = ma5 >= ma30 s1 T T F F T T F F s2 F F T T F F T T T F T T T F T F T F F F T F ~(s1 | s2.shift(1)) s1 = ma5 < ma30 s2 = ma5 >= ma30 df.loc[~(s1 | s2.shift(1))].index df.loc[s1&s2.shift(1)].index 问题:如果我从假如我从2010年1月1日开始,初始资金为100000元,金叉尽量买入,死叉全部卖出,则到今天为止