Skip to content

Instantly share code, notes, and snippets.

@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 / 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
###############################
## 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 / 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")
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*}
## 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")