Newbie questions to use Backtrader in 'real world' scenarios.
-
Hi,
I've been tinkering with Backtrader for the past week or two, and I've watched some YouTube videos as well, but I have a couple of questions which I can't find the answers to on the Backtrader site or here.
I think they are some newbie questions that would really help me use Backtrader in a more 'real world' scenario for the hobbyist investor.
Here are the questions (go easy on me):
-
How do I invest a certain sum of money rather than a fixed stake each time? I think I need to access the current price prior to buying then calculate the number of shares I can purchase based on my cash reserve.
-
How can I set the trade commission as a fixed amount rather than a percentage, e.g. $10? Here in the UK, the brokers tend to charge a fixed sum rather than commission.
-
How do I reinvest all my cash each time rather than a fixed stake? Or reinvest only the profit? In real life this is something I do, I never invest based on a number of shares each time.
-
How do I access user defined variables in my strategy class from the main script? I want to return particular information/results back, that I can then manipulate. For example with the optimization example I want to store each result in a list then analyse the list once each test case has been executed.
Thanks in advance.
-
-
@rustyg said in Newbie questions to use Backtrader in 'real world' scenarios.:
How do I invest a certain sum of money rather than a fixed stake each time? I think I need to access the current price prior to buying then calculate the number of shares I can purchase based on my cash reserve.
You can create a custom sizer and the current cash info is available to then divide by your security price to get units.
@rustyg said in Newbie questions to use Backtrader in 'real world' scenarios.:
How can I set the trade commission as a fixed amount rather than a percentage, e.g. $10? Here in the UK, the brokers tend to charge a fixed sum rather than commission.
Look here
If margin is something else, it is considered the operations are happenning on a futures like intstrument and commission is a fixed price per size contracts
@rustyg said in Newbie questions to use Backtrader in 'real world' scenarios.:
How do I reinvest all my cash each time rather than a fixed stake? Or reinvest only the profit? In real life this is something I do, I never invest based on a number of shares each time.
You can check cash value in the broker in each next and decide if it's enough to invest.
@rustyg said in Newbie questions to use Backtrader in 'real world' scenarios.:
How do I access user defined variables in my strategy class from the main script? I want to return particular information/results back, that I can then manipulate. For example with the optimization example I want to store each result in a list then analyse the list once each test case has been executed.