However, the Position Value is not giving correct value, when comparing to the Calculated Margin Deposit and Position Value that I put as a Custom Metric and also doesn't seem to be changing as can be seen in the Screenshot of the Analysis below:
Upon further investigation, it seems that the Position Value being taken in the Analysis is being calculated from the Margin Deposit value from the last bar in the data:
Can MarginDeposit be dynamic? If yes, how do I set that up and where am I going wrong? Please help.
You definitely should NOT have pointvalue included in calculation of margin deposit. That is wrong.
WRONG:
MarginDeposit = prev_day_close * PointValue;
MarginDeposit of course can be dynamic (variable on bar by bar basis). MarginDeposit is a deposit (fraction of actual price) so it is LESS than price, not 25 * price.
Now I understand that I have been using it incorrectly due to misunderstanding on my part. This is basically what I was trying to emulate:
For buying 1 contract/lot (e.g. lot size is 25), you require the equivalent funds available of (entry price * lot size) / leverage.
I was testing for the leverage of 1, therefore I had put
MarginDeposit = prev_day_close * PointValue;
where PointValue was the lot size. Since each price point moved at 1 contract would give a MTM profit of 1 lot size, I thought this was correct. Obviously, this is not how it works.
So, the question becomes how do I set the lot size in MarginDeposit calculation? And since the Margin requirement set by the exchange changes over time, how do we account for it?
PointValue is NOT Lot size. PointValue is dollar value of profit / loss of single contract position when price of underlying instrument change by 1 (one).
You must NOT "reinterpret" or "assume" things. Variables have strict meaning defined in the guide and ONLY that meaning defined in the guide is correct.
Doing otherwise (out of the blue assumptions and not following the manual) leads to errors.
However, lot sizes are not standardized to 100 shares in India as it is in American Exchanges for example. Instead it is full contract value that is standardized. (For example, the Nifty 50 Index has a current lot size of 75. Another index BankNifty, has a current lot size of 25. Lot sizes are usually re-calculated every few months because of course the prices keeps changing. This was initially why I put PointValue equal to the lot size, because if you buy 1 lot of BankNifty, each 1 point movement gives ₹25 profit/loss.
If PointValue cannot be used for lot size in this use case, can you give me an idea of how to set up lot size while calculating let's say 10% MarginDeposit of full contract value as mentioned in the guide for futures back-testing? I would be really grateful for the help.
No, you don't seem to understand. LotSize has absolutely NOTHING to do with PointValue. Lot size is controlled by RoundLotSize variable, which is completely different than PointValue.