-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstrategy.py
More file actions
30 lines (27 loc) · 821 Bytes
/
Copy pathstrategy.py
File metadata and controls
30 lines (27 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from fast-backtester import instrument, capital_management
class strategy():
self.instruments = []
def __init__(self, instruments, capital=None):
self.instruments = instruments
if capital is None:
self.capital = capital(instruments)
else:
self.capital = capital
self.df = pd.dataframe()
self.datetime_index = "DateTime"
foreach i in self.instruments:
if self.df.empty:
self.df = i.df
else:
self.df = pd.merge(self.df, i.df, on=self.datetime_index)
def run(self):
for row_num in range(0, len(self.df)):
new_orders = self.calculate(self, row_num, self.df, self.capital)
if len(new_orders)>0:
self.capital.add_orders(new_orders)
def plot_total_pnl(self):
pass
def plot_symbol(self, instrument):
symbol.plot_price()
def handle_data(self, market_data, capital):
pass