• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

boundedvariation/quantfin: quant finance in pure haskell

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

boundedvariation/quantfin

开源软件地址(OpenSource Url):

https://github.com/boundedvariation/quantfin

开源编程语言(OpenSource Language):

Haskell 100.0%

开源软件介绍(OpenSource Introduction):

quantfin

Quant Finance in Pure Haskell.

Initially I'm focusing on a Monte Carlo engine, but plenty more to come.

import Quant.Time
import Data.Monoid
import Quant.MonteCarlo
import Quant.YieldCurve
import Quant.ContingentClaim
import Quant.Models.Black
import Quant.Models.Heston

--create a flat yield curve with a 5% rate
baseYC :: FlatCurve
baseYC = FlatCurve 0.05 

black :: Black
black = Black 
			100     --initial stock price
			0.2     --volatility
			baseYC  --forward generator
			baseYC  --discount function

--make a vanilla put, struck at 100, maturing at time 1
vanopt :: ContingentClaim1
vanopt = vanillaOption Call 100 (Time 1) --built in function

vanopt' :: ContingentClaim1
vanopt' = specify $ do
	x <- monitor (Time 1)
	return $ CashFlow (Time 1) (max (x - 100) 0) --roll your own

--Run a Monte Carlo on opt in a a black model with 10000 trials
vanoptPrice :: Double
vanoptPrice = quickSim black vanopt 100000 

vanoptPrice' :: Double
vanoptPrice' = quickSim black vanopt' 100000 


--Make a call spread with a 100 unit notional, using some handy combinators.
cs :: ContingentClaim1
cs =  multiplier 100 
   $  vanillaOption Call 100 (Time 1) 
   <> short (vanillaOption Call 120 (Time 1)) 

--Run a Monte Carlo on the call spread; use antithetic variates
csPrice :: Double
csPrice = quickSim black' cs 100000 

black' :: Black
black' = Black 
			100     --initial stock price
			0.2     --volatility
			(NetYC (FlatCurve 0.05) (FlatCurve 0.02))  --forward generator, now with a 2% dividend yield
			baseYC  --discount rate

callSpreadAnti :: Double
callSpreadAnti = quickSimAnti black' cs 100000

--Let's try it with a Heston model
heston :: Heston
heston = Heston
		100
		0.04       --initial variance
		0.04       --final variance
		0.2        --volvol
		(-0.7)     --correlation between processes
		1.0        --mean reversion speed
		baseYC     --forward generator
		baseYC     --discount function

--price the call spread in the Heston model
csHeston :: Double
csHeston = quickSimAnti heston cs 100000

--create an option that pays off based on the square of its underlying
squareOpt :: ContingentClaim1
squareOpt = terminalOnly (Time 1) $ \x -> x*x  --using the built in function

squareOpt' :: ContingentClaim1
squareOpt' = specify $ do --roll your own
	x <- monitor (Time 1)
	return $ CashFlow (Time 1) $ x*x
squareOptPrice :: Double
squareOptPrice = quickSimAnti black squareOpt 100000

squareOptPrice' :: Double
squareOptPrice' = quickSimAnti black squareOpt' 100000


--create an option with a bizarre payoff
bizarre :: ContingentClaim1
bizarre = specify $ do
  x <- monitor (Time 1)   --check the price of asset 0 @ time 1
  y <- monitor (Time 2)   --check the price of asset 0 @ time 2
  z <- monitor (Time 3)   --check the price of asset 0 @ time 3
  return $ CashFlow (Time 4) $ sin x * cos y / (z ** sin x) --payoff @ time 4
bizarrePrice :: Double
bizarrePrice = quickSimAnti black bizarre 100000



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap