Jackpotjoy

# Category Archives: Risk

## Implement VaR back testing in Python

Introduction We are going to model a VaR Â back testing in Python, including customize confidence level, span of testing horizon, and statistic testing on VaR model and binomial test . even in most case , functional programming will supply thisÂ practiceÂ enough , but I'll do it in OO for a more clearÂ demonstration. Model a VaR let's see full code first, and broke them into segments and analysis by parts . class VaR(): def __init__(self, return_list, conf = 0.95, n = 100): self.return_list Read more [...]

## Blackâ€“Scholes Option Pricing/Greeks in Python

Black-Scholes Option Pricing Equation is widely accepted in industry, in this post, I'd like to dive into a guide Â on how to implement BS equation in Python. BS formula to calculate EURO call Option: $C = S * N\left ( d1 \right ) - K * e^{-r*t} * N\left ( d2 \right )$ C : price of the European call option , r : risk free rate, t : time to maturity S : Spot price , K: Strike price, $N\left ( dx \right )$ :Â cumulative distribution function of the standard normal distribution d1 Read more [...]

## Lets get CAIA started !

start to prepare my CAIA exam in 2013 march.

## VaR Measurement with PerformanceAnalystics in R

VaR is most popular risk measurement of downside risk in recent years. It can aggregate risk across products departments ,and even across different risk type. Â I am going to dive into the VaR() function in the package "PerformanceAnalystics" Here Â is full parameter of function VaR() VaR(R = NULL, p = 0.95, method = c("modified", "gaussian","historical", "kernel")...) R can be assign a data.frame, vector, matrix, or xts, timeSeries object etc . p is assigned Read more [...]

## Implement Portfolio Variance Calculation in R

It is critical to calculate total variance of portfolio given inputs of variance of assets within the portfolio . Â  There is a little hardship in dealing with the correlation of the assets . Â  Interaction for each pair of assets should be calculatedÂ separately. (See second term in below ) if we construct a function with input two vector, (weight vector andÂ volatilityÂ vector) it is quite easy to implement first term with R by above: sum(w^2 * s^2) for the second term , we need a correlation Read more [...]

## Implement Vasicek model in R

Changing Interest rate plays an significant important role inÂ Â In financial simulation. I've develop the this model in R. This model reference from wikipedia.org "a" refer to the speed of interest rate revert back to long term mean rate "b" "dt" refer to interval time, sigma refer to impliedÂ volatilityÂ for changing interest rate , "dWt" refer to the changing dist for interest rate . ForÂ implementÂ this model, I simply construct a list ,and generate rates push in to the list via Read more [...]

## Fix Rate Mortgage Calculation in R

FoundationÂ of Mortgage Calculation Mortgage is a loan for buying a residential or commercial real estate which use underlying real estate as collateral . Borrower have to pay certain amount on every month during the mortgage period .(in US, it up to 30 years ). the amount Â is determined by following formula : ${Payment}_{monthly} = OrigLoanBalance * \frac{r*{\left(1+r \right)}^{T}}{{\left(1+r \right)}^{T}-1}$ T stands for Loan Term (in months) and r stands for monthly interest rate. As Read more [...]

## Caculate Bond Yield To Maturity in R

What is Yield to Maturity From wiki: "The Yield to maturity (YTM) or redemption yield of a bond or other fixed-interest security, such as gilts, is the internal rate of return (IRR, overall interest rate) earned by an investor who buys the bond today at the market price, assuming that the bond will be held until maturity, and that all coupon and principal payments will be made on schedule.â€œ In simple word, Yield to Maturity is a discount rate that equals future cash flow to current present Read more [...]