Friday, 29 March 2013

Assignment #10 : 26th March,2013


Assignment No 10


Problem 1:-
Ques-1 Create 3 vectors, x, y, z and choose any random values for them, ensuring they are of equal length,
T<- cbind(x,y,z)
Create 3 dimensional plot of the same (all 3 types)
Solution:-
Commands:-
> sample<-rnorm(50,25,6)
> x<-sample(sample,10)
> y<-sample(sample,10)
> z<-sample(sample,10)
> T<-cbind(x,y,z)
 Screenshots:-
Image
> plot3d(T)
Image
plot3d(T,col=rainbow(1000))
Image
plot3d(T,col=rainbow(1000),type=’s')
Image


Problem 2:-
Read the documentation of rnorm and pnorm and 
Create 2 random variables
Create 3 plots:
1. X-Y
2. X-Y|Z (introducing a variable z and cbind it to z and y with 5 diff categories) Hint: ?factor
3. Color code and draw the graph
4. Smooth and best fit line for the curve
Solution:-
Commands:-
> x<-rnorm(200,mean=5,sd=1)
> y<-rnorm(200,mean=3,sd=1)
> z1<-sample(letters,5)
> z2<-sample(z1,200,replace=TRUE)
> z<-as.factor(z2)
> t<-cbind(x,y,z)
Screenshots:-
Image
> qplot(x,y)
Image
> qplot(x,z,alpha=I(2/10))
Image
> qplot(x,z)

Image
> qplot(x,y,geom=c(“point”,”smooth”))
Image
> qplot(x,y,colour=z)
Image
> qplot(log(x),log(y),colour=z)
Image

Saturday, 23 March 2013

Assignment no.-9 ,March 19th, 2013

Assignment -: To analyse a data visualization tools and comment on its  usage.

TABLEAU PUBLIC

The data visualization tool that i have analysed is called Tableau Public.It is a premier tool used for business intelligence (BI). It can take data from various sources such as  MS excel, MS Access, SQL Server database,Oracle database, freeware dbs such as MySQL etc.


Data In. Brilliance Out.

Tableau Public is a free data storytelling application. One can create and share interactive charts and graphs, stunning maps, live dashboards and fun applications in minutes, then publish anywhere on the web. Anyone can do it, it’s that easy—and it’s free.


Scope of this tool : This tool can turn data into any number of visualizations, from simple to complex. You can drag and drop fields onto the work area and ask the software to suggest a visualization type, then customize everything from labels and tool tips to size, interactive filters and legend display.



Uniqueness: Tableau Public offers a variety of ways to display interactive data. You can combine multiple connected visualizations onto a single dashboard, where one search filter can act on numerous charts, graphs and maps; underlying data tables can also be joined. And once you get the hang of how the software works, its drag-and-drop interface is considerably quicker than manually coding in JavaScript or R for most users, making it more likely that you'll try additional scenarios with your data set. In addition, you can easily perform calculations on data within the software.
Drawbacks: In the free version of Tableau's business intelligence software, your visualization and data must reside on Tableau's site. Whenever you save your work, it gets sent up to the public website -- which means you can't save work in progress without running the risk that it will be seen before it's ready (while Tableau's site won't deliberately expose your work, it relies on security by obscurity -- so someone could see your work if they guess your URL). And once it's saved, viewers are invited to download your entire workbook with data. Upgrading to a single-user desktop edition costs $999.
Not surprisingly, all that functionality comes at a cost: Tableau's learning curve is fairly steep compared to that of, say, Fusion Tables. Even with the drag-and-drop interface, it'll take more than an hour or two to learn how to use the software's true capabilities, although you can get up and running doing simple charts and maps before too long.
Skill level: Advanced beginner to intermediate.
Runs on: Windows 7, Vista, XP, 2003, Server 2008, 2003.




     
Tableau Desktop Public Edition is Windows software only.

System Requirements:

  • Microsoft® Windows® 8, Windows 7, Windows Vista, Windows XP, Server 2012, Server 2008, Server 2003
  • 250 megabytes minimum free disk space
  • 32-bit or 64-bit versions of Windows
  • 32-bit color depth recommended
Note: Internet Explorer 6 is not supported.

Friday, 15 March 2013

Assignment- 8TH March,2013


Assignment no:-1
Perform Panel Data Analysis of “Produc” data
Solution:
There are three types of models:
  •       Pooled affect model
  •       Fixed affect model
  •       Random affect model 
We will be determining which model is the best by using functions:
      1) pFtest : for determining between fixed and pooled
      2) plmtest : for determining between pooled and random
      3) phtest: for determining between random and fixed
The data can be loaded using the following commands:-
data(Produc , package =”plm”)
head(Produc)
Screenshot:-
Image

Pooled Affect Model 
pool <-plm( log(pcap) ~log(hwy)+ log(water)+ log(util) + log(pc) + log(gsp) + log(emp) + log(unemp), data=Produc,model=(“pooling”),index =c(“state”,”year”))
summary(pool)
Screenshot:-
Image

Fixed Affect Model:
 
fixed<-plm( log(pcap) ~log(hwy)+ log(water)+ log(util) + log(pc) + log(gsp) + log(emp) + log(unemp), data=Produc,model=(“within”),index =c(“state”,”year”))
summary(fixed)
 
Screenshot:-
 
Image
 
 
Random Affect Model:
 
random <-plm( log(pcap) ~log(hwy)+ log(water)+ log(util) + log(pc) + log(gsp) + log(emp) + log(unemp), data=Produc,model=(“random”),index =c(“state”,”year”))
> summary(random)
 
Screenshot:-
 
Image
 
 
Testing of Model
 
This can be done through Hypothesis testing between the models as follows:
 
H0: Null Hypothesis: the individual index and time based params are all zero
H1: Alternate Hypothesis: atleast one of the index and time based params is non zero
 
Pooled vs Fixed
 
Null Hypothesis: Pooled Affect Model
Alternate Hypothesis : Fixed Affect Model
 
Command:
 > pFtest(fixed,pool)
 
Result:
data:  log(pcap) ~ log(hwy) + log(water) + log(util) + log(pc) + log(gsp) + log(emp) + log(unemp)
F = 56.6361, df1 = 47, df2 = 761, p-value < 2.2e-16
alternative hypothesis: significant effects 
Since the p value is negligible so we reject the Null Hypothesis and hence Alternate hypothesis is accepted which is to accept Fixed Affect Model.
 
Pooled vs Random
 
Null Hypothesis: Pooled Affect Model
Alternate Hypothesis: Random Affect Model
 
Command :
> plmtest(pool)
 
Result:
 
 Lagrange Multiplier Test – (Honda)
data:  log(pcap) ~ log(hwy) + log(water) + log(util) + log(pc) + log(gsp) + log(emp) + log(unemp)
normal = 57.1686, p-value < 2.2e-16
alternative hypothesis: significant effects 
 Since the p value is negligible so we reject the Null Hypothesis and hence Alternate hypothesis is accepted which is to accept Random Affect Model.
 
 
Random vs Fixed
 
Null Hypothesis: No Correlation . Random Affect Model
Alternate Hypothesis: Fixed Affect Model
 
Command:
 > phtest(fixed,random)
 
Result: 
 
 Hausman Test
data:  log(pcap) ~ log(hwy) + log(water) + log(util) + log(pc) + log(gsp) + log(emp) + log(unemp)
chisq = 93.546, df = 7, p-value < 2.2e-16
alternative hypothesis: one model is inconsistent . 
Since the p value is negligible so we reject the Null Hypothesis and hence Alternate hypothesis is accepted which is to accept Fixed Affect Model.
 
Conclusion: 
 
So after making all the tests we come to the conclusion that Fixed Affect Model is best suited to do the panel data analysis for “Produc” data set.
 
Hence , we conclude that within the same id i.e. within same “state” there is no variation. 

Wednesday, 13 February 2013

Assignment no-: 6 BIS Lab




Assignments 1: Create a log of the return data for NIFTY INDEX data from 01 jan 2012 to 31 jan 2013.

Log return can be obtained using following formula

(Log St-Log St-1)/ Log St-1  or Log((St-St-1)/ St-1))



COMMANDS:

> niftydata<-read.csv(file.choose(),header=T)
> closing<-niftydata$Close
> local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})

‘tseries’ version: 0.10-30

‘tseries’ is a package for time series analysis and computational
finance.

See ‘library(help="tseries")’ for details.

> closing.ts<-ts(closing,frequency=252)
> lagtable <- cbind(closing.ts,z<-lag(closing.ts, k=-1),z1<-(closing.ts-lag(closing.ts, k=-1)))
> logreturn<-((log(closing.ts)-log(z))/log(z))
> logreturn

Time Series:
Start = c(1, 2)
End = c(2, 22)
Frequency = 252
[1] 3.239464e-03 -3.884187e-04 7.460649e-06 1.031566e-04 -1.790094e-04 -1.020756e-04 2.629635e-03 2.766672e-04 -7.219539e-04 8.448814e-04 1.910705e-04
[12] 2.235372e-03 -2.723447e-04 1.475328e-03 7.041325e-04 -5.460200e-05 1.869905e-03 7.045035e-04 1.047569e-03 -2.666119e-03 2.550488e-03 8.164967e-04
[23] 7.603225e-04 1.232348e-03 7.807907e-04 -5.770056e-04 7.185143e-04 9.547984e-04 -6.627921e-04 1.858701e-04 5.568074e-04 2.462872e-03 -2.099390e-04
[34] 8.866876e-04 8.895253e-04 -2.122643e-03 -4.659254e-04 -1.149537e-03 -3.216077e-03 2.064680e-03 2.098882e-04 -9.865220e-04 4.268778e-04 1.086513e-06
[45] -1.730561e-03 -1.287406e-03 -4.362502e-05 2.503809e-03 5.666613e-04 1.510141e-03 7.344260e-04 -1.787318e-03 -1.362292e-03 -1.341494e-03 3.945467e-04
[56] 1.976128e-03 -3.001079e-03 1.106098e-03 -2.095349e-03 1.320797e-03 -1.082815e-03 -3.583088e-04 2.605582e-03 4.911754e-04 8.865537e-04 -7.763192e-04
[67] -1.954136e-03 2.050752e-04 -3.735635e-04 1.112008e-03 -1.544616e-03 4.199823e-04 1.410639e-03 2.268949e-04 7.107020e-04 -9.115485e-04 -2.006700e-03
[78] 4.944683e-04 -4.627824e-04 -2.924186e-04 3.604002e-05 4.136487e-04 8.749252e-04 -2.003778e-04 -1.136619e-03 -2.310752e-03 6.271584e-04 -2.644486e-03
[89] -5.920671e-04 -2.150921e-04 -8.740499e-04 -5.045429e-04 8.361626e-04 -2.028488e-03 2.894189e-04 5.127588e-04 3.508262e-04 -1.097620e-03 -6.038190e-04
[100] 2.071895e-03 -2.390384e-05 1.549669e-03 1.047839e-04 -9.297326e-04 -6.308823e-04 -1.990929e-03 1.593334e-04 3.676528e-04 3.196962e-03 1.228327e-03
[111] 4.334883e-04 -3.300435e-04 1.425141e-03 1.269615e-04 -1.534822e-03 1.939456e-03 -1.715955e-03 9.131466e-04 3.826181e-04 1.011969e-03 -4.299203e-04
[122] -7.161795e-04 1.407172e-04 4.814369e-04 1.648873e-04 2.911816e-03 -6.630323e-06 2.064695e-04 3.216062e-04 5.429964e-04 -2.266406e-04 -9.200411e-04
[133] 1.542443e-03 -8.541758e-04 -1.571732e-03 -1.785871e-04 -6.722646e-04 -9.899153e-05 5.266673e-04 5.897855e-04 -8.404042e-04 -1.973141e-03 2.342661e-04
[144] -4.253547e-04 -1.536500e-03 1.314838e-03 2.273528e-03 6.544701e-04 2.565831e-04 -2.844336e-04 -2.695327e-04 1.487906e-03 1.189729e-03 2.837990e-05
[155] -3.289665e-04 -5.584902e-05 6.009196e-04 7.046999e-04 -3.770709e-04 7.271941e-05 1.180923e-03 -1.749869e-04 5.371437e-05 -6.170252e-04 -7.902596e-04
[166] -3.412252e-04 -1.026760e-03 5.995619e-04 -1.246938e-03 -1.054797e-04 4.490623e-04 -1.073482e-03 2.835242e-04 2.289030e-03 3.614632e-04 1.031874e-04
[177] 5.750264e-04 8.819401e-04 9.309863e-05 3.004835e-03 6.703951e-04 -2.056453e-04 -9.515204e-04 2.823943e-03 -4.387549e-04 8.771891e-05 -2.132743e-04
[188] -2.853809e-04 1.097066e-03 3.138052e-04 2.513622e-04 1.130621e-03 -8.135789e-04 -1.435064e-03 5.814561e-04 -1.067965e-03 1.139085e-03 -6.499572e-04
[199] 2.280491e-04 -8.009879e-04 2.507867e-04 1.188888e-03 -6.984126e-04 6.675458e-04 -5.217950e-04 2.821077e-04 -8.338676e-04 2.655438e-05 -1.391002e-03
[210] 4.503694e-04 5.212828e-04 1.074665e-03 1.318438e-04 4.087192e-04 7.185322e-04 -4.288652e-04 -1.061865e-03 -5.188074e-05 -3.413826e-04 -7.363699e-04
[221] -1.177061e-03 -5.512835e-05 3.121345e-06 8.964977e-04 2.668488e-04 -2.366583e-05 1.912506e-04 1.865662e-03 1.951756e-03 1.081009e-03 -1.745294e-04
[232] 3.586398e-04 2.198437e-04 5.918464e-04 -4.569753e-04 2.923626e-05 -1.969952e-04 -2.110634e-04 -7.163435e-04 5.522762e-04 -4.260227e-04 7.629091e-04
[243] 6.388874e-04 -2.565234e-04 -1.344742e-03 1.585997e-04 9.771520e-04 -6.943370e-04 7.484690e-04 -6.335935e-05 8.887682e-04 8.168833e-04 3.112892e-04
[254] 1.271069e-04 -5.312741e-04 2.550707e-04 -5.798537e-04 -5.490448e-05 -3.348281e-04 1.397952e-03 6.191517e-04 -1.042707e-03 7.130947e-04 4.782958e-04
[265] 3.383743e-04 -6.395637e-04 1.100716e-04 -6.648065e-04 1.050830e-03 2.834345e-06 -4.714611e-04 1.109914e-04 -3.988862e-04
> T<-252^0.5
> historicalvolatility<-sd(logreturn)*T
> historicalvolatility
[1] 0.01719952



Assignments 2: Do ACF plot and ADF.

Command:

> acf(logreturn)
> adf.test(logreturn)

Thursday, 7 February 2013

Assignment: Day 5-: BIS LAB

1) Assignment 1: Download the data set for > 6 months and find returns having selected the 10th data point    as start and 95th data point as end.

Answer :


> k<-read.csv(file.choose(),header=T)
> k
           Date    Open    High     Low   Close Shares.Traded Turnover..Rs..Cr.
1   02-Jul-2012 5283.85 5302.15 5263.35 5278.60     126161441           4991.57
2   03-Jul-2012 5298.85 5317.00 5265.95 5287.95     133117055           5161.82
3   04-Jul-2012 5310.40 5317.65 5273.30 5302.55     155995887           5750.10
4   05-Jul-2012 5297.05 5333.65 5288.85 5327.30     118915392           4709.79
5   06-Jul-2012 5324.70 5327.20 5287.75 5316.95     113300726           4760.51
6   09-Jul-2012 5283.70 5300.60 5257.75 5275.15     101169926           4189.25
7   10-Jul-2012 5286.60 5348.55 5284.55 5345.35     123947633           5024.13
8   11-Jul-2012 5315.25 5336.45 5300.25 5306.30     113530679           5086.98
9   12-Jul-2012 5240.00 5261.75 5217.70 5235.25     131190833           6193.59
10  13-Jul-2012 5242.75 5267.15 5216.85 5227.25      99045088           4451.90
11  16-Jul-2012 5232.35 5246.85 5190.45 5197.25     106313144           4283.22
12  17-Jul-2012 5228.05 5236.70 5181.70 5192.85     111768115           4719.20
13  18-Jul-2012 5199.10 5222.85 5169.05 5216.30     109647297           4759.52
14  19-Jul-2012 5249.85 5257.75 5233.15 5242.70     109769282           5494.99
15  20-Jul-2012 5233.55 5238.70 5197.50 5205.10      89729408           4527.89
16  23-Jul-2012 5163.25 5164.20 5108.10 5117.95     104770324           4394.24
17  24-Jul-2012 5128.80 5144.00 5103.25 5128.20     116516931           4567.20
18  25-Jul-2012 5118.40 5121.60 5076.60 5109.60     130965621           4654.17
19  26-Jul-2012 5126.30 5126.30 5032.40 5043.00     180131639           6920.23
20  27-Jul-2012 5124.30 5149.95 5077.50 5099.85     131948378           5828.12
21  30-Jul-2012 5129.75 5206.60 5129.75 5199.80     117523733           5278.70
22  31-Jul-2012 5214.85 5234.55 5154.05 5229.00     147059808           6254.67
23  01-Aug-2012 5220.70 5246.35 5212.65 5240.50     113815730           4408.19
24  02-Aug-2012 5233.10 5236.90 5209.95 5227.75      92972386           3699.59
25  03-Aug-2012 5195.60 5220.20 5164.65 5215.70     112918653           4213.76
26  06-Aug-2012 5260.85 5293.20 5260.85 5282.55     103148076           4271.50
27  07-Aug-2012 5295.40 5350.10 5281.65 5336.70     130431591           5226.33
28  08-Aug-2012 5345.25 5377.60 5331.05 5338.00     165954895           6069.12
29  09-Aug-2012 5348.30 5368.20 5312.10 5322.95     181419777           6763.23
30  10-Aug-2012 5308.20 5330.10 5294.10 5320.40     130090985           6540.77
31  13-Aug-2012 5316.35 5352.45 5309.05 5347.90     107578773           4678.33
32  14-Aug-2012 5343.25 5387.05 5328.80 5380.35     109794400           4742.47
33  16-Aug-2012 5385.95 5390.65 5356.65 5362.95     133996943           5285.50
34  17-Aug-2012 5368.60 5399.95 5341.70 5366.30     134985473           5262.34
35  21-Aug-2012 5368.70 5425.15 5368.70 5421.00     124343357           4986.50
36  22-Aug-2012 5395.75 5433.35 5394.80 5412.85     103103501           4156.18
37  23-Aug-2012 5426.15 5448.60 5393.85 5415.35     127995889           5462.34
38  24-Aug-2012 5392.60 5399.65 5371.00 5386.70     114346965           4520.37
39  27-Aug-2012 5387.85 5399.15 5346.65 5350.25      89987572           3882.41
40  28-Aug-2012 5348.05 5359.25 5312.60 5334.60     123683723           4771.00
41  29-Aug-2012 5343.85 5345.50 5282.70 5287.80     157470632           4581.21
42  30-Aug-2012 5268.60 5342.80 5255.05 5315.05     226494000           8374.69
43  31-Aug-2012 5298.20 5303.25 5238.90 5258.50     167393902           6600.58
44  03-Sep-2012 5276.50 5295.80 5243.15 5253.75     110380869           4015.55
45  04-Sep-2012 5249.15 5278.35 5233.20 5274.00     106316880           3726.52
46  05-Sep-2012 5243.90 5259.50 5215.70 5225.70     126162071           4904.68
47  06-Sep-2012 5217.65 5260.60 5217.65 5238.40     134008569           4622.16
48  07-Sep-2012 5309.45 5347.15 5309.20 5342.10     149584722           5590.04
49  08-Sep-2012 5343.65 5366.30 5343.45 5358.70      11221064            376.34
50  10-Sep-2012 5361.90 5375.45 5349.10 5363.45     109607506           4183.01
51  11-Sep-2012 5336.10 5393.35 5332.10 5390.00     112878090           4081.42
52  12-Sep-2012 5404.45 5435.55 5393.95 5431.00     139920871           4885.71
53  13-Sep-2012 5435.20 5447.45 5421.85 5435.35     110774177           4199.37
54  14-Sep-2012 5528.35 5586.65 5526.95 5577.65     233783031           9263.53
55  17-Sep-2012 5631.75 5652.20 5585.15 5610.00     258912780          10924.57
56  18-Sep-2012 5602.40 5620.55 5586.45 5600.05     175488961           7272.63
57  20-Sep-2012 5536.95 5581.35 5534.90 5554.25     165684942           6768.88
58  21-Sep-2012 5577.00 5720.00 5575.45 5691.15     278023825          11101.32
59  24-Sep-2012 5691.95 5709.85 5662.75 5669.60     210419441           8380.56
60  25-Sep-2012 5674.90 5702.70 5652.45 5673.90     341387116          12551.60
61  26-Sep-2012 5653.40 5672.80 5638.65 5663.45     170771069           6754.98
62  27-Sep-2012 5673.75 5693.70 5639.70 5649.50     238991690           9368.11
63  28-Sep-2012 5684.80 5735.15 5683.45 5703.30     163660805           6948.17
64  01-Oct-2012 5704.75 5722.95 5694.00 5718.80     123138510           4798.17
65  03-Oct-2012 5727.70 5743.25 5715.80 5731.25     165037864           6654.02
66  04-Oct-2012 5751.55 5807.25 5751.35 5787.60     171404290           6954.74
67  05-Oct-2012 5815.00 5815.35 4888.20 5746.95     255569804          12995.80
68  08-Oct-2012 5751.85 5751.85 5666.20 5676.00     142319000           5853.56
69  09-Oct-2012 5708.15 5728.65 5677.90 5704.60     119300415           5047.01
70  10-Oct-2012 5671.15 5686.50 5647.05 5652.15     126294361           4564.39
71  11-Oct-2012 5663.50 5721.10 5636.95 5708.05     148283847           6542.71
72  12-Oct-2012 5681.70 5725.00 5659.35 5676.05     130076802           6475.30
73  15-Oct-2012 5674.25 5693.70 5651.05 5687.25      93693482           3962.97
74  16-Oct-2012 5705.60 5714.00 5635.60 5648.00     117415701           5043.30
75  17-Oct-2012 5681.10 5684.35 5633.90 5660.25     123974371           5259.46
76  18-Oct-2012 5675.30 5722.50 5650.55 5718.70     144097860           6264.78
77  19-Oct-2012 5703.30 5711.70 5660.00 5684.25     124262817           5410.95
78  22-Oct-2012 5667.60 5721.55 5658.05 5717.15     103372318           4994.75
79  23-Oct-2012 5715.65 5720.80 5681.45 5691.40      81501427           3803.50
80  25-Oct-2012 5688.80 5718.75 5685.70 5705.30     158343061           7359.34
81  26-Oct-2012 5683.55 5697.20 5641.75 5664.30     101663820           4718.97
82  29-Oct-2012 5665.20 5698.30 5645.10 5665.60      93555816           3953.86
83  30-Oct-2012 5656.35 5689.90 5589.90 5597.90     116678775           5550.86
84  31-Oct-2012 5596.75 5624.40 5583.05 5619.70     112075316           4918.55
85  01-Nov-2012 5609.85 5649.75 5601.95 5645.05     107393402           4633.11
86  02-Nov-2012 5696.35 5711.30 5682.55 5697.70     111162841           4924.33
87  05-Nov-2012 5693.05 5709.20 5679.50 5704.20      74829213           3236.08
88  06-Nov-2012 5694.10 5730.80 5693.65 5724.40     115018796           4677.92
89  07-Nov-2012 5718.60 5777.30 5711.40 5760.10     133740615           5242.18
90  08-Nov-2012 5709.00 5744.50 5693.95 5738.75     117590261           4883.90
91  09-Nov-2012 5731.10 5751.70 5677.75 5686.25      98763127           4833.64
92  12-Nov-2012 5688.45 5718.90 5665.75 5683.70      92702799           4082.62
93  13-Nov-2012 5689.70 5698.25 5660.35 5666.95      16516842            680.72
94  15-Nov-2012 5650.35 5651.65 5603.55 5631.00     133979470           5554.05
95  16-Nov-2012 5624.80 5650.15 5559.80 5574.05     121900570           4996.15
96  19-Nov-2012 5577.30 5592.75 5549.25 5571.40     106988015           4336.84
97  20-Nov-2012 5604.80 5613.70 5548.35 5571.55     107481297           4399.93
98  21-Nov-2012 5582.50 5620.20 5561.40 5614.80     105148728           4228.47
99  22-Nov-2012 5628.60 5643.35 5608.00 5627.75      94058612           3867.76
100 23-Nov-2012 5635.45 5637.75 5593.55 5626.60      85082220           3213.06
101 26-Nov-2012 5648.65 5649.20 5623.45 5635.90      79291426           3246.23
102 27-Nov-2012 5658.50 5733.20 5658.00 5727.45     134407735           5380.95
103 29-Nov-2012 5736.70 5833.50 5736.10 5825.00     207295475           9110.93
104 30-Nov-2012 5836.00 5885.25 5827.85 5879.85     257047977          10777.34
105 03-Dec-2012 5878.25 5899.15 5854.60 5870.95     113423350           4726.68
106 04-Dec-2012 5866.80 5894.95 5859.00 5889.25     131020191           4816.70
107 05-Dec-2012 5906.60 5917.80 5891.35 5900.50     139653957           5583.78
108 06-Dec-2012 5926.30 5942.55 5838.90 5930.90     140267080           5667.65
109 07-Dec-2012 5934.00 5949.85 5888.65 5907.40     127607078           5722.45
110 10-Dec-2012 5916.05 5919.95 5888.10 5908.90      95975757           4339.84
111 11-Dec-2012 5923.80 5965.15 5865.45 5898.80     137415161           6403.06
112 12-Dec-2012 5917.80 5924.60 5874.25 5888.00     132665649           6117.63
113 13-Dec-2012 5900.35 5907.45 5841.35 5851.50     136616335           5976.15
114 14-Dec-2012 5846.90 5886.10 5839.15 5879.60     115159830           5012.83
115 17-Dec-2012 5860.50 5886.05 5850.15 5857.90     109547002           4998.19
116 18-Dec-2012 5873.60 5905.80 5823.15 5896.80     148907334           6740.66
117 19-Dec-2012 5917.30 5939.40 5910.80 5929.60     149439204           6731.27
118 20-Dec-2012 5934.45 5937.60 5881.45 5916.40     123911218           5390.76
119 21-Dec-2012 5888.00 5888.00 5841.65 5847.70     141152911           5603.96
120 24-Dec-2012 5869.00 5871.90 5844.70 5855.75      85336999           3433.98
121 26-Dec-2012 5864.95 5917.30 5859.55 5905.60      83871326           3447.53
122 27-Dec-2012 5930.20 5930.80 5864.70 5870.10     139613235           5955.51
123 28-Dec-2012 5887.15 5915.75 5879.50 5908.35      89669021           3863.47
124 31-Dec-2012 5901.20 5919.00 5897.15 5905.10      64809641           3021.71
125 01-Jan-2013 5937.65 5963.90 5935.20 5950.85      77902745           3298.74
126 02-Jan-2013 5982.60 6006.05 5982.00 5993.25     116057389           4992.90
127 03-Jan-2013 6015.80 6017.00 5986.55 6009.50      99989933           4883.13
128 04-Jan-2013 6011.95 6020.75 5981.55 6016.15     113232990           5191.38
129 07-Jan-2013 6042.15 6042.15 5977.15 5988.40     110248018           5093.62
130 08-Jan-2013 5983.45 6007.05 5964.40 6001.70     109937502           5247.74
131 09-Jan-2013 6006.20 6020.10 5958.45 5971.50     129635568           6462.35
132 10-Jan-2013 5998.80 6005.15 5947.30 5968.65     129767384           6191.88
133 11-Jan-2013 6012.40 6018.85 5940.60 5951.30     128022002           8228.71
134 14-Jan-2013 5967.20 6036.90 5962.15 6024.05     134711348           7279.83
135 15-Jan-2013 6037.85 6068.50 6018.60 6056.60     138364003           6978.26
136 16-Jan-2013 6049.00 6055.95 5992.05 6001.85     128985952           6172.67
137 17-Jan-2013 6001.25 6053.20 5988.10 6039.20     178954867           7569.17
138 18-Jan-2013 6059.85 6083.40 6048.30 6064.40     186460701           8321.15
139 21-Jan-2013 6085.75 6094.35 6065.10 6082.30     130866385           6065.99
140 22-Jan-2013 6080.15 6101.30 6040.50 6048.50     129041713           5744.09
141 23-Jan-2013 6052.85 6069.80 6021.15 6054.30     136989190           5932.29
142 24-Jan-2013 6046.20 6065.30 6007.85 6019.35     185210189           7884.14
143 25-Jan-2013 6024.50 6080.55 6014.45 6074.65     147587200           6384.65
144 28-Jan-2013 6082.10 6088.40 6061.40 6074.80     113113004           5592.39
145 29-Jan-2013 6064.70 6111.80 6042.45 6049.90     157553752           8261.34
146 30-Jan-2013 6065.00 6071.95 6044.15 6055.75     124222858           6220.80
147 31-Jan-2013 6045.65 6058.05 6025.15 6034.75     168516750           8753.14
148 01-Feb-2013 6040.95 6052.95 5983.20 5998.90     159271140           6189.27
> close<-k[,5]
> close
  [1] 5278.60 5287.95 5302.55 5327.30 5316.95 5275.15 5345.35 5306.30 5235.25 5227.25 5197.25 5192.85 5216.30 5242.70 5205.10 5117.95 5128.20 5109.60 5043.00 5099.85
 [21] 5199.80 5229.00 5240.50 5227.75 5215.70 5282.55 5336.70 5338.00 5322.95 5320.40 5347.90 5380.35 5362.95 5366.30 5421.00 5412.85 5415.35 5386.70 5350.25 5334.60
 [41] 5287.80 5315.05 5258.50 5253.75 5274.00 5225.70 5238.40 5342.10 5358.70 5363.45 5390.00 5431.00 5435.35 5577.65 5610.00 5600.05 5554.25 5691.15 5669.60 5673.90
 [61] 5663.45 5649.50 5703.30 5718.80 5731.25 5787.60 5746.95 5676.00 5704.60 5652.15 5708.05 5676.05 5687.25 5648.00 5660.25 5718.70 5684.25 5717.15 5691.40 5705.30
 [81] 5664.30 5665.60 5597.90 5619.70 5645.05 5697.70 5704.20 5724.40 5760.10 5738.75 5686.25 5683.70 5666.95 5631.00 5574.05 5571.40 5571.55 5614.80 5627.75 5626.60
[101] 5635.90 5727.45 5825.00 5879.85 5870.95 5889.25 5900.50 5930.90 5907.40 5908.90 5898.80 5888.00 5851.50 5879.60 5857.90 5896.80 5929.60 5916.40 5847.70 5855.75
[121] 5905.60 5870.10 5908.35 5905.10 5950.85 5993.25 6009.50 6016.15 5988.40 6001.70 5971.50 5968.65 5951.30 6024.05 6056.60 6001.85 6039.20 6064.40 6082.30 6048.50
[141] 6054.30 6019.35 6074.65 6074.80 6049.90 6055.75 6034.75 5998.90
> close.ts<-ts(close)
> close.ts
Time Series:
Start = 1
End = 148
Frequency = 1
  [1] 5278.60 5287.95 5302.55 5327.30 5316.95 5275.15 5345.35 5306.30 5235.25 5227.25 5197.25 5192.85 5216.30 5242.70 5205.10 5117.95 5128.20 5109.60 5043.00 5099.85
 [21] 5199.80 5229.00 5240.50 5227.75 5215.70 5282.55 5336.70 5338.00 5322.95 5320.40 5347.90 5380.35 5362.95 5366.30 5421.00 5412.85 5415.35 5386.70 5350.25 5334.60
 [41] 5287.80 5315.05 5258.50 5253.75 5274.00 5225.70 5238.40 5342.10 5358.70 5363.45 5390.00 5431.00 5435.35 5577.65 5610.00 5600.05 5554.25 5691.15 5669.60 5673.90
 [61] 5663.45 5649.50 5703.30 5718.80 5731.25 5787.60 5746.95 5676.00 5704.60 5652.15 5708.05 5676.05 5687.25 5648.00 5660.25 5718.70 5684.25 5717.15 5691.40 5705.30
 [81] 5664.30 5665.60 5597.90 5619.70 5645.05 5697.70 5704.20 5724.40 5760.10 5738.75 5686.25 5683.70 5666.95 5631.00 5574.05 5571.40 5571.55 5614.80 5627.75 5626.60
[101] 5635.90 5727.45 5825.00 5879.85 5870.95 5889.25 5900.50 5930.90 5907.40 5908.90 5898.80 5888.00 5851.50 5879.60 5857.90 5896.80 5929.60 5916.40 5847.70 5855.75
[121] 5905.60 5870.10 5908.35 5905.10 5950.85 5993.25 6009.50 6016.15 5988.40 6001.70 5971.50 5968.65 5951.30 6024.05 6056.60 6001.85 6039.20 6064.40 6082.30 6048.50
[141] 6054.30 6019.35 6074.65 6074.80 6049.90 6055.75 6034.75 5998.90
> close.ts<-ts(close,deltat=252)
> close.ts
Time Series:
Start = 1
End = 37045
Frequency = 0.00396825396825397
  [1] 5278.60 5287.95 5302.55 5327.30 5316.95 5275.15 5345.35 5306.30 5235.25 5227.25 5197.25 5192.85 5216.30 5242.70 5205.10 5117.95 5128.20 5109.60 5043.00 5099.85
 [21] 5199.80 5229.00 5240.50 5227.75 5215.70 5282.55 5336.70 5338.00 5322.95 5320.40 5347.90 5380.35 5362.95 5366.30 5421.00 5412.85 5415.35 5386.70 5350.25 5334.60
 [41] 5287.80 5315.05 5258.50 5253.75 5274.00 5225.70 5238.40 5342.10 5358.70 5363.45 5390.00 5431.00 5435.35 5577.65 5610.00 5600.05 5554.25 5691.15 5669.60 5673.90
 [61] 5663.45 5649.50 5703.30 5718.80 5731.25 5787.60 5746.95 5676.00 5704.60 5652.15 5708.05 5676.05 5687.25 5648.00 5660.25 5718.70 5684.25 5717.15 5691.40 5705.30
 [81] 5664.30 5665.60 5597.90 5619.70 5645.05 5697.70 5704.20 5724.40 5760.10 5738.75 5686.25 5683.70 5666.95 5631.00 5574.05 5571.40 5571.55 5614.80 5627.75 5626.60
