Skip to content

Commit 2b12c7d

Browse files
committed
Fix : Wallet cash
1 parent d05b62d commit 2b12c7d

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

Controller.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ def __init__(self):
5151
self.interface = interface
5252

5353
# Strategie testing wallet (a little bit different from backtrader broker class)
54+
self.startingcash = 10000.0
55+
5456
global wallet
55-
wallet = Wallet()
57+
wallet = Wallet(self.startingcash)
5658
self.wallet = wallet
59+
5760

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

115118
def run(self):
116119

120+
# Wallet Management : reset between each run
121+
self.cerebro.broker.setcash(self.startingcash)
122+
self.wallet.reset(self.startingcash)
123+
117124
# Compute strategy results
118125
results = self.cerebro.run() # run it all
119126
self.strat_results = results[0] # results of the first strategy
@@ -142,7 +149,6 @@ def displayStrategyResults(self):
142149
if order.status in [order.Completed]:
143150
self.myOrders.append(order)
144151

145-
146152
self.interface.setOrders(self.myOrders)
147153

148154
# Profit and Loss
@@ -165,7 +171,10 @@ def displayUI(self):
165171
pass
166172

167173

168-
def cashChanged(self, cash):
169-
if len(cash) > 0:
170-
self.cerebro.broker.setcash(float(cash))
174+
def cashChanged(self, cashString):
175+
176+
if len(cashString) > 0:
177+
self.startingcash = float(cashString)
178+
self.cerebro.broker.setcash(self.startingcash)
179+
171180
pass

finplotWindow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ def show(self):
341341

342342
def drawPnL(self, pln_data):
343343

344-
# put an MA on the close price
345-
#fplt.plot(pln_data['time'], pln_data['pnlcomm'], ax = self.axPnL)
346-
#fplt.plot(pln_data['time'], pln_data['cash'], ax = self.axPnL, legend="Cash")
344+
self.axPnL.reset()
345+
347346
fplt.plot(pln_data['time'], pln_data['value'], ax = self.axPnL, legend="value")
348347
fplt.plot(pln_data['time'], pln_data['equity'], ax = self.axPnL, legend="equity")
348+
349349
self.axPnL.ax_widget.show()
350350
self.axPnL.show()
351351

observers/SkinokObserver.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ def __init__(self):
3636
self.progressBar.setMaximum(self.datas[0].close.buflen())
3737
self.progressBar.setValue(0)
3838

39-
# Wallet Management
40-
Controller.wallet.reset()
41-
4239
def next(self):
4340

4441
# Watch trades

wallet.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
###############################################################################
2121
class Wallet():
2222

23-
def __init__(self):
23+
def __init__(self, startingCash):
2424

25-
self.reset()
25+
self.reset(startingCash)
2626

2727
pass
2828

29-
def reset(self):
29+
def reset(self, startingCash):
3030

31-
self.current_value = 10000 # todo: change it by initial cash settings
32-
self.current_cash = 10000 # todo: change it by initial cash settings
33-
self.current_equity = 10000 # todo: change it by initial cash settings
31+
self.current_value = startingCash # todo: change it by initial cash settings
32+
self.current_cash = startingCash # todo: change it by initial cash settings
33+
self.current_equity = startingCash # todo: change it by initial cash settings
3434

3535
self.value_list = []
3636
self.cash_list = []

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy