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
# original idea: http://mcarreira.typepad.com/mc_notes/2014/03/a-simple-model-for-the-pl-of-a-market-maker-how-many-losing-days-in-a-year.html | |
ndays <- 1e5; pl <- unlist(lapply(1:ndays, function(x) { sum((rbinom(7*60*10, 1, 0.525) - 0.5) * 2) })) ; 1 / (length(pl[pl < 0]) / ndays * 252) | |
# updated code demonstrating win vs. loss asymmetry with M/T. thanks @marascio and @MarcosCarreira for the suggestions. | |
# wins are 1.00, losses are -1.05 (normalized) | |
ndays <- 1e5; pl <- unlist(lapply(1:ndays, function(x) { sum(ifelse((rbinom(7*60*10, 1, 0.525) - 0.5) * 2 == -1, -1.05, 1)) })) ; 1 / (length(pl[pl < 0]) / ndays * 252) | |
# same as above - ifelse() is slow compared to writing the vector correctly the first time, but this is more cryptic. | |
# wins are 1.00, losses are -1.05 (normalized) | |
ndays <- 1e5; pl <- unlist(lapply(1:ndays, function(x) { sum(((1-rbinom(7*60*10, 1, 0.525))*-2.05)+1) })) ; 1 / (length(pl[pl < 0]) / ndays * 252) |
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
import numpy as np | |
ndays = int(1e5) | |
ntradesday = 7*60*10 | |
pl = np.sum((np.random.binomial(1, 0.525, (ndays, ntradesday))-0.5)*2, 1) | |
1.0 / (len(pl[pl < 0]) / float(ndays) * 252) |
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
winProb <- 0.525 | |
numBets <- c(1, 50, 1000, 10000, 100000) | |
runTimes <- 1000 | |
pl <- function(bets) | |
{ | |
sum(rbinom(bets, 1, winProb) - 0.5) | |
} | |
runs <- do.call(rbind, lapply(1:runTimes, function(x) { sapply(numBets, pl) })) |
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
hello milktrader! |
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(quantmod) | |
library(PerformanceAnalytics) | |
getSymbols('HEIA.AS', src='yahoo') | |
Return.cumulative(Return.calculate(get('HEIA.AS')['2010-12-31::'])) |
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
#!/usr/bin/ruby | |
def winloss | |
if rand(2) == 1 | |
return true | |
else | |
return false | |
end | |
end |
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
#!/usr/bin/ruby | |
def winloss | |
if rand(2) == 1 | |
return true | |
else | |
return false | |
end | |
end |
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
require 'rubygems' | |
require 'eventmachine' | |
require 'em-http-request' | |
require 'json' | |
EventMachine.run { | |
bid = 0.0 | |
ask = 0.0 | |
spread = 0.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
data <- read.table('TrAEX.xls', header=TRUE, sep='\t', skip=5, stringsAsFactors=FALSE) | |
data.xts <- xts(data$Quote, order.by=as.POSIXlt(data$Date...time, format='%H:%M:%S')) |
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
require(quantstrat) | |
# clean up | |
rm(list=ls(all=TRUE, pos=.blotter), pos=.blotter) | |
rm(list=ls(all=TRUE, pos=.instrument), pos=.instrument) | |
rm(list=ls(all=TRUE, pos=.strategy), pos=.strategy) | |
# set initial values | |
initDate <- '2011-08-05 06:00:00' | |
initEq <- 10000 |
OlderNewer