Skip to content

Instantly share code, notes, and snippets.

View WilsonMongwe's full-sized avatar

Wilson Mongwe WilsonMongwe

View GitHub Profile
@WilsonMongwe
WilsonMongwe / Create corpus.R
Created October 8, 2017 07:06
Analyzing a south african financial news corpus from twitter
library(httr)
library(httpuv)
library(RColorBrewer)
library(twitteR)
library(tm)
library(wordcloud)
library(base64enc)
library(devtools)
library(ROAuth)
#This is the code for the negative log likelihood function
#for the JUmp-difusion model
nll_jumps<-function(w)
{
mu=w[1] # drift
s=(w[2]) # diffsuive vol
lam=(w[3]) # jump frequency
mu_j=w[4] # jump size
simulateJump=function(mu_,ss_,lambda_,mu2_,sigma_,TotalTime,delta)
{
Sn=0
times <- c(0)
while(Sn <= TotalTime)
{
n <- length(times)
u <- runif(1)
expon <- -log(u)/lambda_
Sn <- times[n]+expon
library(DEoptim)
# Parameters
mu_= 0.05
ss_= 0.3
lambda_= 25
mu2_=0.01
sigma_=0.1
TotalTime = 50
delta=1/252
first_moment<-function(s_0,r,TotalTime)
{
(s_0*(exp(r*TotalTime)-1))/(r*TotalTime)
}
second_moment<-function(s_0,r,s,TotalTime)
{
part1 = (2*s_0^2)/(r*(r+s^2)*(2*r+s^2)*TotalTime^2)
part2 = r*exp((2*r+s^2)*TotalTime)-(2*r+s^2)*exp(r*TotalTime)+r+s^2