Problems with margin, buy/sell logic and plotting



  • Hi everyone, I have got some questions to seek for help :

    1. margin call calculation : I would like to apply my own margin call calculation. Is it possible to do so? If so, what should I do?

    2. immediate buy/sell logic : I have read the document about Buy/Sell logic. But it seems that it can only buy/sell when there is a new data feed come in. Can I perform immediate buy/sell with current price?

    3. plot specific data without OHLC : So, now I got my own CSV data feed, and I only want to display some specific data, e.g. only Bid price. I have tried to set open = -1 and bid = 5 in my data feed. But then I cannot see the Bid prices shown-up on the graph. Did I miss some key step to perform plotting?

    4. order.executed.value meaning, usage and its calculation

    5. meaning and usage of cash and value in the broker : For my point of view, cash is the actual money on the broker, and value means 'money + contract's value on my broker'. Is it correct? How the platform calculate my contract's value?

    Sorry for a lot of questions. Any answer / hint is appreciated. Thank you!



  • Hi Michael,
    Some pointers for your questions:

    1 - Regarding margin calls. They are not supported in the framework by default but you can simulate it by closing a position every time your account would have moved into a margin close out territory.

    2 - If I understand you correctly, you want to enter an order with the close price of the current bar right? If so you can set the cheat-on-close broker parameter to do this:

    https://www.backtrader.com/docu/broker.html?highlight=coc#reference

    3 - You would need to show us your data feed code. However, it should be no problem to use the bid price only. Note that you can customize the plotting quite a bit since plotting is handled by matplotlib.

    4 - order.executed.value is the value of the order when it was executed by the broker. (price * size). This might be different to the price when the order was created and sent to the broker. I.e due to slippage.

    5 - If I am not mistaken value is the account equity. This means you can have 1000 USD in cash, spend 500 on shares and assuming the share price has not moves, you would have 500 left in cash and an account value of $1000 still.



  • Thanks buddy!

    1. Ok. It works perfectly now.

    2. Yeah, that's what I meant. Again, it works perfectly now.

    3. I forgot to add 'line' object of my indicator, so it cannot be plot correctly.

    4. So, it is the equity of the contract?

    5. Understood

    Again, thank you for this precious information! I am grateful for your help.



  • @ThatBlokeDave

    One more question need help. Let say I got 2 to 3 GB tick-data to perform back-testing.

    How can I perform data streaming with the platform?

    It means that I will not pass all the data to cerebro at the beginning, I want to pass my data e.g. 500 MB each time.

    Can it be done? Should I use 'replay' method?



  • @Michael-Scofield said in Problems with margin, buy/sell logic and plotting:

    1. So, it is the equity of the contract?

    Following the description price * size: yes

    @Michael-Scofield said in Problems with margin, buy/sell logic and plotting:

    How can I perform data streaming with the platform?

    Load it. If you have it in a file, use GenericCSVData

    It means that I will not pass all the data to cerebro at the beginning, I want to pass my data e.g. 500 MB each time.

    It depends if the source is efficient at giving you the 500 MB chunks or you expect the internal engine to filter it out for you. The most efficient way is always a database giving you only the chunk you are going to process. If not, any Python program is going to go through the entire dataset until it reaches what you want to process (fromdate and todate parameters to data feed control the chunking, but do really try to split it, before you give it to python)

    Can it be done? Should I use 'replay' method?

    You would use replaydata if you want to see the re-construction of the larger timeframe tick-by-tick (tick -> 5-minutes would mean you see each tick in next, which could amount to some thousand calls)

    If you are only interested in the final re-constructed bar (for example tick -> 5-minutes would only issue 1 call for each 5 minutes) use resampledata.



  • @Paska-Houso Understood. Thank you very much.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.