Change indicators to return their results and work on three indicator strat

This commit is contained in:
2020-11-02 09:10:01 -05:00
parent 4679910374
commit 43e297c075
3 changed files with 55 additions and 25 deletions

View File

@@ -57,6 +57,18 @@ class ManualStrategy:
orders['Shares'] = orders['Shares'].rolling(2).apply(strat)
def three_indicator_strat(self, macd, rsi, price_sma, orders):
# XXX: continue here
def strat(row):
m = macd.loc[row.index]
print(m)
# mac, signal = m.iloc[0]
# print(mac, signal)
return 0
orders['Shares'] = orders.apply(strat, axis=1)
raise Exception()
# this method should use the existing policy and test it against new data
def testPolicy(self, symbol="IBM",
@@ -67,22 +79,18 @@ class ManualStrategy:
self.holding = 0
df = util.get_data([symbol], pd.date_range(sd, ed))
df.drop(columns=["SPY"], inplace=True)
macd = indicators.macd(df, symbol)
orders = pd.DataFrame(index=df.index)
orders["Symbol"] = symbol
orders["Order"] = ""
orders["Shares"] = 0
self.macd_strat(macd, orders)
macd = indicators.macd(df, symbol)
rsi = indicators.rsi(df, symbol)
price_sma = indicators.price_sma(df, symbol, [21])
# self.macd_strat(macd, orders)
self.three_indicator_strat(macd, rsi, price_sma, orders)
# here we build a fake set of trades
# orders.iloc[0] = [symbol, "BUY", 1000]
# orders.iloc[40] = [symbol, "SELL", 1000]
# orders.iloc[41] = [symbol, "BUY", 1000]
# orders.iloc[60] = [symbol, "SELL", 2000]
# orders.iloc[61] = [symbol, "BUY", 2000]
# orders.iloc[-1] = [symbol, "SELL", 1000]
# orders = orders[orders["Shares"] != 0]
# heers = orders[orders["Shares"] != 0]
return orders