Content-Length: 298411 | pFad | http://github.com/kernc/backtesting.py/discussions/1197

61 Position sizing for backtesting · kernc backtesting.py · Discussion #1197 · GitHub
Skip to content

Position sizing for backtesting #1197

Answered by iimka
ek-ex asked this question in Q&A
Jan 19, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Setting cash=10000 simply initializes the account with $10,000 at the start. As the account balance changes, the amount of capital/size used for each trade is controlled by self.buy(size=...).

If you want to trade with $10,000 each time, I haven't tried that (since using a percentage of the account balance for trading seems more reasonable than a fixed amount as the account balance increases).

However, I guess we can use the closing price of the previous bar to calculate the number of shares that can be bought with 10,000, and then put that into self.buy(size=...). Although there may be some discrepancies, it should be close to trading with 10,000.

Day 0: Cash = 10000
Day 1: self.buy() Ca…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ek-ex
Comment options

@iimka
Comment options

Answer selected by ek-ex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/kernc/backtesting.py/discussions/1197

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy