diff --git a/app/src/scripts/presets/market/averages/index.ts b/app/src/scripts/presets/market/averages/index.ts index 19dd6d166..86be71c43 100644 --- a/app/src/scripts/presets/market/averages/index.ts +++ b/app/src/scripts/presets/market/averages/index.ts @@ -1,6 +1,8 @@ import { averages } from "/src/scripts/datasets/date"; import { colors } from "/src/scripts/utils/colors"; +import { SeriesType } from "../../enums"; + export function createPresets(scale: ResourceScale): PartialPresetFolder { return { name: "Averages", @@ -58,28 +60,88 @@ function createPresetFolder({ ], }, { - scale, name: "Ratio", - description: "", - icon: IconTablerMathXDivideY, - title: `Market Price To ${name} Moving Average Ratio`, - top: [ + tree: [ { - title: `SMA`, - color, - datasetPath: `/${scale}-to-price-${key}-sma`, - }, - ], - bottom: [ - { - title: `Ratio`, - color, - datasetPath: `/${scale}-to-market-price-to-price-${key}-sma-ratio`, + scale, + name: "Basic", + description: "", + icon: IconTablerMathXDivideY, + title: `Market Price To ${name} Moving Average Ratio`, + top: [ + { + title: `SMA`, + color, + datasetPath: `/${scale}-to-price-${key}-sma`, + }, + ], + bottom: [ + { + title: `Ratio`, + seriesType: SeriesType.Based, + datasetPath: `/${scale}-to-market-price-to-price-${key}-sma-ratio`, + options: { + base: 1, + }, + }, + { + title: `Even`, + color: colors.white, + datasetPath: `/${scale}-to-1`, + options: { + lineStyle: 3, + lastValueVisible: false, + }, + }, + ], }, { - title: `Even`, - color: colors.white, - datasetPath: `/${scale}-to-1`, + scale, + name: "Averages", + description: "", + icon: IconTablerMathAvg, + title: `Market Price To ${name} Moving Average Ratio Averages`, + top: [ + { + title: `SMA`, + color, + datasetPath: `/${scale}-to-price-${key}-sma`, + }, + ], + bottom: [ + { + title: `1Y`, + color: colors.red, + datasetPath: `/${scale}-to-market-price-to-price-${key}-sma-ratio-1y-sma`, + }, + { + title: `1M`, + color: colors.orange, + datasetPath: `/${scale}-to-market-price-to-price-${key}-sma-ratio-1m-sma`, + }, + { + title: `1W`, + color: colors.yellow, + datasetPath: `/${scale}-to-market-price-to-price-${key}-sma-ratio-1w-sma`, + }, + { + title: `Raw`, + color: colors.white, + datasetPath: `/${scale}-to-market-price-to-price-${key}-sma-ratio`, + options: { + base: 1, + }, + }, + { + title: `Even`, + color: colors.gray, + datasetPath: `/${scale}-to-1`, + options: { + lineStyle: 3, + lastValueVisible: false, + }, + }, + ], }, ], }, diff --git a/parser/src/datasets/subs/ratio.rs b/parser/src/datasets/subs/ratio.rs index 2aff48186..be792e9eb 100644 --- a/parser/src/datasets/subs/ratio.rs +++ b/parser/src/datasets/subs/ratio.rs @@ -39,25 +39,25 @@ impl RatioDataset { min_initial_states: MinInitialStates::default(), ratio: BiMap::new_bin(1, &f_ratio("ratio")), - ratio_1w_sma: BiMap::new_bin(1, &f_ratio("ratio_1w_sma")), - ratio_1m_sma: BiMap::new_bin(1, &f_ratio("ratio_1m_sma")), - ratio_1y_sma: BiMap::new_bin(1, &f_ratio("ratio_1y_sma")), + ratio_1w_sma: BiMap::new_bin(2, &f_ratio("ratio_1w_sma")), + ratio_1m_sma: BiMap::new_bin(2, &f_ratio("ratio_1m_sma")), + ratio_1y_sma: BiMap::new_bin(2, &f_ratio("ratio_1y_sma")), ratio_1y_sma_momentum_oscillator: BiMap::new_bin( - 1, + 2, &f_ratio("ratio_1y_sma_momentum_oscillator"), ), - ratio_99p: BiMap::new_bin(1, &f_ratio("ratio_99p")), - ratio_99_5p: BiMap::new_bin(1, &f_ratio("ratio_99_5p")), - ratio_99_9p: BiMap::new_bin(1, &f_ratio("ratio_99_9p")), - ratio_1p: BiMap::new_bin(1, &f_ratio("ratio_1p")), - ratio_0_5p: BiMap::new_bin(1, &f_ratio("ratio_0_5p")), - ratio_0_1p: BiMap::new_bin(1, &f_ratio("ratio_0_1p")), - price_99p: BiMap::new_bin(1, &f_price("99p")), - price_99_5p: BiMap::new_bin(1, &f_price("99_5p")), - price_99_9p: BiMap::new_bin(1, &f_price("99_9p")), - price_1p: BiMap::new_bin(1, &f_price("1p")), - price_0_5p: BiMap::new_bin(1, &f_price("0_5p")), - price_0_1p: BiMap::new_bin(1, &f_price("0_1p")), + ratio_99p: BiMap::new_bin(2, &f_ratio("ratio_99p")), + ratio_99_5p: BiMap::new_bin(2, &f_ratio("ratio_99_5p")), + ratio_99_9p: BiMap::new_bin(2, &f_ratio("ratio_99_9p")), + ratio_1p: BiMap::new_bin(2, &f_ratio("ratio_1p")), + ratio_0_5p: BiMap::new_bin(2, &f_ratio("ratio_0_5p")), + ratio_0_1p: BiMap::new_bin(2, &f_ratio("ratio_0_1p")), + price_99p: BiMap::new_bin(2, &f_price("99p")), + price_99_5p: BiMap::new_bin(2, &f_price("99_5p")), + price_99_9p: BiMap::new_bin(2, &f_price("99_9p")), + price_1p: BiMap::new_bin(2, &f_price("1p")), + price_0_5p: BiMap::new_bin(2, &f_price("0_5p")), + price_0_1p: BiMap::new_bin(2, &f_price("0_1p")), }; s.min_initial_states diff --git a/parser/src/structs/date_map.rs b/parser/src/structs/date_map.rs index 137b18fc6..a50fd1029 100644 --- a/parser/src/structs/date_map.rs +++ b/parser/src/structs/date_map.rs @@ -640,11 +640,15 @@ where }) .into(); - let last_value = f32::lossy_from(source.get_or_import(date).unwrap_or_else(|| { + let mut last_value = f32::lossy_from(source.get_or_import(date).unwrap_or_else(|| { dbg!(date); panic!() })); + if last_value.is_nan() { + last_value = 0.0; + } + average.replace(((previous_average * (days - 1.0) + last_value) / days).into()); self.insert(*date, average.unwrap()); diff --git a/parser/src/structs/height_map.rs b/parser/src/structs/height_map.rs index 6be276f20..3758d44c3 100644 --- a/parser/src/structs/height_map.rs +++ b/parser/src/structs/height_map.rs @@ -652,7 +652,11 @@ where }) .into(); - let last_value = f32::lossy_from(source.get_or_import(&height)); + let mut last_value = f32::lossy_from(source.get_or_import(&height)); + + if last_value.is_nan() { + last_value = 0.0; + } average.replace( ((previous_average * (block_time as f32 - 1.0) + last_value) / block_time as f32)