Lean icon indicating copy to clipboard operation
Lean copied to clipboard

Model Interest Paid on Leveraged Assets

Open jaredbroad opened this issue 10 years ago • 5 comments
trafficstars

Leverage is currently free in LEAN. Implement a system for deducting interest charges from cash when holding leveraged stock overnight. Apply a default interest rate of 1.5% on the leveraged fraction of holdings. Potentially best place is to apply cash charge on day change in AlgorithmManager data loop.

jaredbroad avatar Feb 21 '15 21:02 jaredbroad

When looking at this feature, would it be possible to consider the calculation of swap for FX transactions also. It would be nice to be able to specify a 'Calculation Time' that would fire an event where the calculation could be performed.

The default event code could calculate a 1.5% default rate, but could be overridden to perform custom calculation (in the case of FX swap, we could probably load external data to calc the swap rate) and return the +/- interest back into the account.

Applying on the 'day change' may not work in all cases as brokers may not charge swap at the end of the day (I have a local broker that charges the swap at 1930hrs local time), so the ability to set this to a custom time of day may be more appropriate.

I definately don't have the C# skills to build an event model like this, but will volunteer to put together an example of swap calculation code using external interest rate data if that helps.

QANTau avatar Mar 06 '15 00:03 QANTau

Great feedback thanks @QANTau. We will factor this into the design of the leverage fee calculations. Its probably best done in the transaction models class however it has some similarities to the Benchmark system.

One way to help would be starting with the source of the swap rate data, and how to import it into LEAN. It might be nice if this was standardized/similar to the way benchmark loads in data (https://github.com/QuantConnect/Lean/issues/30). If possible it would be sourced from a web-source like Yahoo to be self-updating.

jaredbroad avatar Mar 06 '15 23:03 jaredbroad

OANDA - Historical Interest Data: https://www.oanda.com/forex-trading/analysis/historical-rates

OANDA - How they calculate interest: https://oanda.secure.force.com/AnswersSupport?urlName=Interest-Rate-Calculation-1436196464449&language=en_US

jaredbroad avatar Dec 07 '18 04:12 jaredbroad

I provided a sample code to calculate interests..

https://www.quantconnect.com/forum/discussion/5460/calculate-rollover-interest-for-oanda/p1

It would be interesting if the model could attach the interests to the trade, as costs or contribution.

ebengtso avatar May 12 '19 11:05 ebengtso

Bitfinex interest rates: https://www.bitfinex.com/stats/#rates-on-margin-funding

Further info: https://support.bitfinex.com/hc/en-us/articles/214424645-What-interest-rate-is-charged-on-margin-positions-on-Bitfinex https://support.bitfinex.com/hc/en-us/articles/213919009-What-is-the-Bitfinex-Funding-Flash-Return-Rate

lucasbrynte avatar Aug 17 '22 14:08 lucasbrynte

Closing since Lean now supports this. Missing to implement the default margin interest rate model see https://github.com/QuantConnect/Lean/issues/6981

Martin-Molinero avatar Feb 20 '23 15:02 Martin-Molinero