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 8788269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:06:47+00:00 2026-06-13T22:06:47+00:00

A list of Equity Analytics (stocks) objects doing a calculation for daily returns. Was

  • 0

A list of Equity Analytics (stocks) objects doing a calculation for daily returns.
Was thinking there must be a pairwise solution to do this:

for(int i = 0; i < sdata.Count; i++){
    sdata[i].DailyReturn = (i > 0) ? (sdata[i-1].AdjClose/sdata[i].AdjClose) - 1
                                   : 0.0;
}
  • 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-13T22:06:48+00:00Added an answer on June 13, 2026 at 10:06 pm

    I’m new to LINQ, I started using it because of stackoverflow so I tried to play with your question, and I know this may attract downvotes but I tried and it does what you want in case there is at least one element in the list.

    sdata[0].DailyReturn = 0.0;
    sdata.GetRange(1, sdata.Count - 1).ForEach(c => c.DailyReturn = (sdata[sdata.IndexOf(c)-1].AdjClose / c.AdjClose) - 1);
    

    But must say that avoiding for loops isn’t the best practice. from my point of view, LINQ should be used where convenient and not everywhere. Good old loops are sometimes easier to maintain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Both list and islice objects are iterable but why this difference in result. r
List<int> megalist; int boxId; boxId = ListofUniqueIDSpecificToDate.IndexOf(lstbox.SelectedIndex);<< this is wrong I'm trying to display
List<CertMail> lsRecipetNumber = new List<CertMail>(); CertMail class is in data access layer which returns
List<String> flowers = new ArrayList<String>(); My for loop currently looks like this... for (int
list dog; ............. ............ So I added many dog objects to it. If I
List<int> a = new List<int>{ 1,1,2,2,3,4,5 }; What's the quickest way to do this
List<Question> questions = new ArrayList<Question>(); questions.addAll(getAllQuestions()); //returns a set of Questions Collections.sort(questions, new BeanComparator(questionId));
list = [('ba',4), ('hh',5), ('gg', 25)] How do I do: list.index('hh') ...and returns 1?
List<? extends Base> list List<Base> list Is there any difference between the two declarations?
List<Foo> results = null; results = this.getResults(); if (results == null || results.size() ==

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.