Skip to content

Instantly share code, notes, and snippets.

@AndrewCraswell
Last active March 5, 2016 20:08
Show Gist options
  • Save AndrewCraswell/dae2d9f459726af60be3 to your computer and use it in GitHub Desktop.
Save AndrewCraswell/dae2d9f459726af60be3 to your computer and use it in GitHub Desktop.
Function to calculate the return from betting "No" on all reasonable markets in a PredictIt.com Linked market type.
// Function to calculate the return from betting "No" on all reasonable markets in a PredictIt.com Linked market type.
// Execute by browsing to the linked market overview, and pasting function into the Developer Console window (F12)
(function () {
// Get the prices of each "No" option.
var noList = $('#contractListTable .sharesDown > .sharesDown').text().split('¢').filter(function (item) {
// Filter out options not currently traded, or costing more than $0.96.
return !(item === '' || item.indexOf('None') > -1 || item >= 97);
}).map(function (item, idx) {
return parseInt(item) / 100;
}).sort();
var totalCost = noList.reduce((a, b) => a + b, 0);
var returns = noList.length -1;
var totalProfit = returns - totalCost;
var adjustedProfit = totalProfit * (totalProfit > 0 ? 0.9 : 1); // Adjusted after fees
var ror = adjustedProfit / totalCost;
console.clear();
console.log('Total Cost: $' + totalCost.toFixed(2));
console.log('Net Profit: $' + adjustedProfit.toFixed(2));
console.log('Rate of Return: ' + ror.toFixed(2) + '%');
// If the move is profitable, calculate how much investment would yield a easily measured return.
if (adjustedProfit > 0) {
console.log('It would cost $' + (10 / ror).toFixed(2) + ' to earn $10');
}
})();
@bluebatray
Copy link

Hey Andrew!

So I took your code and modified it. I noticed the formula you have is wrong. I actually thought PredictIt worked like how you had it too, until today when I found out it's far harder to get gains from No markets, all because of the PredictIt Tax. It's easy to test actually, simply go to any market, run your code and if it's 'good' then buy 1 share of each. Compare this with PredictIt's Risk Calculation and you should see the numbers are all over the place (I did this just to test your code and found that every single one was a loss for me, even though it showed a flat 5% gain. This took me about 3 hours to break down and understand what's going on, just to give you an idea. I have commented the code and put examples in there.

It still needs work but the formula should be right.

https://gist.github.com/bluebatray/1d6d351a4c90862a7bb9

Things that still need to be fixed/updated:

  • If you already bought shares, for some reason the numbers will get duplicated. DON'T USE IF YOU ALREADY HAVE SHARES
  • Right now on line 63 I have 'person 1, person 2', etc. It'd be nice to use the actual label of the person (or percent or whatever it is). This gets tricky because of the way the tags are nested.
  • I would like to find a way where shares are adjusted on a per answer basis to give an actual flat percent total. I don't know how to do this mathematically.

Also to note: line 63. If you uncomment that, you can see each answer's actual percent potential. May help you understand.

I would really like to work with you on this to perfect it for both of our benefits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment