This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### Author: Wilson Mongwe | |
#### Date: 21/06/2015 | |
#### Website: www.wilsonmongwe.co.za | |
#### Title: Implementing the EM algorithm to the coin tossing example | |
####################### Simulating the population data ######################### | |
N= 10000 | |
numberOfCOins=2 | |
components = sample(1:numberOfCOins,prob=c(0.45,0.55),size=N,replace=TRUE) | |
thetas= c(0.7,0.2) ### probablity of obtaining a head on Coin 2 and Coin 3 respectively |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### Author: Wilson Mongwe | |
#### Date: 21/06/2015 | |
#### Website: www.wilsonmongwe.co.za | |
#### Title: This code is for implementing the EM algorithm to estimate paramters from a mixture | |
#### of three normal distributions. | |
########################### Simulating the population data ############################# | |
N= 10000 ### Number of draws from the mixture | |
normals= 3 ### number of normals in the mixture. We have chosen to use 3 in this example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### Author: Wilson Mongwe | |
#### Date: 05/10/2015 | |
#### Website: www.wilsonmongwe.co.za | |
#### Title: Training the nueral network for the jump test | |
#### This code tests fro the presence of jumps using nueral networks | |
#### Training the neural network ##### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(RQuantLib) | |
shinyServer(function(input, output) { | |
## The model class is the backbone of thsi application | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load packages ---- | |
library(shiny) | |
library(quantmod) | |
library(randomForest) | |
### The simulation functions | |
simulateJump=function(mu_,ss_,lambda_,mu2_,sigma_,TotalTime,delta,compare,size) | |
{ | |
Sn=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########## This code calculates non parametric estimates of the jump-difusion parameters ####### | |
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Creating a twitter authentication in R | |
#The infomation can be found under the "Keys and Acces Tokens" tab of your twitter aplication. | |
api_key <- "Enter your API key here" #This is called the: Consumer Key (API Key) | |
api_secret <- "Enter your secret API key here" #This is called the: Consumer Secret (API Secret) | |
access_token <- "Enter your access token here" #This is called the: Access Token | |
access_token_secret <- "Enter your secret access token here" #This is called the: Access Token Secret | |
#Run this code to set up the twitter authentication. | |
setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This code reads in the tweets from the timelines of the three news websites | |
#Note that there is a limit of 3200 tweets that can be extracted from a users timeline. | |
fin24Tweets <- userTimeline('Fin24', n=3200) | |
bdLiveTweets <- userTimeline('BDliveSA', n=3200) | |
moneyWebTweets <- userTimeline('Moneyweb', n=3200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Clean the tweets by removing silly symblos/characters | |
cleanTweets <- function(tweets) | |
{ | |
tweets = gsub("@", "", tweets) | |
tweets = gsub("@\\w+", " ", tweets) | |
tweets = gsub("https", "", tweets) | |
tweets <- gsub("[ |\t]{2,}", " ", tweets) | |
tweets <- gsub("[ |\t]{2,}", " ", tweets) | |
tweets <- gsub("amp", " ", tweets) | |
tweets <- gsub("^ ", "", tweets) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
texts_from_tweets=cleanTweets(texts_from_tweets) | |
tweets_corpus = Corpus(VectorSource(texts_from_tweets)) | |
tweets_corpus_cleaned<- tm_map(tweets_corpus, function(x)removeWords(x,stopwords())) | |
# create document term matrix applying some transformations | |
add_more_stopwords=c("reports","report","opinion","column","can","will","still","read","wants","says","national","world","sport","life","video", | |
"lunchbox","comment","must","miss","new","editorial","popular", "cartoon","international","national","politics","companies", | |
"business","day","top","week","markets","economy","subscribe" , "case","missed","ahead","editor","premium","tomorrow","stories", | |
"click","keep","needs","interview","moneyweb","year","soapbox","news","expo","register","today","need","now","podcast","lineup", | |
"bafana","line-up","reader","question","wednesday","conversation","money","company","writes","how", |
OlderNewer