Skip to content

Instantly share code, notes, and snippets.

@Shreyes2010
Shreyes2010 / Persistence.r
Created July 25, 2012 11:55
Persistence measure : Rolling regression
## Reading the relevent files
install.packages("zoo")
library(zoo)
ife <- read.csv("CPI_Data.csv")
ife_wpi <- read.csv("WPI_Data_1.csv")
# Function to compute Y-o-Y inflation rate
@Shreyes2010
Shreyes2010 / Result.R
Created May 31, 2012 19:10
Results from the adf.test()
Augmented Dickey-Fuller Test
data: Full sample
Dickey-Fuller = -2.4901, Lag order = 4, p-value = 0.3734
alternative hypothesis: stationary
Augmented Dickey-Fuller Test
data: First 80 obs
Dickey-Fuller = -2.9479, Lag order = 4, p-value = 0.1882
@Shreyes2010
Shreyes2010 / MOM_YOY.R
Created April 12, 2012 15:50
MOM vs YOY rates in inflation
a <- read.csv("Data.csv")
# Pretty functions to compute the MOM and YOY inflation rates
mom.inf <- function(series){
x <- rep(NA,length(series))
for(i in 2:length(series))x[i] <- ((series[i] - series[i-1])/series[i-1])*100
return(x)
}
@Shreyes2010
Shreyes2010 / IFE_Assignment.r
Created March 10, 2012 09:58
IFE_Assignment
data <- read.csv("IFE_Update.csv")
# Plotting the foreign reserves of all the countries
png("IR_Relative.png", height = 800, width = 1000)
par(mfrow = c(3, 2)) ## This is to specify the number of rows and columns you want for the plots
# India
plot(data$Index, (data$India.Millions/max(data$India.Millions[!is.na(data$India.Millions)])),
type="l", xlab= "Months", ylab= "Foreign reserves (in $ millions)", col="green", lwd = 2,
main ="India's foreign reserves since 2002")
@Shreyes2010
Shreyes2010 / GARCH.R
Created February 8, 2012 23:19
GARCH MLE codes
# Specifying functions:
CalcResiduals <- function(th, data) {
# Calculates the e_t and h_t for the GARCH(1, 1) model with given parameters.
#
# Argumentss:
# th: Parameters
# th[1] -> mean
# th[2] -> alpha.0
# th[3] -> alpha.1
@Shreyes2010
Shreyes2010 / R_codes_bond_kaggle.R
Created January 31, 2012 21:56
So far what I got with dealing with the NA's
############################################################################################
####################### READING THE RELEVANT FILES #########################################
train.data <- read.csv("train_sample.csv")
## Set seed for reproducing the random numbers
set.seed(10001)
## This is to confirm the selection of trade_price_last{1-10}
@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)
@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)
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 / 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