forked from Jay-Jay-D/LeanOptimization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTotalTradesFitness.cs
40 lines (31 loc) · 986 Bytes
/
TotalTradesFitness.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Optimization
{
public class TotalTradesFitness : OptimizerFitness
{
public TotalTradesFitness(IOptimizerConfiguration config) : base(config)
{
}
double scale = 0.0001;
//Fitness based on total trades
protected override FitnessResult CalculateFitness(Dictionary<string, string> result)
{
this.Name = "Trades";
var fitness = new FitnessResult();
int parsed = 0;
var raw = result["Total Trades"];
int.TryParse(raw, out parsed);
fitness.Value = parsed.ToString();
fitness.Fitness = (double)(System.Math.Max(parsed, 0)) * scale;
return fitness;
}
public override double GetValueFromFitness(double? fitness)
{
return fitness.Value / scale;
}
}
}