37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import pandas as pd
|
|
import util as ut
|
|
import datetime as dt
|
|
|
|
|
|
class BenchmarkStrategy:
|
|
def __init__(self, verbose=False, impact=0.0, commission=0.0, units=1000):
|
|
self.verbose = verbose
|
|
self.impact = impact
|
|
self.commission = commission
|
|
self.units = units
|
|
|
|
def addEvidence(self, symbol=0, sd=0, ed=0, sv=0):
|
|
"""Keep this so that API is valid."""
|
|
pass
|
|
|
|
def testPolicy(self, symbol="IBM",
|
|
sd=dt.datetime(2009, 1, 1),
|
|
ed=dt.datetime(2010, 1, 1),
|
|
sv=10000):
|
|
"""Benchmark is to buy 1000 shares and hold."""
|
|
dates = pd.date_range(sd, ed)
|
|
prices = ut.get_data([symbol], dates, addSPY=False,
|
|
colname='close', datecol='time')
|
|
|
|
orders = pd.DataFrame(index=prices.index)
|
|
orders["Symbol"] = symbol
|
|
orders["Order"] = ""
|
|
orders["Shares"] = 0
|
|
orders.iloc[0] = [symbol, "BUY", self.units]
|
|
orders.iloc[-1] = [symbol, "SELL", -self.units]
|
|
|
|
if self.verbose:
|
|
print(type(orders)) # it better be a DataFrame!
|
|
print(orders)
|
|
return orders
|