kieranjwood / trading-momentum-transformer

This code accompanies the the paper Trading with the Momentum Transformer: An Intelligent and Interpretable Architecture (https://arxiv.org/pdf/2112.08534.pdf).
https://kieranjwood.github.io/publication/momentum-transformer/
MIT License
432 stars 188 forks source link

why transaction cost on diff of position ? #4

Closed makovez closed 1 year ago

makovez commented 1 year ago

Hi,

Debugging the code i noticed that the difference of the position is being used to apply commissions. Why is that?

If the position size is 0.5 and the next position is 0.7 you calculate the commission on 0.7-0.6=0.1 commission and then you subtract this to the captured return. Shouldn't you calulcate it on the actual position itself so 0.5 0.1 and then substract from captured return?

Also the position used is the scaled one so it would even be smaller than the actual real position size.

image

kieranjwood commented 1 year ago

Hi @makovez this is explained in the paper https://arxiv.org/pdf/2112.08534.pdf with the equation: $R{t+1}^{(i)} = R{t+1}^{(i)} - C\sigma_{\text{tgt}} | X_t^{(i)} / \sigmat^{(i)} - X{t-1}^{(i)} / \sigma_{t-1}^{(i)} |$

The amount of volatility scaling is recalculated at each time step, therefore we introduce the $\sigma_\text{tgt}/\sigma_t^{(i)}$ term into the transaction cost calculation to account for this and calculate the true position size. I hope this makes sense.

makovez commented 1 year ago

Hi @kieranjwood Thanks for you answer.

I have read again that part of the paper and I can't still see the explaination on the reasons why you multiply the commission to the difference of the positions.

The formula you mention is the exact same formula highlighted in the code, but the reason is not explained.

From my background usually commission should be applied to the position size invested, why you use the difference of the position sizes between two different days?

kieranjwood commented 1 year ago

Ignoring the volatility scaling framework for now, lets say 0.5 represents 5 contracts and 0.6 represents 6 contract. If we change our position from 0.5 to 0.6 we only need to pay transaction costs for 1 contract, which is why we use the difference.

makovez commented 1 year ago

Ignoring the volatility scaling framework for now, lets say 0.5 represents 5 contracts and 0.6 represents 6 contract. If we change our position from 0.5 to 0.6 we only need to pay transaction costs for 1 contract, which is why we use the difference.

Ok now makes sense. Thanks for the clarification

danbo6 commented 4 months ago

Ignoring the volatility scaling framework for now, lets say 0.5 represents 5 contracts and 0.6 represents 6 contract. If we change our position from 0.5 to 0.6 we only need to pay transaction costs for 1 contract, which is why we use the difference.

But why you use the diff of scaled_position, I thought we should use the diff of actual position.