Skip to content

Instantly share code, notes, and snippets.

@bluebatray
Last active February 19, 2016 04:47
Show Gist options
  • Save bluebatray/1d6d351a4c90862a7bb9 to your computer and use it in GitHub Desktop.
Save bluebatray/1d6d351a4c90862a7bb9 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.
// Execute by browsing to the linked market overview, and pasting function into the Developer Console window (F12)
//
// The formula is as follows:
// Add up all the No's that will give profit (and adjust for predict it tax) NOTE: Do not count the answer that is a yes.
// This answer is a loss and is subtracted from the rest.
//
// Example: Rubio_No:47¢ Cruz_No:59¢ Kasich_No:94¢ Bush_No:95¢
//
// We buy 1 share of each. Now let's see how a Rubio_Yes would play out.
// Well we lose our 47¢ we bought his 'No' share for.
// Next, we add up all the profits WITH Predictit Tax deducted BUT we DON'T count Rubio, cause he won. 41(.9)+6(.9)+5(.9) = 46.8 respectively.
// Subtract our loss against it 46.8 (profit) - 47 = -.2 loss
//
// Let's see how a Cruz_Yes would play out
// Well we lose our 59¢ we bought his 'No' share for.
// Next, we add up all the profits WITH Predictit Tax deducted BUT we DON'T count Cruz, cause he won. 53(.9)+6(.9)+5(.9) = 57.6 respectively.
// Subtract our loss against it 57.6 (profit) - 59 = -1.4 loss
//
// Ok, so the formula, we want to go through each answer and add up all the No's that would give us money and subtract the No loss share.
// This is done looping through an our array of answers (in this case people) and an array within that. see below
(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;
});
// 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();
var highestPotentialPercent;
var lowestPotentialPercent;
//Go through the answers
for (i = 0; i < noList.length; i++) {
//console.log("Person " + (i+1) + ":" + noList[i]);
var adjustedTotal = 0;
//If there's a match, we want to ignore it (we're representing the answer that got a 'Yes')
//all that's left are the totals
for (j = 0; j < noList.length; j++) {
if(i!=j)
{
//add up adjusted total (how much we'd win, profit only)
adjustedTotal += (1-noList[j])*.9;
}
}
var percentGainOrLoss = ((adjustedTotal - noList[i])*100).toFixed(1);
//subtract total against the money we lost (whoever got the Yes which is 'i')
//console.log("Person " + (i+1) + ":" + percentGainOrLoss + "%");
if(highestPotentialPercent == null){
highestPotentialPercent = percentGainOrLoss;
}else{
if(highestPotentialPercent > percentGainOrLoss)
highestPotentialPercent = percentGainOrLoss;
}
if(lowestPotentialPercent == null){
lowestPotentialPercent = percentGainOrLoss;
}else{
if(lowestPotentialPercent < percentGainOrLoss)
lowestPotentialPercent = percentGainOrLoss;
}
}
if(lowestPotentialPercent > 0){
console.log('---GOOD BET---');
console.log('Lowest Potential Gain:' + lowestPotentialPercent + '%');
console.log('Highest Potential Gain:' + highestPotentialPercent + '%');
}else{
if(highestPotentialPercent < 0)
{
console.log('---BAD BET---');
console.log('Lowest Potential Loss:' + lowestPotentialPercent + '%');
console.log('Highest Potential Loss:' + highestPotentialPercent + '%');
}else{
console.log('---OK BET---');
console.log('Lowest Potential Loss:' + lowestPotentialPercent + '%');
console.log('Highest Potential Gain:' + highestPotentialPercent + '%');
}
}
//console.log('Total Profit: $' + totalProfit.toFixed(2));
//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');
//}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment