This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Set the working directory using setwd() ## | |
# Reading the relevant file. | |
infy <- read.csv("01-10-2010-TO-01-10-2011INFYEQN.csv") | |
# Plotting the past one years closing price of INFY | |
plot(as.Date(infy$Date, "%d-%b-%y"), infy$Close.Price, xlab= "Dates", ylab= "Adjusted closing price", type='l', col='red', main="Adjusted closing price of INFOSYS for past 1 year") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Similarly for APT the mathematical form is: | |
\begin{eqnarray*} | |
R_i &=& a_j + \beta_{j1} F_1 + \beta_{j2} F_2 + \dots + \beta_{jn} F_n + \epsilon_j \\ | |
a_j &:& \mbox {constant for asset `j'}\\ | |
F_k &:& \mbox{ are systemic factors}\\ | |
\beta_{jk} &:& \mbox{ is the sensitivity of $j^{th}$ asset to factor `k'}\\ | |
\epsilon_j &:& \mbox{risky asset's idiosyncratic random shock with mean zero} | |
\end{eqnarray*} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################### | |
## Access the relevant files ## | |
############################### | |
returns <- read.csv("Returns_CNX_500.csv") | |
returns1 <- returns | |
nifty <- read.csv("Nifty_returns.csv") | |
mibor <- read.csv("MIBOR.csv", na.strings="#N/A") | |
exchange <- read.csv("Exchange_rates.csv", na.strings="#N/A") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################### | |
## Access the relevant files ## | |
############################### | |
returns <- read.csv("Returns_CNX_500.csv") | |
returns1 <- returns | |
nifty <- read.csv("Nifty_returns.csv") | |
mibor <- read.csv("MIBOR.csv", na.strings="#N/A") | |
exchange <- read.csv("Exchange_rates.csv", na.strings="#N/A") | |
################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Problem 14: | |
The following iterative sequence is defined for the set of positive integers: | |
n n/2 (n is even) | |
n 3n + 1 (n is odd) | |
Using the rule above and starting with 13, we generate the following sequence: | |
13 40 20 10 5 16 8 4 2 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shreyes <- function(temp) ## Cute function that returns the number of iterations that were preformed. | |
{ c <- 0 | |
while(temp > 1) | |
{ if(temp%%2==0) temp <- temp/2 else temp <- 3*temp + 1 | |
c <- c+1 | |
} | |
return(c) | |
} | |
largest <- 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
single.call <- function(limit) { # Another cute function that returns the vector that contains the number of iterations for each number. | |
memo <- rep(-1, limit) | |
memo[1] <- 0 | |
for(i in c(2:limit)) { | |
l <- 0 | |
n <- i | |
while(n >= i) { # Check only so long as "n > i" and not "1" this is basically the optimization we wanted. | |
l <- l + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Y = C + I + G + (X - M) | |
Y: Output produced in the economy | |
C: Total consumption demand | |
I: Total investment | |
G: Total govt. spending | |
X: Total value of exports | |
M: Total value of imports | |
We assume a closed economy so the identity boils down to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IS curve equation | |
# y = output; c = marginal propensity to consume; alpha = 1/(1-c) A = autonomous component; | |
# b = Senstivity to interest rates; i = interest rates | |
# I = I.0 - b*i (investment equation) | |
# y = alpha*A - alpha*b*i | |
IS.curve <- function(c, A, b, i) | |
{ | |
y = (1/(1-c))*A - (1/(1-c))*b*i | |
return(y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Aggregate demand curve | |
ad.curve <- function(c, A, b, ms, h, k ,y) # We are trying to arrive at a relation between | |
# Prices and output. | |
{ | |
alpha <- 1/(1-c) | |
omega <- (k/h) - (1/alpha*b) | |
P <- (ms/h)/(y*omega + (A/b)) # This is just basic algebra, you substitute "i" in terms of | |
# "P" and "Y" from the IS and LM equations and find a relation between prices and output. | |
return(P) |
OlderNewer