Skip to content

Commit 4adb8c0

Browse files
committed
Clean Pnl data creation
1 parent 1fe994b commit 4adb8c0

File tree

2 files changed

+12
-60
lines changed

2 files changed

+12
-60
lines changed

Controller.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,16 @@ def displayStrategyResults(self):
136136

137137
self.interface.setOrders(self.myOrders)
138138

139-
self.interface.displayPnL( self.strat_results._trades.items(), self.dataframe, self.wallet )
139+
# Profit and Loss
140+
pnl_data = {}
141+
142+
pnl_data['value'] = self.wallet.value_list
143+
pnl_data['equity'] = self.wallet.equity_list
144+
pnl_data['cash'] = self.wallet.cash_list
145+
pnl_data['time'] = self.dataframe.index
146+
147+
# draw charts
148+
self.interface.displayPnL( pd.DataFrame(pnl_data) )
140149

141150
pass
142151

userInterface.py

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -408,67 +408,10 @@ def setOrders(self, orders):
408408
# A python expert could do waaaaay better optimized on this function
409409
# But anyway... it works...
410410
#########
411-
def displayPnL(self, trades, df, wallet):
412-
413-
pnl_data = {}
414-
415-
'''
416-
pnl_data['time'] = []
417-
#pnl_data['pnlcomm'] = []
418-
# temporary
419-
tradesDatetimeIndex = []
420-
tradesPnl = []
421-
422-
# Prepare data before plotting Pnl
423-
for key, values in trades:
424-
425-
row = 0
426-
for trade in values[0]:
427-
428-
if not trade.isopen:
429-
430-
tradesDatetimeIndex.append( bt.num2date(trade.dtclose) )
431-
#tradesDatetimeIndex.append( pd.to_datetime(trade.dtclose) )
432-
tradesPnl.append(trade.pnlcomm)
433-
434-
row += 1
435-
436-
# Re-index :
437-
# Trades are only few times on all the datetime index
438-
current_pnl = 0
439-
for i,timeIndex in enumerate(df.index):
440-
441-
# Convert Timestamp to datetime
442-
timeIndex_datetime = pd.to_datetime(timeIndex)
443-
444-
# is the current datetime in the trade closed times ?
445-
# if so : register a
446-
if timeIndex_datetime in tradesDatetimeIndex:
447-
pnl_index = tradesDatetimeIndex.index(timeIndex_datetime)
448-
current_pnl = tradesPnl[pnl_index]
449-
450-
#pnl_data['cash'].append(broker.value.array[i])
451-
pnl_data['time'].append(timeIndex)
452-
453-
pass
454-
455-
'''
456-
457-
#pnl_data['cash'] = broker.value.array.tolist()
458-
pnl_data['value'] = wallet.value_list
459-
pnl_data['equity'] = wallet.equity_list
460-
pnl_data['cash'] = wallet.cash_list
461-
pnl_data['time'] = df.index
462-
463-
# Data prepared
464-
#pnl_data['broker'] = broker.plotlines._getvalues()
465-
#taille_cash = len(pnl_data['cash'])
466-
#taille_time = len(pnl_data['time'])
467-
468-
pnl_df = pd.DataFrame(pnl_data)
411+
def displayPnL(self, pnl_dataframe):
469412

470413
# draw charts
471-
self.fpltWindow.drawPnL(pnl_df)
414+
self.fpltWindow.drawPnL(pnl_dataframe)
472415
pass
473416

474417
#########

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