/* Calculation of critical price options on options */ static double CriticalValueOptionsOnOptions( int fCall, double X1, double X2, double T, double r, double b, double v) { double Si, ci, di; assert_valid_strike(X1); assert_valid_strike(X2); assert_valid_time(T); assert_valid_interest_rate(r); assert_valid_cost_of_carry(b); assert_valid_volatility(v); Si = X1; ci = gbs(fCall, Si, X1, T, r, b, v); di = delta(fCall, Si, X1, T, r, b, v); /* Newton-Raphson algorithm */ while(fabs(ci - X2) > epsilon) { Si = Si - (ci - X2) / di; ci = gbs(fCall, Si, X1, T, r, b, v); di = delta(fCall, Si, X1, T, r, b, v); } return Si; }
/* Arithmetic average rate option */ double TurnbullWakemanAsian( int fCall, double S, double SA, double X, double T, double T2, double tau, double r, double b, double v) { double m1, m2, bA, vA, t1, result; double b2, vv, bvv, b2vv, t22; assert_valid_price(S); assert_valid_price(SA); assert_valid_strike(X); assert_valid_time(T); assert_valid_time(T2); assert_valid_interest_rate(r); assert_valid_cost_of_carry(b); assert_valid_volatility(v); b2 = b * 2.0; vv= v * v; bvv = b+vv; b2vv = b2 + vv; t22 = pow(T2-tau, 2.0); m1 = (exp(b * T2) - exp(b * tau)) / (b * (T2 - tau)); m2 = 2.0 * exp(b2vv * T2) / (bvv * b2vv * t22) + 2.0 * exp(b2vv * tau) / (b * t22) * (1.0 / b2vv - exp(b * (T2 - tau)) / bvv); bA = log(m1) / T2; vA = sqrt(log(m2) / T2 - 2.0 * bA); t1 = T - T2; if (t1 > 0) { X = T / T2 * X - t1 / T2 * SA; result = gbs(fCall, S, X, T2, r, bA, vA) * T2 / T; } else result = gbs(fCall, S, X, T2, r, bA, vA); return result; }
/* Rho for the generalized Black and Scholes formula */ double rho(int fCall, double S, double X, double T, double r, double b, double v) { double result; assert_valid_price(S); assert_valid_strike(X); assert_valid_time(T); assert_valid_interest_rate(r); assert_valid_cost_of_carry(b); assert_valid_volatility(v); if(b == 0.0) result = -T * gbs(fCall, S, X, T, r, b, v); else { const double vst = v * sqrt(T); const double d1 = (log(S / X) + (b + pow2(v) / 2.0) * T) / (vst); const double d2 = d1 - vst; if(fCall) result = T * X * exp(-r * T) * cnd(d2); else result = -T * X * exp(-r * T) * cnd(-d2); } return result; }
GUTF8String DjVuTXT::get_xmlText(const int height) const { GP<ByteStream> gbs(ByteStream::create()); ByteStream &bs=*gbs; writeText(bs,height); bs.seek(0L); return bs.getAsUTF8(); }
void check_bsbisection(void) { double price, computed, facit = 0.35; int fCall = 0; double S = 75.0, X = 70.0, T = 0.5, r = 0.10, b = 0.05; price = gbs(fCall, S, X, T, r, b, facit); computed = BSbisection(fCall, S, X, T, r, b, price); assert_equal(computed, facit); }
/* NewtonRhapson for imp. vol of european options */ void check_NewtonRaphson_put(void) { int fCall = 0, ok; double S = 75.0, X = 70.0, T = 0.5, r = 0.10, v = 0.35; double computed, price = gbs(fCall, S, X, T, r, r, v); ok = NewtonRaphson(fCall, S, X, T, r, price, &computed); assert(ok); assert_equal(computed, v); ok = NewtonRaphson_put(S, X, T, r, price, &computed); assert(ok); assert_equal(computed, v); }
void lt_XMLParser::Impl::ChangeMeta( DjVuFile &dfile, const lt_XMLTags &tags ) { dfile.resume_decode(true); GP<ByteStream> gbs(ByteStream::create()); tags.write(*gbs,false); gbs->seek(0L); GUTF8String raw(gbs->getAsUTF8()); if(raw.length()) { //GUTF8String gs="<"+(metadatatag+(">"+raw))+"</"+metadatatag+">\n"); dfile.change_meta(raw+"\n"); }else { dfile.change_meta(GUTF8String()); } }
void madef(int n,int *a,char *s2){ int fd; int i,j; char *s; int bs; bs=gbs(); s=(char*)malloc(bs*sizeof(char)); (void)umask(0); if((fd=open("matrix.txt",O_WRONLY | O_CREAT | O_TRUNC, 0666))<0){ printf("Can't open file!\n"); exit(-1); } // write in file bs genstr(bs,s,bs); if((write(fd,s,bs))<0){ printf("Can't write a symbol!\n"); exit(-1); } if((write(fd," ",1))<0){ printf("Can't write spase!\n"); exit(-1); } // write size of matrix if((write(fd,s2,strlen(s2)))<0){ printf("Can't write n!\n"); exit(-1); } if((write(fd,"\n",1))<0){ printf("Can't write enter!\n"); exit(-1); } // write in file matrix for(i=0;i<n;i++){ for(j=0;j<n;j++){ genstr(bs,s,a[i*n+j]); if((write(fd,s,bs))<0){ printf("Can't write element of matrix!\n"); exit(-1); } if(j!=(n-1)) if((write(fd," ",1))<0){ printf("Can't write element of matrix!\n "); exit(-1); } } if(write(fd,"\n",1)<0){ printf("Can't write in file!\n"); exit(-1); } } free(s); if(close(fd)<0){ printf("Can't close file\n"); exit(-1); } }