-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Feat/order size #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Feat/order size #24
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this
position
computation correct? You effectively replace formercash
withsize
, but size actually corresponds tocash / price
?I think when size is given, position might better be
float(size) if enough_cash else error
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention for the
size
variable being computed as such is because:margin
option to define a leveraged trade. (Only found out about it after reading: How to use backtesting.py for forex trading #10 ) Was initially under the assumption that all trades were on a 1:1 leverage. Under my assumption, i believed that specifying themargin
option wasn't needed in order to define a "leveraged trade". In fact, by specifying an order size that is larger than your holding cash amount would technically mean you enter a trade on cross margin. (which was why I did not implement a check forif enough_cash
). Reason for this assumption is largely influenced by Trading View's pine script, and how "leveraged trades" would be entered under their backtesting tools.So my thoughts are as follows, and would need some clarification:
margin
option would come in handy for that. A quick look into the code base shows howmargin
is used to calculateleverage
amount. Butmargin
andleverage
are simply being used in reporting functions and likely no where else?Would love to take a stab at pyramiding too, there are indeed many use cases for that. Let me know your thoughts. I might be working on a path different than the philosophy of this library. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It simulates them.
backtesting.py/backtesting/backtesting.py
Lines 561 to 570 in b3cfaff
margin=
therefore represents initial and maintenance margin of the trades. It's used only in stats and plots so the interested user gets a rough idea on how leveraged their strategy is allowed to be to still remain afloat.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our case,
position
is actually equal tosize
when the user requests it. Thus, we only need to deduct the commission and then confirm we have (leveraged) cash to cover it all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think? 😅