Skip to content

Position sizing for backtesting #1197

Answered by iimka
ek-ex asked this question in Q&A
Jan 19, 2025 · 1 comments · 5 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 5 replies

Comment options

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

@iimka
Comment options

Answer selected by ek-ex
@ek-ex
Comment options

@iimka
Comment options

@iimka
Comment options

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