Skip to content

Instantly share code, notes, and snippets.

## 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")
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*}
@Shreyes2010
Shreyes2010 / R.codes
Created December 26, 2011 15:10
R codes
###############################
## 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")
###############################
## 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")
###################################################################
@Shreyes2010
Shreyes2010 / Problem_14.txt
Created January 4, 2012 07:33
Project Euler : problem 14
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
@Shreyes2010
Shreyes2010 / Problem_14.R
Created January 4, 2012 11:52
Solution to problem 14 in Euler
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
@Shreyes2010
Shreyes2010 / project_14_UT.R
Created January 4, 2012 12:29
Utkarsh solution
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
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
@Shreyes2010
Shreyes2010 / IS_LM_Functions.R
Created January 9, 2012 09:45
R codes for IS and LM curve
# 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)
@Shreyes2010
Shreyes2010 / AD_curve.R
Created January 9, 2012 09:50
Aggregate demand curve
# 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)