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