Finish manual strategy for project 8

I struggled with the manual strategy, mostly because I tried to read
good triggers from the price action charts. Finally, I had the ingenious
(hmm) idea to scatter plot the 1, 3, and 5 day percentage returns over
different indicators. I can also use this information to train my Q
learner.
This commit is contained in:
2020-11-03 19:05:43 -05:00
parent 43e297c075
commit 0519ae9336
3 changed files with 108 additions and 46 deletions

View File

@@ -58,19 +58,32 @@ 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
shares = 0
_, _, macd_diff = macd.loc[row.name]
cur_rsi = rsi.loc[row.name][0]
cur_price_sma = price_sma.loc[row.name][0]
if self.holding == -1000 and cur_price_sma < 0.9:
shares = 2000
elif self.holding == 0 and cur_price_sma < 0.9:
shares = 1000
elif self.holding == -1000 and cur_rsi > 80:
shares = 2000
elif self.holding == 0 and cur_rsi > 80:
shares = 1000
elif self.holding == -1000 and macd_diff < -0.5:
shares = 2000
elif self.holding == 0 and macd_diff < -0.5:
shares = 1000
elif self.holding == 1000 and cur_price_sma > 1.1:
shares = -2000
elif self.holding == 0 and cur_price_sma > 1.1:
shares = -1000
self.holding += shares
return shares
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",
sd=dt.datetime(2009, 1, 1),
ed=dt.datetime(2010, 1, 1),
@@ -87,10 +100,9 @@ class ManualStrategy:
macd = indicators.macd(df, symbol)
rsi = indicators.rsi(df, symbol)
price_sma = indicators.price_sma(df, symbol, [21])
price_sma = indicators.price_sma(df, symbol, [8])
# self.macd_strat(macd, orders)
self.three_indicator_strat(macd, rsi, price_sma, orders)
# heers = orders[orders["Shares"] != 0]
return orders