You are on page 1of 2

<br><script language="JavaScript1.

2">
function calculatePrices(){
var spotPrice = 1.0 * getValue("spotPrice");
var callStrikePrice = 1.0 * getValue("callStrikePrice");
var callRate = 1.0 * getValue("callRate");
var putStrikePrice = 1.0 * getValue("putStrikePrice");
var putRate = 1.0 * getValue("putRate");

var actualCallRate = Math.ceil(100.0 * ((((callStrikePrice - spotPrice) -


(callStrikePrice - (callStrikePrice+putStrikePrice)/2.0))/(callStrikePrice -
spotPrice)) + 1) * callRate);
var actualPutRate = Math.ceil(100.0 * (1 -
((((callStrikePrice+putStrikePrice)/2.0 - putStrikePrice) - (spotPrice -
putStrikePrice))/(spotPrice - putStrikePrice))) * putRate);

var buyPercent = Math.ceil(10000.0 * actualCallRate/(actualCallRate +


actualPutRate));
var sellPercent = Math.ceil(10000.0 * actualPutRate/(actualCallRate +
actualPutRate));

var result = "The chances of Nifty Future going up is " + buyPercent/100.0


+ " % and going down is " + sellPercent/100.0 + " %";
if(buyPercent==sellPercent){
result = result + "<br/><h1 style='color:yellow'>TREND IS
NEUTRAL</h1>";
}else if(buyPercent>sellPercent){
result = result + "<br/><h1 style='color:green'>TREND IS UP</h1>";
}else{
result = result + "<br/><h1 style='color:red'>TREND IS DOWN</h1>";
}
document.getElementById("result").innerHTML = result;
}

function populateCallPutStrikePrice(){
var spotPrice = 1.0 * getValue("spotPrice");
if(getValue("spotPrice")!=null && getValue("spotPrice")!=""){
document.getElementById("userInput").style.display="block";
}else{
document.getElementById("userInput").style.display="none";
}
if(spotPrice%100>=0 && spotPrice%100<40){
setValue("callStrikePrice",Math.floor(spotPrice/100)*100 + 100 + "");
setValue("putStrikePrice",Math.floor(spotPrice/100)*100 - 100 + "");
}else if(spotPrice%100 >=40 && spotPrice%100<=60){
setValue("callStrikePrice",Math.floor(spotPrice/100)*100 + 100 + "");
setValue("putStrikePrice",Math.floor(spotPrice/100)*100 + "");
}else{
setValue("callStrikePrice",Math.floor(spotPrice/100)*100 + 200 + "");
setValue("putStrikePrice",Math.floor(spotPrice/100)*100 + "");
}
}

function getValue(id){
return document.getElementById(id).value;
}

function setValue(id,value){
document.getElementById(id).value = value;
}
</script>

You might also like