Skip to content

Conversation

@jbdelmundo
Copy link
Collaborator

@jbdelmundo jbdelmundo commented Mar 23, 2021

Description

Added the following changes:

  • Docstrings in BaseStrategy
  • Added a new logging module instead of simply doing print() inside the BaseStrategy
  • Logging inside the strategy can be accessed using self.logging.log()
  • Separated the function of adding periodic cash
  • buy_signal() and sell_signal() can now return (signal, buy/sell_prop) instead of just boolean (still backwards compatible)
  • Added trade_history
  • Set default signal to False (no action)

Checklist

  • [ X] I am making a pull request from a branch other than master
  • [ X] I have read the CONTRIBUTING.md
  • [ X] I have added/edited documentation in a relevant docs/docusaurus markdown file
  • [X ] (For new docs, check if not applicable) I have added the id of a new docs md to the docs/docusaurus/sidebars.js file

@jbdelmundo jbdelmundo requested review from a user, enzoampil, jpdeleon and rafmacalaba March 23, 2021 14:00
@jbdelmundo jbdelmundo self-assigned this Mar 23, 2021
@jbdelmundo
Copy link
Collaborator Author

This might be a large change so comments, requests for change are welcome! :)

Copy link
Collaborator

@rafmacalaba rafmacalaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ghost
Copy link

ghost commented Mar 27, 2021

has no idea what I'm doing lgtm!! 😅 I'll defer to your judgement

Copy link
Owner

@enzoampil enzoampil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jbdelmundo , thanks so much for this PR. BaseStrategy looks 5 times cleaner, and the buy / sell proportions look very interesting 😄

Let's start with the initial comments that I just gave, most importantly regarding the new "execution types" being implemented, and the inconsistency between the types used for create_buy_order vs create_sell_order.

My recommendation is to include all three execution types for both:

  1. close - next time step close
  2. open - next time step open (this is the preferred execution_type though requires an open column)
  3. market - current time step close

Note: There's current handling that makes open the same as market in the case that open is chosen, but the column doesn't exist in the input dateframe.

stop loss percent
stop_trail : float
stop trail percent
execution_type : str {`market`,`close`} (default=`market`)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbdelmundo Any specific reason why you decided to leave out the open option that was previously implemented? 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I am having trouble making the backtest use the next opening price.
I have tried using Market and Close orders in backtrader but it seems both use the closing price.
For Close orders, it uses the next day (or bar) close price, and for Market orders, it uses the current closing price

I am using the Ternary Strategy to manually provide buy and sell signals and review them on the order history

)

elif stock_value > 0:
# Buy on tomorrow's closing price
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbdelmundo Yeah, I think best to still include the open type of execution. Technically, next day open is the most recommended approach to implementing the buy and sell; although, we use current / next day close as a proxy when next day open is not available.

)

# Buy based on the opening price of the next closing day (only works "open" data exists in the dataset)
else:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbdelmundo I notice that for create_buy_order the execution types are market, and close, while for create_short_sell_order, you stuck to the original close, and open execution types. Is there a reason for why they're not consistent?

Co-authored-by: Lorenzo Ampil <lorenzojulioampil@gmail.com>
@jbdelmundo jbdelmundo closed this Jul 6, 2021
@jbdelmundo jbdelmundo deleted the branch enzoampil:master July 6, 2021 12:12
@jbdelmundo jbdelmundo deleted the master branch July 6, 2021 12:12
@jbdelmundo jbdelmundo mentioned this pull request Jul 6, 2021
@jbdelmundo
Copy link
Collaborator Author

Reopened here.
I was renaming my remote branch and got deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants