Assignment 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 :
> plot(returns1,main=" Final Returns ploted against time from 10 th to 95th day of NSE Mid-cap Index ")
> 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
>
> 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 :
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
>
No comments:
Post a Comment