Skip to content

Commit

Permalink
Fix : Wallet cash
Browse files Browse the repository at this point in the history
  • Loading branch information
Skinok committed Nov 25, 2021
1 parent d05b62d commit 2b12c7d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
19 changes: 14 additions & 5 deletions Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ def __init__(self):
self.interface = interface

# Strategie testing wallet (a little bit different from backtrader broker class)
self.startingcash = 10000.0

global wallet
wallet = Wallet()
wallet = Wallet(self.startingcash)
self.wallet = wallet


# Then add obersers and analyzers
self.cerebro.addanalyzer(bt.analyzers.TradeAnalyzer, _name = "ta")
Expand Down Expand Up @@ -114,6 +117,10 @@ def addStrategy(self, strategyName):

def run(self):

# Wallet Management : reset between each run
self.cerebro.broker.setcash(self.startingcash)
self.wallet.reset(self.startingcash)

# Compute strategy results
results = self.cerebro.run() # run it all
self.strat_results = results[0] # results of the first strategy
Expand Down Expand Up @@ -142,7 +149,6 @@ def displayStrategyResults(self):
if order.status in [order.Completed]:
self.myOrders.append(order)


self.interface.setOrders(self.myOrders)

# Profit and Loss
Expand All @@ -165,7 +171,10 @@ def displayUI(self):
pass


def cashChanged(self, cash):
if len(cash) > 0:
self.cerebro.broker.setcash(float(cash))
def cashChanged(self, cashString):

if len(cashString) > 0:
self.startingcash = float(cashString)
self.cerebro.broker.setcash(self.startingcash)

pass
6 changes: 3 additions & 3 deletions finplotWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ def show(self):

def drawPnL(self, pln_data):

# put an MA on the close price
#fplt.plot(pln_data['time'], pln_data['pnlcomm'], ax = self.axPnL)
#fplt.plot(pln_data['time'], pln_data['cash'], ax = self.axPnL, legend="Cash")
self.axPnL.reset()

fplt.plot(pln_data['time'], pln_data['value'], ax = self.axPnL, legend="value")
fplt.plot(pln_data['time'], pln_data['equity'], ax = self.axPnL, legend="equity")

self.axPnL.ax_widget.show()
self.axPnL.show()

Expand Down
3 changes: 0 additions & 3 deletions observers/SkinokObserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ def __init__(self):
self.progressBar.setMaximum(self.datas[0].close.buflen())
self.progressBar.setValue(0)

# Wallet Management
Controller.wallet.reset()

def next(self):

# Watch trades
Expand Down
12 changes: 6 additions & 6 deletions wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
###############################################################################
class Wallet():

def __init__(self):
def __init__(self, startingCash):

self.reset()
self.reset(startingCash)

pass

def reset(self):
def reset(self, startingCash):

self.current_value = 10000 # todo: change it by initial cash settings
self.current_cash = 10000 # todo: change it by initial cash settings
self.current_equity = 10000 # todo: change it by initial cash settings
self.current_value = startingCash # todo: change it by initial cash settings
self.current_cash = startingCash # todo: change it by initial cash settings
self.current_equity = startingCash # todo: change it by initial cash settings

self.value_list = []
self.cash_list = []
Expand Down

0 comments on commit 2b12c7d

Please sign in to comment.