[101] 5635.90 5727.45 5825.00 5879.85 5870.95 5889.25 5900.50 5930.90 5907.40 5908.90 5898.80 5888.00 5851.50 5879.60 5857.90 5896.80 5929.60 5916.40 5847.70 5855.75
[121] 5905.60 5870.10 5908.35 5905.10 5950.85 5993.25 6009.50 6016.15 5988.40 6001.70 5971.50 5968.65 5951.30 6024.05 6056.60 6001.85 6039.20 6064.40 6082.30 6048.50
[141] 6054.30 6019.35 6074.65 6074.80 6049.90 6055.75 6034.75 5998.90
> close.ts<-ts(close,deltat=1/252)
> close.ts
Time Series:
Start = c(1, 1)
End = c(1, 148)
Frequency = 252
  [1] 5278.60 5287.95 5302.55 5327.30 5316.95 5275.15 5345.35 5306.30 5235.25 5227.25 5197.25 5192.85 5216.30 5242.70 5205.10 5117.95 5128.20 5109.60 5043.00 5099.85
 [21] 5199.80 5229.00 5240.50 5227.75 5215.70 5282.55 5336.70 5338.00 5322.95 5320.40 5347.90 5380.35 5362.95 5366.30 5421.00 5412.85 5415.35 5386.70 5350.25 5334.60
 [41] 5287.80 5315.05 5258.50 5253.75 5274.00 5225.70 5238.40 5342.10 5358.70 5363.45 5390.00 5431.00 5435.35 5577.65 5610.00 5600.05 5554.25 5691.15 5669.60 5673.90
 [61] 5663.45 5649.50 5703.30 5718.80 5731.25 5787.60 5746.95 5676.00 5704.60 5652.15 5708.05 5676.05 5687.25 5648.00 5660.25 5718.70 5684.25 5717.15 5691.40 5705.30
 [81] 5664.30 5665.60 5597.90 5619.70 5645.05 5697.70 5704.20 5724.40 5760.10 5738.75 5686.25 5683.70 5666.95 5631.00 5574.05 5571.40 5571.55 5614.80 5627.75 5626.60
[101] 5635.90 5727.45 5825.00 5879.85 5870.95 5889.25 5900.50 5930.90 5907.40 5908.90 5898.80 5888.00 5851.50 5879.60 5857.90 5896.80 5929.60 5916.40 5847.70 5855.75
[121] 5905.60 5870.10 5908.35 5905.10 5950.85 5993.25 6009.50 6016.15 5988.40 6001.70 5971.50 5968.65 5951.30 6024.05 6056.60 6001.85 6039.20 6064.40 6082.30 6048.50
[141] 6054.30 6019.35 6074.65 6074.80 6049.90 6055.75 6034.75 5998.90

> close.ts<-ts(data=close.ts[10:95],frequency=1,deltat=1/252)
> close.ts
Time Series:
Start = 1
End = 86
Frequency = 1
 [1] 5227.25 5197.25 5192.85 5216.30 5242.70 5205.10 5117.95 5128.20 5109.60 5043.00 5099.85 5199.80 5229.00 5240.50 5227.75 5215.70 5282.55 5336.70 5338.00 5322.95
[21] 5320.40 5347.90 5380.35 5362.95 5366.30 5421.00 5412.85 5415.35 5386.70 5350.25 5334.60 5287.80 5315.05 5258.50 5253.75 5274.00 5225.70 5238.40 5342.10 5358.70
[41] 5363.45 5390.00 5431.00 5435.35 5577.65 5610.00 5600.05 5554.25 5691.15 5669.60 5673.90 5663.45 5649.50 5703.30 5718.80 5731.25 5787.60 5746.95 5676.00 5704.60
[61] 5652.15 5708.05 5676.05 5687.25 5648.00 5660.25 5718.70 5684.25 5717.15 5691.40 5705.30 5664.30 5665.60 5597.90 5619.70 5645.05 5697.70 5704.20 5724.40 5760.10
[81] 5738.75 5686.25 5683.70 5666.95 5631.00 5574.05

> returns<-close.ts
> k.diff<-diff(close.ts)
> returns<-cbind(close.ts,k.diff,lag(close.ts,k=-1))
> returns<-cbind(close.ts,k.diff,lag(close.ts,k=-1),k.diff/lag(close.ts,k=-1))
> plot(returns,main=" Returns from 10 th to 95th day of NSE Mid-cap Index ")
> returns1<-returns[,4]
>  plot(returns1,main=" Final Returns ploted against time from 10 th to 95th day of NSE Mid-cap Index ")


2) Assignment 2: Also plot the results.

Answer :



> plot(returns1,main=" Final Returns ploted against time from 10 th to 95th day of NSE Mid-cap Index ")

3) Assignment 3 : 1 to 700 data is available , we need to predict  data 701 to 850

Answer:


> k<-read.csv(file.choose(),header=T)
> k1<-k[1:700,1:9]
> head(k1)
  age ed employ address income debtinc creddebt othdebt default
1  41  3     17      12    176     9.3    11.36    5.01       1
2  27  1     10       6     31    17.3     1.36    4.00       0
3  40  1     15      14     55     5.5     0.86    2.17       0
4  41  1     15      14    120     2.9     2.66    0.82       0
5  24  2      2       0     28    17.3     1.79    3.06       1
6  41  2      5       5     25    10.2     0.39    2.16       0
> k1$ed<-factor(k1$ed)
> k1.est<-glm(default ~ age + ed + employ + address + income + debtinc + creddebt + othedebt, data=k1, family ="binomial")
Error in eval(expr, envir, enclos) : object 'othedebt' not found
> k1.est<-glm(default ~ age + ed + employ + address + income + debtinc + creddebt + othdebt, data=k1, family ="binomial")
> summary(k1.est)

Call:
glm(formula = default ~ age + ed + employ + address + income +
    debtinc + creddebt + othdebt, family = "binomial", data = k1)

Deviance Residuals:
    Min       1Q   Median       3Q      Max
-2.4322  -0.6463  -0.2899   0.2807   3.0255

Coefficients:
             Estimate Std. Error z value Pr(>|z|)  
(Intercept) -1.589302   0.605324  -2.626  0.00865 **
age          0.035514   0.017588   2.019  0.04346 *
ed2          0.307623   0.251629   1.223  0.22151  
ed3          0.352448   0.339937   1.037  0.29983  
ed4         -0.085359   0.472938  -0.180  0.85677  
ed5          0.874942   1.293734   0.676  0.49886  
employ      -0.260737   0.033410  -7.804 5.99e-15 ***
address     -0.105426   0.023264  -4.532 5.85e-06 ***
income      -0.007855   0.007782  -1.009  0.31282  
debtinc      0.070551   0.030598   2.306  0.02113 *
creddebt     0.625177   0.112940   5.535 3.10e-08 ***
othdebt      0.053470   0.078464   0.681  0.49558  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 804.36  on 699  degrees of freedom
Residual deviance: 549.56  on 688  degrees of freedom
AIC: 573.56

Number of Fisher Scoring iterations: 6

> forecast<-k[701:850,1:8]
> forecast$ed<-factor(forecast$ed)
> forecast$probability<-predict(k1.est,newdata=forecast,type="response")
> head(forecast)
    age ed employ address income debtinc creddebt othdebt probability
701  36  1     16      13     32    10.9     0.54    2.94  0.00783975
702  50  1      6      27     21    12.9     1.32    1.39  0.07044926
703  40  1      9       9     33    17.0     4.88    0.73  0.63780431
704  31  1      5       7     23     2.0     0.05    0.41  0.07471587
705  29  1      4       0     24     7.8     0.87    1.01  0.34464735
706  25  2      1       3     14     9.9     0.23    1.15  0.45584645
>