Stackoverflow 46166069

CSharp · Console

/Program.cs

using System;                                                                                 
using System.Collections.Generic;                                                             
using System.Linq;                                                                            
using System.Reflection;                                                                      
                                                                                              
class CalculationData {                                                                       
    public decimal Ema12 { get; set; }                                                        
    public decimal Ema26 { get; set; }                                                        
    public decimal Ema { get; set; }                                                          
    public decimal ADL { get; set; }                                                          
}                                                                                             
                                                                                              
public class Program {                                                                               
                                                                                              
    static double RSquared(IEnumerable<double> s) {                                           
        return 0.5; // TODO - obviously                                                                          
    }                                                                                         
                                                                                              
    public static void Main() {                                                                      
        var list = new [] {                                                                   
            new CalculationData { Ema12 = 1, Ema26  = 2, Ema = 3, ADL = 4 },                  
            new CalculationData { Ema12 = 21, Ema26  = 2, Ema = 3, ADL = 4 },                  
            new CalculationData { Ema12 = 21, Ema26  = 52, Ema = 63, ADL = 4 },                  
            new CalculationData { Ema12 = 21, Ema26  = 52, Ema = 63, ADL = 4 },                  
            new CalculationData { Ema12 = 41, Ema26  = 52, Ema = 63, ADL = 74 },                  
        };                                                                                    
                                                                                              
        var properties = typeof(CalculationData).GetProperties();                                
                                                                                              
        var results = properties.Select((p) => {                                                 
            var series = list.Select((data) => (double)(decimal)p.GetValue(data));            
            return new {                                                                      
                Name = p.Name,                                                                
                RSquared = RSquared(series) 
            };                                                                                
        }).ToArray();                                                                         
                                                                                              
        foreach(var item in results) {                                                        
            Console.WriteLine(item);                                                          
        }                                                                                     
    }                                                                                         
}                                                                                             
                                                                                              
;