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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:59:35+00:00 2026-05-27T11:59:35+00:00

I currently have the following working code. It is painfully slow however. I know

  • 0

I currently have the following working code. It is painfully slow however. I know that passing the holdings as a query rather than as a list might simplify and speed up things, but for various reasons this is not possible.

How can I update the list of holdings in place, without creating a new list? Other suggestions to improve the code?

internal List<DailyHoldingItem> TransformHoldingItemsToCurrency(List<DailyHoldingItem> holdings,string toCurrency)
        {
        //TODO - how to do this calculation in place, without creating a new list?
        var query = (from holding in holdings
                     from fxRateHolding in amdw.FXRates
                     from fxRateToCur in amdw.FXRates
                     where
                     fxRateHolding.BaseCurrency == holding.Currency &&
                     fxRateToCur.BaseCurrency == toCurrency &&
                     fxRateHolding.ValueDate == holding.Date &&
                     fxRateToCur.ValueDate == holding.Date
                     select new { holding, fxRateHolding, fxRateToCur });

        return query.Select(dhi =>
        {
            decimal factor = dhi.fxRateToCur.Value / dhi.fxRateHolding.Value;
            dhi.holding.MarketValue *= factor;
            dhi.holding.Fee *= factor;
            dhi.holding.Remuneration *= factor;
            return dhi.holding;
        }).ToList();

    }
  • 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-05-27T11:59:36+00:00Added an answer on May 27, 2026 at 11:59 am

    Well for one thing you can speed things up using joins, and only evaluating the valid “target” currencies once:

    var targetRates = amdw.FXRates
                          .Where(rate => rate.BaseCurrency == toCurrency)
                          .ToList();
    
    var query = from holding in holdings
                join fxRateHolding in amdw.FXRates
                  on new { holding.Currency, holding.Date } equals
                     new { Currency = fxRateHolding.BaseCurrency, 
                           Date = fxRateHolding.ValueDate }
                join fxRateToCur in targetRates
                  on holding.Date equals fxRateToCur.ValueDate
                select new { holding, fxRateHolding, fxRateToCur };
    

    Personally I wouldn’t try to update the list in place and I wouldn’t mutate the existing holdings (as you currently do in your Select call). Mutating existing values tends to make your code harder to reason about – which is why LINQ is designed to be used in a more functional way.

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

Sidebar

Related Questions

I currently have code that does the following: private final static ExecutorService pool =
Currently I have the following code, working with Node.js, socket.io and Redis: var io
I'm working on separating JavaScript code from my HTML. I currently have code that
Currently I have Windsor controller factory that is working well. However, I am changing
I have the following problem using subversion: I'm currently working on the trunk of
I`m currently working on a script, and I have the following situation. function somnicefunction()
I currently have the following js code function clearMulti(option) { var i; var select
currently I have the following code: String select = qry.substring(select .length(),qry2.indexOf( from )); String[]
I currently have the following code to generate a sales report over the last
I'm currently working on a PHP/MySQL script that does the following, in this order:

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.