never executed always true always false
1 -- GENERATED by C->Haskell Compiler, version 0.28.8 Switcheroo, 25 November 2017 (Haskell)
2 -- Edit the ORIGNAL .chs file instead!
3
4
5 module QuantLib.Index
6 (
7 -- * Types
8 GenIndex
9 , Index
10 , HistoricalIndexAnalysis
11
12 -- * Constructors
13 , asIndex
14 , historicalIndexAnalysis
15
16 -- * Mutators
17 , addFixing
18 , addFixings
19 , clearFixings
20 , clearAllFixingHistories
21
22 -- * Inspectors
23 -- ** Index fixings
24 , name
25 , fixingCalendar
26 , fixing
27 , hasHistoricalFixing
28 , isValidFixingDate
29 , fixingHistory
30 , fixingHistoryNames
31 , fixingHistoryNameKey
32 -- ** Historical return analysis
33 , skipped
34 , mean
35 , standardDeviation
36 , skewness
37 , kurtosis
38 , minimumReturn
39 , maximumReturn
40 , semiVariance
41 , semiDeviation
42 , downsideVariance
43 , downsideDeviation
44 , percentile
45 , gaussianPercentile
46 , valueAtRisk
47 , potentialUpside
48 , gaussianPotentialUpside
49 , regret
50 , shortfall
51 , gaussianShortfall
52 , averageShortfall
53 , gaussianAverageShortfall
54 , gaussianValueAtRisk
55 , expectedShortfall
56 , gaussianExpectedShortfall
57 , covariance
58 , correlation
59 ) where
60 import qualified Foreign.C.String as C2HSImp
61 import qualified Foreign.C.Types as C2HSImp
62 import qualified Foreign.ForeignPtr as C2HSImp
63 import qualified Foreign.Marshal.Utils as C2HSImp
64 import qualified Foreign.Ptr as C2HSImp
65
66
67 import Control.Exception (mask_)
68 import QuantLib.Internal
69 import QuantLib.Internal.Common
70 import QuantLib.Internal.Type
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 -- |stores the historical fixing at the given date; the date must be the actual calendar date of the fixing, not a settlement date
86 addFixing :: (GenIndex idx) -> (Day) -> (Double) -- ^fixing
87 -> (Bool) -- ^forceOverwrite
88 -> IO ()
89 addFixing a1 a2 a3 a4 =
90 withIndex a1 $ \a1' ->
91 withDay a2 $ \a2' ->
92 let {a3' = realToFrac a3} in
93 let {a4' = C2HSImp.fromBool a4} in
94 preErrorCheck $ \a5' ->
95 addFixing'_ a1' a2' a3' a4' a5' >>
96 errorCheck a5'>>
97 return ()
98
99
100
101 -- |The index's own name, as QuantLib builds it -- for an interest-rate index the family name,
102 -- tenor and day counter, e.g. @\"Euribor6M Actual\/360\"@. This is the key QuantLib's
103 -- process-global fixing store uses, so it is the name a stored fixing is filed under.
104 name :: GenIndex idx -> IO String
105 name x = mask_ (nameRaw x)
106 nameRaw :: (GenIndex idx) -> IO ((String))
107 nameRaw a1 =
108 withIndex a1 $ \a1' ->
109 nameRaw'_ a1' >>= \res ->
110 peekDynString res >>= \res' ->
111 return (res')
112
113
114
115 -- |returns the calendar defining valid fixing dates
116 fixingCalendar :: (GenIndex idx) -> IO ((Calendar))
117 fixingCalendar a1 =
118 withIndex a1 $ \a1' ->
119 preErrorCheck $ \a2' ->
120 fixingCalendar'_ a1' a2' >>= \res ->
121 peekCalendar res >>= \res' ->
122 errorCheck a2'>>
123 return (res')
124
125
126
127 -- |returns the fixing at the given date, forecasting it if not available and /forecastTodaysFixing/ is true
128 fixing :: (GenIndex idx) -> (Day) -> (Bool) -- ^forecastTodaysFixing
129 -> IO ((Double))
130 fixing a1 a2 a3 =
131 withIndex a1 $ \a1' ->
132 withDay a2 $ \a2' ->
133 let {a3' = C2HSImp.fromBool a3} in
134 preErrorCheck $ \a4' ->
135 fixing'_ a1' a2' a3' a4' >>= \res ->
136 let {res' = realToFrac res} in
137 errorCheck a4'>>
138 return (res')
139
140
141
142 -- |whether a historical fixing has been stored for the given date
143 hasHistoricalFixing :: (GenIndex idx) -> (Day) -> IO ((Bool))
144 hasHistoricalFixing a1 a2 =
145 withIndex a1 $ \a1' ->
146 withDay a2 $ \a2' ->
147 preErrorCheck $ \a3' ->
148 hasHistoricalFixing'_ a1' a2' a3' >>= \res ->
149 let {res' = C2HSImp.toBool res} in
150 errorCheck a3'>>
151 return (res')
152
153
154
155 -- |whether the given date is a valid fixing date for this index
156 isValidFixingDate :: (GenIndex idx) -> (Day) -> IO ((Bool))
157 isValidFixingDate a1 a2 =
158 withIndex a1 $ \a1' ->
159 withDay a2 $ \a2' ->
160 preErrorCheck $ \a3' ->
161 isValidFixingDate'_ a1' a2' a3' >>= \res ->
162 let {res' = C2HSImp.toBool res} in
163 errorCheck a3'>>
164 return (res')
165
166
167
168 -- |Stores historical fixings as @(date, value)@ pairs; the date is the actual fixing date.
169 addFixings :: GenIndex idx -> [(Day, Double)] -> Bool -> IO ()
170 addFixings idx fixings forceOverwrite = qlIndexAddFixings idx dates values forceOverwrite
171 where (dates, values) = unzip fixings
172 qlIndexAddFixings :: (GenIndex idx) -> ([Day]) -> ([Double]) -> (Bool) -- ^forceOverwrite
173 -> IO ()
174 qlIndexAddFixings a1 a2 a3 a4 =
175 withIndex a1 $ \a1' ->
176 withDayArray a2 $ \(a2'1, a2'2) ->
177 withDoubleArrayRaw a3 $ \a3' ->
178 let {a4' = C2HSImp.fromBool a4} in
179 preErrorCheck $ \a5' ->
180 qlIndexAddFixings'_ a1' a2'1 a2'2 a3' a4' a5' >>
181 errorCheck a5'>>
182 return ()
183
184
185
186 -- |clears all stored historical fixings for this index
187 clearFixings :: (GenIndex idx) -> IO ()
188 clearFixings a1 =
189 withIndex a1 $ \a1' ->
190 preErrorCheck $ \a2' ->
191 clearFixings'_ a1' a2' >>
192 errorCheck a2'>>
193 return ()
194
195
196
197 -- |Returns every stored native fixing for this index, in ascending date order. This is a
198 -- snapshot copied out of QuantLib's process-global fixing store; it has no forecasting behavior.
199 fixingHistory :: GenIndex idx -> IO [(Day, Double)]
200 fixingHistory i = do
201 (ds, vs) <- qlIndexFixingHistory i
202 return $ zip ds vs
203 qlIndexFixingHistory :: (GenIndex idx) -> IO (([Day]), ([Double]))
204 qlIndexFixingHistory a1 =
205 withIndex a1 $ \a1' ->
206 preIntArray $ \(a2'1, a2'2) ->
207 preDoubleArray $ \(a3'1, a3'2) ->
208 preErrorCheck $ \a4' ->
209 qlIndexFixingHistory'_ a1' a2'1 a2'2 a3'1 a3'2 a4' >>
210 peekDayArray a2'1 a2'2>>= \a2'' ->
211 peekDoubleArray a3'1 a3'2>>= \a3'' ->
212 errorCheck a4'>>
213 return (a2'', a3'')
214
215
216
217 -- |Returns the names with an entry in QuantLib's process-global fixing store. Names are
218 -- case-insensitive in that store and can be shared by separate index instances.
219 fixingHistoryNames :: IO (([String]))
220 fixingHistoryNames =
221 preCStringArray $ \(a1'1, a1'2) ->
222 preErrorCheck $ \a2' ->
223 fixingHistoryNames'_ a1'1 a1'2 a2' >>
224 peekCStringArray a1'1 a1'2>>= \a1'' ->
225 errorCheck a2'>>
226 return (a1'')
227
228
229
230 -- |Normalizes a native history name with IndexManager's bytewise case-insensitive
231 -- comparison. Use this key for ownership registries; Unicode case folding differs.
232 fixingHistoryNameKey :: (String) -- ^nativeName
233 -> IO ((String))
234 fixingHistoryNameKey a1 =
235 C2HSImp.withCString a1 $ \a1' ->
236 preErrorCheck $ \a2' ->
237 fixingHistoryNameKey'_ a1' a2' >>= \res ->
238 peekDynString res >>= \res' ->
239 errorCheck a2'>>
240 return (res')
241
242
243
244 -- |Clears every native fixing history in QuantLib's process-global store, for all index names.
245 -- This affects other index instances and is intended for explicit session or test cleanup.
246 clearAllFixingHistories :: IO ()
247 clearAllFixingHistories =
248 preErrorCheck $ \a1' ->
249 clearAllFixingHistories'_ a1' >>
250 errorCheck a1'>>
251 return ()
252
253
254
255 -- |Computes 'SequenceStatistics' (mean\/standard deviation\/skewness\/kurtosis\/min\/max\/semi-
256 -- and downside-variance and -deviation\/percentiles\/value-at-risk\/expected shortfall,
257 -- empirical and gaussian-assumption\/covariance\/correlation) over historical fixings of the
258 -- given indexes, sampled every @step@ between @startDate@ and @endDate@. A date/index pair whose
259 -- fixing is unavailable is recorded in 'skipped' rather than failing the whole analysis.
260 -- 'SequenceStatistics' is only the accumulator filled internally by this constructor, so its
261 -- risk-statistics surface is exposed directly through these accessors.
262 historicalIndexAnalysis :: (Day) -- ^startDate
263 -> (Day) -- ^endDate
264 -> ((Int,TimeUnit)) -- ^step
265 -> ([GenIndex idx]) -> IO ((HistoricalIndexAnalysis))
266 historicalIndexAnalysis a1 a2 a3 a4 =
267 withDay a1 $ \a1' ->
268 withDay a2 $ \a2' ->
269 let {(a3'1, a3'2) = fromEnumQuantity a3} in
270 withIndexArray a4 $ \(a4'1, a4'2) ->
271 preErrorCheck $ \a5' ->
272 historicalIndexAnalysis'_ a1' a2' a3'1 a3'2 a4'1 a4'2 a5' >>= \res ->
273 peekHistoricalIndexAnalysis res >>= \res' ->
274 errorCheck a5'>>
275 return (res')
276
277
278
279 -- |Skipped fixing dates paired with the reason no complete fixing vector was available.
280 skipped :: HistoricalIndexAnalysis -> IO [(Day, String)]
281 skipped analysis = do
282 dates <- qlHistoricalIndexAnalysisSkippedDates analysis
283 messages <- qlHistoricalIndexAnalysisSkippedMessages analysis
284 pure (zip dates messages)
285 qlHistoricalIndexAnalysisSkippedDates :: (HistoricalIndexAnalysis) -> IO (([Day]))
286 qlHistoricalIndexAnalysisSkippedDates a1 =
287 withHistoricalIndexAnalysis a1 $ \a1' ->
288 preIntArray $ \(a2'1, a2'2) ->
289 preErrorCheck $ \a3' ->
290 qlHistoricalIndexAnalysisSkippedDates'_ a1' a2'1 a2'2 a3' >>
291 peekDayArray a2'1 a2'2>>= \a2'' ->
292 errorCheck a3'>>
293 return (a2'')
294
295
296 qlHistoricalIndexAnalysisSkippedMessages :: (HistoricalIndexAnalysis) -> IO (([String]))
297 qlHistoricalIndexAnalysisSkippedMessages a1 =
298 withHistoricalIndexAnalysis a1 $ \a1' ->
299 preCStringArray $ \(a2'1, a2'2) ->
300 preErrorCheck $ \a3' ->
301 qlHistoricalIndexAnalysisSkippedMessages'_ a1' a2'1 a2'2 a3' >>
302 peekCStringArray a2'1 a2'2>>= \a2'' ->
303 errorCheck a3'>>
304 return (a2'')
305
306
307
308 -- |Per-index mean of the historical relative returns actually sampled.
309 mean :: (HistoricalIndexAnalysis) -> IO (([Double]))
310 mean a1 =
311 withHistoricalIndexAnalysis a1 $ \a1' ->
312 preDoubleArray $ \(a2'1, a2'2) ->
313 preErrorCheck $ \a3' ->
314 mean'_ a1' a2'1 a2'2 a3' >>
315 peekDoubleArray a2'1 a2'2>>= \a2'' ->
316 errorCheck a3'>>
317 return (a2'')
318
319
320
321 -- |Per-index standard deviation of the historical relative returns actually sampled.
322 standardDeviation :: (HistoricalIndexAnalysis) -> IO (([Double]))
323 standardDeviation a1 =
324 withHistoricalIndexAnalysis a1 $ \a1' ->
325 preDoubleArray $ \(a2'1, a2'2) ->
326 preErrorCheck $ \a3' ->
327 standardDeviation'_ a1' a2'1 a2'2 a3' >>
328 peekDoubleArray a2'1 a2'2>>= \a2'' ->
329 errorCheck a3'>>
330 return (a2'')
331
332
333
334 -- |Per-index skewness of the historical relative returns actually sampled.
335 skewness :: (HistoricalIndexAnalysis) -> IO (([Double]))
336 skewness a1 =
337 withHistoricalIndexAnalysis a1 $ \a1' ->
338 preDoubleArray $ \(a2'1, a2'2) ->
339 preErrorCheck $ \a3' ->
340 skewness'_ a1' a2'1 a2'2 a3' >>
341 peekDoubleArray a2'1 a2'2>>= \a2'' ->
342 errorCheck a3'>>
343 return (a2'')
344
345
346
347 -- |Per-index (excess) kurtosis of the historical relative returns actually sampled.
348 kurtosis :: (HistoricalIndexAnalysis) -> IO (([Double]))
349 kurtosis a1 =
350 withHistoricalIndexAnalysis a1 $ \a1' ->
351 preDoubleArray $ \(a2'1, a2'2) ->
352 preErrorCheck $ \a3' ->
353 kurtosis'_ a1' a2'1 a2'2 a3' >>
354 peekDoubleArray a2'1 a2'2>>= \a2'' ->
355 errorCheck a3'>>
356 return (a2'')
357
358
359
360 -- |Per-index minimum of the historical relative returns actually sampled.
361 minimumReturn :: (HistoricalIndexAnalysis) -> IO (([Double]))
362 minimumReturn a1 =
363 withHistoricalIndexAnalysis a1 $ \a1' ->
364 preDoubleArray $ \(a2'1, a2'2) ->
365 preErrorCheck $ \a3' ->
366 minimumReturn'_ a1' a2'1 a2'2 a3' >>
367 peekDoubleArray a2'1 a2'2>>= \a2'' ->
368 errorCheck a3'>>
369 return (a2'')
370
371
372
373 -- |Per-index maximum of the historical relative returns actually sampled.
374 maximumReturn :: (HistoricalIndexAnalysis) -> IO (([Double]))
375 maximumReturn a1 =
376 withHistoricalIndexAnalysis a1 $ \a1' ->
377 preDoubleArray $ \(a2'1, a2'2) ->
378 preErrorCheck $ \a3' ->
379 maximumReturn'_ a1' a2'1 a2'2 a3' >>
380 peekDoubleArray a2'1 a2'2>>= \a2'' ->
381 errorCheck a3'>>
382 return (a2'')
383
384
385
386 -- |Per-index variance of the historical relative returns falling below the mean.
387 semiVariance :: (HistoricalIndexAnalysis) -> IO (([Double]))
388 semiVariance a1 =
389 withHistoricalIndexAnalysis a1 $ \a1' ->
390 preDoubleArray $ \(a2'1, a2'2) ->
391 preErrorCheck $ \a3' ->
392 semiVariance'_ a1' a2'1 a2'2 a3' >>
393 peekDoubleArray a2'1 a2'2>>= \a2'' ->
394 errorCheck a3'>>
395 return (a2'')
396
397
398
399 -- |Per-index square root of 'semiVariance'.
400 semiDeviation :: (HistoricalIndexAnalysis) -> IO (([Double]))
401 semiDeviation a1 =
402 withHistoricalIndexAnalysis a1 $ \a1' ->
403 preDoubleArray $ \(a2'1, a2'2) ->
404 preErrorCheck $ \a3' ->
405 semiDeviation'_ a1' a2'1 a2'2 a3' >>
406 peekDoubleArray a2'1 a2'2>>= \a2'' ->
407 errorCheck a3'>>
408 return (a2'')
409
410
411
412 -- |Per-index variance of the historical relative returns falling below zero.
413 downsideVariance :: (HistoricalIndexAnalysis) -> IO (([Double]))
414 downsideVariance a1 =
415 withHistoricalIndexAnalysis a1 $ \a1' ->
416 preDoubleArray $ \(a2'1, a2'2) ->
417 preErrorCheck $ \a3' ->
418 downsideVariance'_ a1' a2'1 a2'2 a3' >>
419 peekDoubleArray a2'1 a2'2>>= \a2'' ->
420 errorCheck a3'>>
421 return (a2'')
422
423
424
425 -- |Per-index square root of 'downsideVariance'.
426 downsideDeviation :: (HistoricalIndexAnalysis) -> IO (([Double]))
427 downsideDeviation a1 =
428 withHistoricalIndexAnalysis a1 $ \a1' ->
429 preDoubleArray $ \(a2'1, a2'2) ->
430 preErrorCheck $ \a3' ->
431 downsideDeviation'_ a1' a2'1 a2'2 a3' >>
432 peekDoubleArray a2'1 a2'2>>= \a2'' ->
433 errorCheck a3'>>
434 return (a2'')
435
436
437
438 -- |Per-index empirical @y@-th percentile of the historical relative returns actually sampled;
439 -- @y@ must lie in @[0.9, 1.0)@.
440 percentile :: (HistoricalIndexAnalysis) -> (Double) -- ^y
441 -> IO (([Double]))
442 percentile a1 a2 =
443 withHistoricalIndexAnalysis a1 $ \a1' ->
444 let {a2' = realToFrac a2} in
445 preDoubleArray $ \(a3'1, a3'2) ->
446 preErrorCheck $ \a4' ->
447 percentile'_ a1' a2' a3'1 a3'2 a4' >>
448 peekDoubleArray a3'1 a3'2>>= \a3'' ->
449 errorCheck a4'>>
450 return (a3'')
451
452
453
454 -- |Per-index @y@-th percentile assuming the historical relative returns are gaussian; @y@ must lie in @[0.9, 1.0)@.
455 gaussianPercentile :: (HistoricalIndexAnalysis) -> (Double) -- ^y
456 -> IO (([Double]))
457 gaussianPercentile a1 a2 =
458 withHistoricalIndexAnalysis a1 $ \a1' ->
459 let {a2' = realToFrac a2} in
460 preDoubleArray $ \(a3'1, a3'2) ->
461 preErrorCheck $ \a4' ->
462 gaussianPercentile'_ a1' a2' a3'1 a3'2 a4' >>
463 peekDoubleArray a3'1 a3'2>>= \a3'' ->
464 errorCheck a4'>>
465 return (a3'')
466
467
468
469 -- |Per-index empirical value-at-risk at the given @centile@, which must lie in @[0.9, 1.0)@.
470 valueAtRisk :: (HistoricalIndexAnalysis) -> (Double) -- ^centile
471 -> IO (([Double]))
472 valueAtRisk a1 a2 =
473 withHistoricalIndexAnalysis a1 $ \a1' ->
474 let {a2' = realToFrac a2} in
475 preDoubleArray $ \(a3'1, a3'2) ->
476 preErrorCheck $ \a4' ->
477 valueAtRisk'_ a1' a2' a3'1 a3'2 a4' >>
478 peekDoubleArray a3'1 a3'2>>= \a3'' ->
479 errorCheck a4'>>
480 return (a3'')
481
482
483
484 -- |Per-index value-at-risk at the given @centile@ assuming the historical relative returns are gaussian; @centile@ must lie in @[0.9, 1.0)@.
485 gaussianValueAtRisk :: (HistoricalIndexAnalysis) -> (Double) -- ^centile
486 -> IO (([Double]))
487 gaussianValueAtRisk a1 a2 =
488 withHistoricalIndexAnalysis a1 $ \a1' ->
489 let {a2' = realToFrac a2} in
490 preDoubleArray $ \(a3'1, a3'2) ->
491 preErrorCheck $ \a4' ->
492 gaussianValueAtRisk'_ a1' a2' a3'1 a3'2 a4' >>
493 peekDoubleArray a3'1 a3'2>>= \a3'' ->
494 errorCheck a4'>>
495 return (a3'')
496
497
498
499 -- |Per-index empirical expected shortfall at the given @centile@, which must lie in @[0.9, 1.0)@.
500 -- Throws if no sampled return falls below the value-at-risk threshold.
501 expectedShortfall :: (HistoricalIndexAnalysis) -> (Double) -- ^centile
502 -> IO (([Double]))
503 expectedShortfall a1 a2 =
504 withHistoricalIndexAnalysis a1 $ \a1' ->
505 let {a2' = realToFrac a2} in
506 preDoubleArray $ \(a3'1, a3'2) ->
507 preErrorCheck $ \a4' ->
508 expectedShortfall'_ a1' a2' a3'1 a3'2 a4' >>
509 peekDoubleArray a3'1 a3'2>>= \a3'' ->
510 errorCheck a4'>>
511 return (a3'')
512
513
514
515 -- |Per-index expected shortfall at the given @centile@ assuming the historical relative returns
516 -- are gaussian; @centile@ must lie in @[0.9, 1.0)@.
517 gaussianExpectedShortfall :: (HistoricalIndexAnalysis) -> (Double) -- ^centile
518 -> IO (([Double]))
519 gaussianExpectedShortfall a1 a2 =
520 withHistoricalIndexAnalysis a1 $ \a1' ->
521 let {a2' = realToFrac a2} in
522 preDoubleArray $ \(a3'1, a3'2) ->
523 preErrorCheck $ \a4' ->
524 gaussianExpectedShortfall'_ a1' a2' a3'1 a3'2 a4' >>
525 peekDoubleArray a3'1 a3'2>>= \a3'' ->
526 errorCheck a4'>>
527 return (a3'')
528
529
530
531 -- |Per-index empirical potential upside at the given @centile@, which must lie in @[0.9, 1.0)@ --
532 -- the upside counterpart of 'valueAtRisk'.
533 potentialUpside :: (HistoricalIndexAnalysis) -> (Double) -- ^centile
534 -> IO (([Double]))
535 potentialUpside a1 a2 =
536 withHistoricalIndexAnalysis a1 $ \a1' ->
537 let {a2' = realToFrac a2} in
538 preDoubleArray $ \(a3'1, a3'2) ->
539 preErrorCheck $ \a4' ->
540 potentialUpside'_ a1' a2' a3'1 a3'2 a4' >>
541 peekDoubleArray a3'1 a3'2>>= \a3'' ->
542 errorCheck a4'>>
543 return (a3'')
544
545
546
547 -- |Per-index potential upside at the given @centile@ assuming the historical relative returns
548 -- are gaussian; @centile@ must lie in @[0.9, 1.0)@.
549 gaussianPotentialUpside :: (HistoricalIndexAnalysis) -> (Double) -- ^centile
550 -> IO (([Double]))
551 gaussianPotentialUpside a1 a2 =
552 withHistoricalIndexAnalysis a1 $ \a1' ->
553 let {a2' = realToFrac a2} in
554 preDoubleArray $ \(a3'1, a3'2) ->
555 preErrorCheck $ \a4' ->
556 gaussianPotentialUpside'_ a1' a2' a3'1 a3'2 a4' >>
557 peekDoubleArray a3'1 a3'2>>= \a3'' ->
558 errorCheck a4'>>
559 return (a3'')
560
561
562
563 -- |Per-index regret at the given @target@: expected loss below target, conditional on being below it.
564 regret :: (HistoricalIndexAnalysis) -> (Double) -- ^target
565 -> IO (([Double]))
566 regret a1 a2 =
567 withHistoricalIndexAnalysis a1 $ \a1' ->
568 let {a2' = realToFrac a2} in
569 preDoubleArray $ \(a3'1, a3'2) ->
570 preErrorCheck $ \a4' ->
571 regret'_ a1' a2' a3'1 a3'2 a4' >>
572 peekDoubleArray a3'1 a3'2>>= \a3'' ->
573 errorCheck a4'>>
574 return (a3'')
575
576
577
578 -- |Per-index empirical probability of falling below @target@.
579 shortfall :: (HistoricalIndexAnalysis) -> (Double) -- ^target
580 -> IO (([Double]))
581 shortfall a1 a2 =
582 withHistoricalIndexAnalysis a1 $ \a1' ->
583 let {a2' = realToFrac a2} in
584 preDoubleArray $ \(a3'1, a3'2) ->
585 preErrorCheck $ \a4' ->
586 shortfall'_ a1' a2' a3'1 a3'2 a4' >>
587 peekDoubleArray a3'1 a3'2>>= \a3'' ->
588 errorCheck a4'>>
589 return (a3'')
590
591
592
593 -- |Per-index probability of falling below @target@ assuming the historical relative returns are gaussian.
594 gaussianShortfall :: (HistoricalIndexAnalysis) -> (Double) -- ^target
595 -> IO (([Double]))
596 gaussianShortfall a1 a2 =
597 withHistoricalIndexAnalysis a1 $ \a1' ->
598 let {a2' = realToFrac a2} in
599 preDoubleArray $ \(a3'1, a3'2) ->
600 preErrorCheck $ \a4' ->
601 gaussianShortfall'_ a1' a2' a3'1 a3'2 a4' >>
602 peekDoubleArray a3'1 a3'2>>= \a3'' ->
603 errorCheck a4'>>
604 return (a3'')
605
606
607
608 -- |Per-index empirical average shortfall (expected loss below @target@, unconditional) at the given @target@.
609 averageShortfall :: (HistoricalIndexAnalysis) -> (Double) -- ^target
610 -> IO (([Double]))
611 averageShortfall a1 a2 =
612 withHistoricalIndexAnalysis a1 $ \a1' ->
613 let {a2' = realToFrac a2} in
614 preDoubleArray $ \(a3'1, a3'2) ->
615 preErrorCheck $ \a4' ->
616 averageShortfall'_ a1' a2' a3'1 a3'2 a4' >>
617 peekDoubleArray a3'1 a3'2>>= \a3'' ->
618 errorCheck a4'>>
619 return (a3'')
620
621
622
623 -- |Per-index average shortfall at the given @target@ assuming the historical relative returns are gaussian.
624 gaussianAverageShortfall :: (HistoricalIndexAnalysis) -> (Double) -- ^target
625 -> IO (([Double]))
626 gaussianAverageShortfall a1 a2 =
627 withHistoricalIndexAnalysis a1 $ \a1' ->
628 let {a2' = realToFrac a2} in
629 preDoubleArray $ \(a3'1, a3'2) ->
630 preErrorCheck $ \a4' ->
631 gaussianAverageShortfall'_ a1' a2' a3'1 a3'2 a4' >>
632 peekDoubleArray a3'1 a3'2>>= \a3'' ->
633 errorCheck a4'>>
634 return (a3'')
635
636
637
638 toMatrixDouble :: (Word, Word, [Double]) -> Matrix Double
639 toMatrixDouble (r, c, d) = Matrix r c d
640
641 -- |Covariance matrix of the historical relative returns across indexes.
642 covariance :: HistoricalIndexAnalysis -> IO (Matrix Double)
643 covariance hra = toMatrixDouble <$> qlHistoricalIndexAnalysisCovariance hra
644 qlHistoricalIndexAnalysisCovariance :: (HistoricalIndexAnalysis) -> IO ((Word), (Word), ([Double]))
645 qlHistoricalIndexAnalysisCovariance a1 =
646 withHistoricalIndexAnalysis a1 $ \a1' ->
647 prePtr $ \a2' ->
648 prePtr $ \a3' ->
649 preDoubleArray $ \(a4'1, a4'2) ->
650 preErrorCheck $ \a5' ->
651 qlHistoricalIndexAnalysisCovariance'_ a1' a2' a3' a4'1 a4'2 a5' >>
652 peekWord a2'>>= \a2'' ->
653 peekWord a3'>>= \a3'' ->
654 peekDoubleArray a4'1 a4'2>>= \a4'' ->
655 errorCheck a5'>>
656 return (a2'', a3'', a4'')
657
658
659
660 -- |Correlation matrix of the historical relative returns across indexes.
661 correlation :: HistoricalIndexAnalysis -> IO (Matrix Double)
662 correlation hra = toMatrixDouble <$> qlHistoricalIndexAnalysisCorrelation hra
663 qlHistoricalIndexAnalysisCorrelation :: (HistoricalIndexAnalysis) -> IO ((Word), (Word), ([Double]))
664 qlHistoricalIndexAnalysisCorrelation a1 =
665 withHistoricalIndexAnalysis a1 $ \a1' ->
666 prePtr $ \a2' ->
667 prePtr $ \a3' ->
668 preDoubleArray $ \(a4'1, a4'2) ->
669 preErrorCheck $ \a5' ->
670 qlHistoricalIndexAnalysisCorrelation'_ a1' a2' a3' a4'1 a4'2 a5' >>
671 peekWord a2'>>= \a2'' ->
672 peekWord a3'>>= \a3'' ->
673 peekDoubleArray a4'1 a4'2>>= \a4'' ->
674 errorCheck a5'>>
675 return (a2'', a3'', a4'')
676
677
678
679 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
680
681 foreign import ccall safe "QuantLib/Index.chs.h qlIndexAddFixing"
682 addFixing'_ :: ((C2HSImp.Ptr (CIndex')) -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
683
684 foreign import ccall safe "QuantLib/Index.chs.h qlIndexName"
685 nameRaw'_ :: ((C2HSImp.Ptr (CIndex')) -> (IO (C2HSImp.Ptr C2HSImp.CChar)))
686
687 foreign import ccall safe "QuantLib/Index.chs.h qlIndexFixingCalendar"
688 fixingCalendar'_ :: ((C2HSImp.Ptr (CIndex')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCalendar)))))
689
690 foreign import ccall safe "QuantLib/Index.chs.h qlIndexFixing"
691 fixing'_ :: ((C2HSImp.Ptr (CIndex')) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))
692
693 foreign import ccall safe "QuantLib/Index.chs.h qlIndexHasHistoricalFixing"
694 hasHistoricalFixing'_ :: ((C2HSImp.Ptr (CIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt))))
695
696 foreign import ccall safe "QuantLib/Index.chs.h qlIndexIsValidFixingDate"
697 isValidFixingDate'_ :: ((C2HSImp.Ptr (CIndex')) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt))))
698
699 foreign import ccall safe "QuantLib/Index.chs.h qlIndexAddFixings"
700 qlIndexAddFixings'_ :: ((C2HSImp.Ptr (CIndex')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))))
701
702 foreign import ccall safe "QuantLib/Index.chs.h qlIndexClearFixings"
703 clearFixings'_ :: ((C2HSImp.Ptr (CIndex')) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))
704
705 foreign import ccall safe "QuantLib/Index.chs.h qlIndexFixingHistory"
706 qlIndexFixingHistory'_ :: ((C2HSImp.Ptr (CIndex')) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CInt)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))))
707
708 foreign import ccall safe "QuantLib/Index.chs.h qlIndexManagerHistories"
709 fixingHistoryNames'_ :: ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))
710
711 foreign import ccall safe "QuantLib/Index.chs.h qlIndexHistoryNameKey"
712 fixingHistoryNameKey'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr C2HSImp.CChar))))
713
714 foreign import ccall safe "QuantLib/Index.chs.h qlIndexManagerClearHistories"
715 clearAllFixingHistories'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))
716
717 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysis"
718 historicalIndexAnalysis'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CIndex'))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CHistoricalIndexAnalysis))))))))))
719
720 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisSkippedDates"
721 qlHistoricalIndexAnalysisSkippedDates'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CInt)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
722
723 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisSkippedDatesErrorMessage"
724 qlHistoricalIndexAnalysisSkippedMessages'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
725
726 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisMean"
727 mean'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
728
729 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisStandardDeviation"
730 standardDeviation'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
731
732 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisSkewness"
733 skewness'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
734
735 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisKurtosis"
736 kurtosis'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
737
738 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisMin"
739 minimumReturn'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
740
741 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisMax"
742 maximumReturn'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
743
744 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisSemiVariance"
745 semiVariance'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
746
747 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisSemiDeviation"
748 semiDeviation'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
749
750 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisDownsideVariance"
751 downsideVariance'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
752
753 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisDownsideDeviation"
754 downsideDeviation'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))
755
756 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisPercentile"
757 percentile'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
758
759 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisGaussianPercentile"
760 gaussianPercentile'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
761
762 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisValueAtRisk"
763 valueAtRisk'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
764
765 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisGaussianValueAtRisk"
766 gaussianValueAtRisk'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
767
768 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisExpectedShortfall"
769 expectedShortfall'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
770
771 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisGaussianExpectedShortfall"
772 gaussianExpectedShortfall'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
773
774 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisPotentialUpside"
775 potentialUpside'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
776
777 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisGaussianPotentialUpside"
778 gaussianPotentialUpside'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
779
780 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisRegret"
781 regret'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
782
783 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisShortfall"
784 shortfall'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
785
786 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisGaussianShortfall"
787 gaussianShortfall'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
788
789 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisAverageShortfall"
790 averageShortfall'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
791
792 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisGaussianAverageShortfall"
793 gaussianAverageShortfall'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))
794
795 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisCovariance"
796 qlHistoricalIndexAnalysisCovariance'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))))
797
798 foreign import ccall safe "QuantLib/Index.chs.h qlHistoricalIndexAnalysisCorrelation"
799 qlHistoricalIndexAnalysisCorrelation'_ :: ((C2HSImp.Ptr (CHistoricalIndexAnalysis)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))))