Skip to content

Instantly share code, notes, and snippets.

@raulcontrerasrubio
raulcontrerasrubio / irswap.js
Created August 19, 2019 19:47
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.
@raulcontrerasrubio
raulcontrerasrubio / youtubeFilter.js
Last active December 9, 2019 16:38
Youtube video url filter
/*
* The aim of this file is get the correct video url from a youtube playlist to automatize the audio download with youtube-dl
*/
const fs = require('fs');
const filename = './videos.txt';
const lines = require('fs').readFileSync(filename, 'utf-8')
.split('\n')
.filter(Boolean);
/*
* https://locutus.io/php/strings/number_format/
* _number_format(number:number, decimals:number, decPoint:string, thousandsSep:string):string
* Returns a string which represents the number formatted
*/
const _number_format = (number, decimals, decPoint, thousandsSep) => {
// eslint-disable-line camelcase
number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
var n = !isFinite(+number) ? 0 : +number;