This commit is contained in:
David Brazda
2024-10-23 17:24:23 +02:00
parent ac00480d55
commit 608ded3d36
2 changed files with 11 additions and 3 deletions

View File

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name='ttools',
version='0.3.8',
version='0.3.9',
packages=find_packages(),
install_requires=[
'vectorbtpro',

View File

@ -5,14 +5,17 @@ from typing import Any
import datetime
def trades2entries_exits(pf):
def trades2entries_exits(pf, notext=False):
"""
Convert trades from Portfolio to entries and exits DataFrame for use in lw plot
For each trade exit type is fetched from orders.
For each trade exit type is fetched from orders and transformed for markers to use.
Args:
pf Portfolio object: trades and orders
notext (bool): if True, no text is added
Returns:
tuple: (entries DataFrame, exits DataFrame)
@ -20,6 +23,11 @@ def trades2entries_exits(pf):
trades = pf.trades.readable
orders = pf.orders.readable
if notext:
trade_entries = pd.Series(index=trades["Entry Index"], dtype=bool, data=True)
trade_exits = pd.Series(index=trades["Exit Index"], dtype=bool, data=True)
return trade_entries, trade_exits
# Merge the dataframes on 'order_id'
trades = trades.merge(orders[['Order Id', 'Stop Type']], left_on='Exit Order Id', right_on='Order Id', how='left').drop(columns=['Order Id'])