Porfoliovariance sumcovarm porfoliovariance 1

This preview shows pages 9–13. Sign up to view the full content.

PorfolioVariance = sum((covarM %*% Allocation)*Allocation) > PorfolioVariance [1] 0.01425122 #UNIT 7 ############################################################################## #Binomial Option Pricing Model #Call Example 7.1 genPriceLattice <- function(S=100, up=0.25, down=-0.1, N=1) { u=1+up d=1+down X <- c() X[1] <- S count <- 2 for (i in 1:N) { for (j in 0:i) { X[count] <- S * d^j * u^(i-j) count <- count + 1 } } count=1 M=matrix(0, rep( (N+1)*(N+1)), nrow=(N+1), ncol=(N+1)) for (i in 1:(N+1)) { for (j in 1:(N+1)) { if (j<=i) { M[j,i]=X[count] count=count+1 } } } return (M) } # genPriceLattice(S=40, up=+0.25, down=-0.1, N=1) # genPriceLattice(S=44.44, up=+0.25, down=-0.1, N=1) # genPriceLattice(S=60, u=0.1, d=-0.05, N=2) # r is interest rate getOnePeriodOptionsPrice=function(S_t0, K, r, up, down)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
{ u=1+up d=1+down S_t1u=S_t0 * u S_t1d=S_t0 * d C_t1u=max(0, S_t1u - K) C_t1d=max(0, S_t1d - K) C_t1=matrix(c(C_t1u, C_t1d), nrow=2, ncol=1) M=matrix( c( (u*S_t0), (1+r), (d*S_t0), (1+r)), nrow=2, ncol=2, byrow=T) coeff=solve(M, C_t1) return (coeff[1,1]*S_t0+coeff[2,1]) } # getOnePeriodOptionsPrice(40, 45, 0.05, 0.25 ,-0.1) getOnePeriodPreviousOptionsPrice=function(S_t1u, S_t1d, C_t1u,C_t1d, r, up, down) { u=1+up d=1+down S_t0=S_t1u/u #be sure that S_t0 is also S_t1d/d #S_t1u=S_t0 * u #S_t1d=S_t0 * d #C_t1u=max(0, S_t1u - K) #C_t1d=max(0, S_t1d - K) C_t1=matrix(c(C_t1u, C_t1d), nrow=2, ncol=1) M=matrix( c( (S_t1u), (1+r), (S_t1d), (1+r)), nrow=2, ncol=2, byrow=T) coeff=solve(M, C_t1) return (coeff[1,1]*S_t0+coeff[2,1]) } # getOnePeriodPreviousOptionsPrice(50,36,5,0, 0.05, 0.25 ,-0.1) genOptionsPriceLattice = function(Sx=40, Kx=45, rx=0.05, upx=0.25, downx=-0.1, Nx=1) { P=genPriceLattice(Sx, upx, downx, Nx) M=matrix(0, rep( (Nx+1)*(Nx+1)), nrow=(Nx+1), ncol=(Nx+1)) for (i in 1:(Nx)) { ri=(Nx-i+1) for (j in 1:(Nx)) { rj=(Nx-j+1) if (ri<Nx & i<=j ) { M[rj,ri]= getOnePeriodPreviousOptionsPrice(P[rj,ri+1], P[rj+1,ri+1], M[rj,ri+1] ,M[rj+1,ri+1], rx, upx ,downx) } if (ri==Nx) { Ct1u =max(0, P[rj,ri+1]-K) M[rj,ri+1]=Ct1u Ct1d =max(0, P[rj+1,ri+1]-K) M[rj+1,ri+1]=Ct1d cat(P[rj,ri+1], P[rj+1,ri+1], Ct1u ,Ct1d, rx, upx ,downx,"\n") M[rj,ri]= getOnePeriodPreviousOptionsPrice(P[rj,ri+1], P[rj+1,ri+1], Ct1u ,Ct1d, rx, upx ,downx) } } }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
x=cbind(d1, d2, x1, x2) require ("neuralnet") net.out <- neuralnet(d1+d2~x1+x2, data=x, hidden=10, threshold=0.01) x1=ts(c(0.9,0.8,0.3,0.2)) x2=ts(c(0.76,0.4,0.7,0.22)) test=cbind( x1, x2) cbind(test, compute(net.out, test)\$net.result) #NEURAL NET RESULT
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern