Skip to content

Instantly share code, notes, and snippets.

@josephdunn
Last active August 29, 2015 13:58
Show Gist options
  • Save josephdunn/9994098 to your computer and use it in GitHub Desktop.
Save josephdunn/9994098 to your computer and use it in GitHub Desktop.
# 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment