Skip to content

Instantly share code, notes, and snippets.

@raulcontrerasrubio
Created August 19, 2019 19:47
Show Gist options
  • Save raulcontrerasrubio/92d702500f27b1ddacb75a0dfadc48fe to your computer and use it in GitHub Desktop.
Save raulcontrerasrubio/92d702500f27b1ddacb75a0dfadc48fe to your computer and use it in GitHub Desktop.
Interest Rate Swap Arbitrage
/*
* Returns an array with the new interest rate when two companies (A and B) swap their interest rate on an arbitrage operation.
* [New cost for company A, new cost for company B]
* fixedA<number>: The fixed interest rate of a loan for the company A.
* variableA<number>: The variable interest rate of a loan for the company A.
* fixedB<number>: The fixed interest rate of a loan for the company B.
* variableB<number>: The variable interest rate of a loan for the company B.
* winA<number>: Part (between 0 and 1) of the arbitrage benefits company A will get.
* winB<number>: Part (between 0 and 1) of the arbitrage benefits company B will get.
* aIsFixed<boolean>: If true, the initial interest rate of A is fixed and the new interest rate is variable and viceversa.
* Remember to add the EURIBOR to the variable interest rate -> EURIBOR + New variable interest rate
*/
function irswap(fixedA, variableA, fixedB, variableB, winA = 0.5, winB = 0.5, aIsFixed = true){
if(isNaN(fixedA) || isNaN(fixedB) || isNaN(variableA) || isNaN(variableB) || isNaN(winA) || isNaN(winB)) throw new Error('All rates and shares must be numbers');
if(winA + winB !== 1) throw new Error('All wins must be shared');
const fixedDifferences = !!aIsFixed ? fixedB - fixedA : fixedA - fixedB;
const variableDifferences = !!aIsFixed ? variableB - variableA : variableA - variableB;
const arbitrageWins = fixedDifferences - variableDifferences;
return !!aIsFixed ? [variableA - arbitrageWins*winA, fixedB - arbitrageWins*winB] : [fixedA - arbitrageWins*winA, variableB - arbitrageWins*winB];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment