-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuy_everything.py
More file actions
30 lines (23 loc) · 923 Bytes
/
Copy pathbuy_everything.py
File metadata and controls
30 lines (23 loc) · 923 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 model_base import ModelBase
class BuyEverything(ModelBase):
name = "buy everything"
def __init__(self, startingCash):
self.cash = startingCash
self.history = []
self.assets = {}
def calculateActions(self, day):
self.prices = day['Close'].to_dict()
for key in self.prices:
if key not in self.assets:
self.assets[key] = 0
newlyPurchasedAmount = self.cash / list(self.prices.values())[0]
self.assets[list(self.prices.keys())[0]] += newlyPurchasedAmount
self.cash -= newlyPurchasedAmount * list(self.prices.values())[0]
self.history.append(self.calculateValue())
def calculateValue(self):
value = 0
for ticker, amount in self.assets.items():
value += amount * self.prices[ticker]
return value + self.cash
def accountHistory(self):
return self.history