Skip to content

Instantly share code, notes, and snippets.

@saru2020
Last active December 29, 2020 11:12
Show Gist options
  • Save saru2020/8ffbaeaa1a0e26093208d96789f2e731 to your computer and use it in GitHub Desktop.
Save saru2020/8ffbaeaa1a0e26093208d96789f2e731 to your computer and use it in GitHub Desktop.
Free Share Calc[Used to calculate the selling price of a stock given the no of bought shares & no of sold shares]// source https://jsbin.com/fopixis
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[add your bin description]">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Free Share Calc</title>
</head>
<body>
Calc to calculate the profit required to get 1 free stock/share
<script id="jsbin-javascript">
let buyPrice = 3496.67
let buyQuantity = 3
// let sellPrice = 6900
let sellQuantity = 2
var profit = 0
// profit = (sellPrice * sellQuantity) - (buyPrice * sellQuantity)
// console.log('profit: ' + profit)
let investedCapital = buyPrice * buyQuantity
//profit - investedCapital = requiredProfitForFreeShare
// var freeSharePrice = profit
var tempSellPrice = 0
while(parseInt(profit) <= parseInt(buyPrice)) {
tempSellPrice += 1
profit = (tempSellPrice * sellQuantity) - (investedCapital - buyPrice)
// console.log(tempSellPrice)
// console.log(profit)
}
// console.log('investedCapital: ' + investedCapital)
// console.log('profit: ' + profit)
console.log('The Final Sell Price should be: ' + tempSellPrice)
// console.log('some')
profit = (tempSellPrice * sellQuantity) - (buyPrice * sellQuantity)
console.log('Takehome profit: ' + profit)
</script>
<script id="jsbin-source-javascript" type="text/javascript">let buyPrice = 3496.67
let buyQuantity = 3
// let sellPrice = 6900
let sellQuantity = 2
var profit = 0
// profit = (sellPrice * sellQuantity) - (buyPrice * sellQuantity)
// console.log('profit: ' + profit)
let investedCapital = buyPrice * buyQuantity
//profit - investedCapital = requiredProfitForFreeShare
// var freeSharePrice = profit
var tempSellPrice = 0
while(parseInt(profit) <= parseInt(buyPrice)) {
tempSellPrice += 1
profit = (tempSellPrice * sellQuantity) - (investedCapital - buyPrice)
// console.log(tempSellPrice)
// console.log(profit)
}
// console.log('investedCapital: ' + investedCapital)
// console.log('profit: ' + profit)
console.log('The Final Sell Price should be: ' + tempSellPrice)
// console.log('some')
profit = (tempSellPrice * sellQuantity) - (buyPrice * sellQuantity)
console.log('Takehome profit: ' + profit)</script></body>
</html>
let buyPrice = 3496.67
let buyQuantity = 3
// let sellPrice = 6900
let sellQuantity = 2
var profit = 0
// profit = (sellPrice * sellQuantity) - (buyPrice * sellQuantity)
// console.log('profit: ' + profit)
let investedCapital = buyPrice * buyQuantity
//profit - investedCapital = requiredProfitForFreeShare
// var freeSharePrice = profit
var tempSellPrice = 0
while(parseInt(profit) <= parseInt(buyPrice)) {
tempSellPrice += 1
profit = (tempSellPrice * sellQuantity) - (investedCapital - buyPrice)
// console.log(tempSellPrice)
// console.log(profit)
}
// console.log('investedCapital: ' + investedCapital)
// console.log('profit: ' + profit)
console.log('The Final Sell Price should be: ' + tempSellPrice)
// console.log('some')
profit = (tempSellPrice * sellQuantity) - (buyPrice * sellQuantity)
console.log('Takehome profit: ' + profit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment