-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCode.Rmd
More file actions
113 lines (89 loc) · 2.18 KB
/
Copy pathtestCode.Rmd
File metadata and controls
113 lines (89 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
title: "CodeForC1"
author: "DABAJA"
date: "9/15/2017"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
To do:
- fix the directories and make sure the packages are uploading.
- doing some online editing - test
Instal packages
```{r Packages}
#install.packages(c("timeDate","mvtnorm","quadprog","quantreg","rgl","robustbase","scatterplot3d","SparseM","tseries"))
#install.packages("/Users/dawidjarosz/Dropbox/Semester\ 11/Statistical\ Analysis\ of\ Financial\ Data/Class\ 1/Rsafd", repos = NULL, type="source")
library(timeDate)
library(mvtnorm)
library(quadprog)
library(rgl)
library(robustbase)
library(scatterplot3d)
library(SparseM)
library(tseries)
library(Rsafd)
```
Load the data set: Rdata rdb - file with databases he works with in the book.
```{r}
lazyLoad(filebase = "/Users/dawidjarosz/Dropbox/Semester\ 11/Statistical\ Analysis\ of\ Financial\ Data/Class\ 1/Rsafd/data/Rdata",
envir = parent.frame())
```
```{r}
wn <- rnorm(1024)
```
Samuelson
```{r}
DELTAT <- 1/252
SIG <- .2*sqrt(DELTAT)
MU <- .15*DELTAT
TIME <- (1:1024)/252
STOCK <- rep(0,1024) #repeats a zero for every entry
```
Model
```{r}
for (i in 1:1024) {
STOCK[i] <- exp(SIG*RW[i] + MU*TIME[i]) # this is exponential
}
```
without a loop
```{r}
STOCK <- exp(SIG*RW + MU*TIME)
```
Plot
```{r}
plot(TIME, STOCK, type="l")
```
```{r}
head(HOWAREYOU)
```
Building function, Black and Scholes -
```{r}
S <- 100 #stock price
K <- S
R <- .4 #per year
SIG <- .2 #annualized vol
TAU <-90/252 #time to maturity, trading days.
d1 <- log(S/K) + TAU * (R+SIG^2/2)
d2 <- d1/(SIG*sqrt(TAU))
d2 <- d1 - SIG*sqrt(TAU)
```
Making a BS funciton, pricing a call.
bs_call <- function() #locally
fix(bs_call) #for any other script, use it a lot, this is how you'll have access to it later
# the function doesn't work
```{r}
bs_call <- function(S=100,
K=100,
R=.1,
SIG=2,
TAU=90/252){
d1 <- log(S/K) + TAU * (R+SIG^2/2)
d1 <- d1/(SIG*sqrt(TAU))
d2 <- d1 - SIG*sqrt(TAU)
c <- s*pnorm(d1) - K*exp(-R*TAU)*pnorm(d2)
return(c) }
```
```{r}
#bs_call(S=109, K=109, R=0.2)
```