Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9004433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:53:39+00:00 2026-06-16T00:53:39+00:00

I am trying to see how winning percentage affects returns for a trading strategy.

  • 0

I am trying to see how “winning percentage” affects returns for a trading strategy.

I download the prices of S&P and calculating the daily returns. Then, I randomly select x% of these returns and say I correctly predicted it’s direction so the return is positive. For the remainder 1-x%, I say I am wrong and the return is negative. I replicate this process say 1000 times and collect the annualised geometric return.

I vary x from 0.5 to 0.6 at 0.01 increment intervals.

Here is my code:

library(quantmod)
library(multicore)

getSymbols("^GSPC", from = "1950-1-1")
ret <- ROC(GSPC)[-1,4]

set.seed(123)

winpct <- seq(0.5, 0.6, 0.01)
ret <- coredata(ret)

system.time(res <- simplify2array(mclapply(winpct, function(x) replicate(1000, drawsample(ret, x)))))

drawsample <- function(ret, winpct){
  len = length(ret)
  ret = abs(ret)

  win = sample(1:len, round(winpct * len))
  a = c(ret[win], -ret[-win])
  return(prod(1 + a) ^ (252 / length(a)) - 1)
}

Time taken:

   user  system elapsed 
 18.904   0.842   5.580 

Are there any further optimisations I can do to speed things up?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:53:40+00:00Added an answer on June 16, 2026 at 12:53 am

    I made the following two tweaks:

    1/ use exp(sum(a)) rather than prod(1+a). I think you want this anyways, as you have created a log returns series with ROC(GSPC)[-1,6]. According to rbenchmark this got me a speedup of about 7%.

    2/ sample from c(-1,-1) for the length of the ret series, and then multiply with the ret series, to obtain the signed series of returns. This got me another 30%.

    Note that in my code, i’ve re-named your a as bin.

    drawsample2 <- function(ret, winpct){
      len = length(ret)
      win = sample(c(-1,1), len, replace=TRUE, prob = c((1-winpct), winpct))
      ret <- abs(ret)
      bin <- ret*win
      return(exp(sum(bin))^(252/length(ret)) - 1)
    }
    

    Benchmarking against your drawsample() i get ~37% speedup.

    bb <- benchmark(simplify2array(mclapply(winpct, function(x) replicate(1000, drawsample(ret, x)))), 
              simplify2array(mclapply(winpct, function(x) replicate(1000, drawsample2(ret, x)))),
              columns =c('test', 'elapsed', 'relative'),
              replications = 10,
              order = 'elapsed')
    

    On my MBP, here are the benchmarks:

    > bb
    
      elapsed relative
    2  17.254    1.000
    1  27.734    1.607
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to see if the user has internet connection when the app
I'm trying to see if there is a way in rails routing to 'return'
I am trying to see if there is an existing row in my sqlite
I am trying to see if two images that the user clicked on are
I am trying to see if the controller class name is the name of
I'm trying to see if I have a correct understanding of prefetching with Core
I am trying to see from an SQL console what is inside an Oracle
I'm trying to see the value of a variable, but the debugger shows me
I'm trying to see if there is a way to build a Linq statement
I am trying to see if an element have a specific CSS attribute. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.