From 907f6d83cadd9315bf3e6b480c83ebae62eebd89 Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Tue, 3 Jul 2018 16:46:04 +0400 Subject: [PATCH 1/2] calculation fixes PM-687 --- src/components/Outcome/OutcomeScalar/index.js | 17 +++++--- .../ScalarSlider/index.js | 34 ++++++++++----- .../OutcomeSectionScalar/index.js | 43 +++++++++++-------- 3 files changed, 59 insertions(+), 35 deletions(-) diff --git a/src/components/Outcome/OutcomeScalar/index.js b/src/components/Outcome/OutcomeScalar/index.js index f3ee2fa71..27b2ec74a 100644 --- a/src/components/Outcome/OutcomeScalar/index.js +++ b/src/components/Outcome/OutcomeScalar/index.js @@ -27,15 +27,15 @@ const OutcomeScalar = ({ outcomeTokenIndex: 1, // always calc for long when calculating estimation }) - const decimals = parseInt(decimalsRaw, 10) + const decimals = Math.max(decimalsRaw, 2) const upper = Decimal(upperBound).div(10 ** decimals) const lower = Decimal(lowerBound).div(10 ** decimals) const bounds = upper.sub(lower) - let value = Decimal(marginalPrice.toString()) - .times(bounds) - .add(lowerBound) + let value = Decimal(marginalPrice) + .times(upperBound - lowerBound) + .add(lower) if (showOnlyWinningOutcome) { value = Decimal(winningOutcome).div(10 ** decimals) @@ -57,18 +57,21 @@ const OutcomeScalar = ({
-  {unit} +   + {unit}
-  {unit} +   + {unit}
-  {unit} +   + {unit}
diff --git a/src/routes/MarketDetails/components/ExpandableViews/MarketBuySharesForm/OutcomesSection/OutcomeSectionScalar/ScalarSlider/index.js b/src/routes/MarketDetails/components/ExpandableViews/MarketBuySharesForm/OutcomesSection/OutcomeSectionScalar/ScalarSlider/index.js index 52aed2821..4ea7a535c 100644 --- a/src/routes/MarketDetails/components/ExpandableViews/MarketBuySharesForm/OutcomesSection/OutcomeSectionScalar/ScalarSlider/index.js +++ b/src/routes/MarketDetails/components/ExpandableViews/MarketBuySharesForm/OutcomesSection/OutcomeSectionScalar/ScalarSlider/index.js @@ -18,10 +18,8 @@ const ScalarSlider = ({ // current value const bounds = bigUpperBound.sub(bigLowerBound).div(10 ** decimals) - const value = new Decimal(marginalPriceCurrent).mul(bounds).add(bigLowerBound.div(10 ** displayDecimals)) const percentage = new Decimal(marginalPriceCurrent).mul(100) - const selectedValue = new Decimal(marginalPriceSelected).mul(bounds).add(bigLowerBound.div(10 ** displayDecimals)) const selectedPercentage = new Decimal(marginalPriceSelected).mul(100) @@ -33,26 +31,42 @@ const ScalarSlider = ({
-
{`${bigLowerBound.div(10 ** decimals).toFixed(0)} ${unit}`}
-
Lower Bound
+
+ {`${bigLowerBound.div(10 ** decimals).toFixed(0)} ${unit}`} +
+
+ Lower Bound +
-
Predicted Outcome
-
{`${decimalToText(value.toFixed(displayDecimals))} ${unit}`}
+
+ Predicted Outcome +
+
+ {`${decimalToText(value.toFixed(displayDecimals))} ${unit}`} +
-
Selected Trade
-
{`${decimalToText(selectedValue)} ${unit}`}
+
+ Selected Trade +
+
+ {`${decimalToText(selectedValue)} ${unit}`} +
-
{`${bigUpperBound.div(10 ** decimals).toFixed(0)} ${unit}`}
-
Upper Bound
+
+ {`${bigUpperBound.div(10 ** decimals).toFixed(0)} ${unit}`} +
+
+ Upper Bound +
diff --git a/src/routes/MarketDetails/components/ExpandableViews/MarketBuySharesForm/OutcomesSection/OutcomeSectionScalar/index.js b/src/routes/MarketDetails/components/ExpandableViews/MarketBuySharesForm/OutcomesSection/OutcomeSectionScalar/index.js index b2afdec3b..d27b42dd9 100644 --- a/src/routes/MarketDetails/components/ExpandableViews/MarketBuySharesForm/OutcomesSection/OutcomeSectionScalar/index.js +++ b/src/routes/MarketDetails/components/ExpandableViews/MarketBuySharesForm/OutcomesSection/OutcomeSectionScalar/index.js @@ -14,29 +14,30 @@ const OutcomeSectionScalar = (props) => { selectedBuyInvest, selectedOutcome, market: { - event: { lowerBound, upperBound }, eventDescription: { decimals, unit }, netOutcomeTokensSold, funding, + event: { lowerBound, upperBound }, + eventDescription: { decimals, unit }, + netOutcomeTokensSold, + funding, }, outcomeTokenCount, } = props const canRunSimulation = selectedBuyInvest && selectedOutcome const marketTokenCounts = netOutcomeTokensSold.map(value => Decimal(value)) - const marginalPricesCurrent = marketTokenCounts.map((value, outcomeTokenIndex) => - calcLMSRMarginalPrice({ - netOutcomeTokensSold: marketTokenCounts, - outcomeTokenIndex, - funding, - })) + const marginalPricesCurrent = calcLMSRMarginalPrice({ + netOutcomeTokensSold: marketTokenCounts, + outcomeTokenIndex: 1, + funding, + }) let marginalPriceSelected = marginalPricesCurrent if (canRunSimulation) { marketTokenCounts[selectedOutcome] = marketTokenCounts[selectedOutcome].add(outcomeTokenCount) - marginalPriceSelected = marketTokenCounts.map((value, outcomeTokenIndex) => - calcLMSRMarginalPrice({ - netOutcomeTokensSold: marketTokenCounts, - outcomeTokenIndex, - funding, - })) + marginalPriceSelected = calcLMSRMarginalPrice({ + netOutcomeTokensSold: marketTokenCounts, + outcomeTokenIndex: 1, + funding, + }) } const scalarOutcomes = [ @@ -44,13 +45,13 @@ const OutcomeSectionScalar = (props) => { index: 0, label: 'Short', color: COLOR_SCHEME_SCALAR[0], - probability: marginalPriceSelected[0].mul(100), + probability: Decimal(1).sub(marginalPriceSelected).mul(100), }, { index: 1, label: 'Long', color: COLOR_SCHEME_SCALAR[1], - probability: marginalPriceSelected[1].mul(100), + probability: marginalPriceSelected.mul(100), }, ] @@ -61,7 +62,13 @@ const OutcomeSectionScalar = (props) => {

Your Trade

- +
@@ -71,8 +78,8 @@ const OutcomeSectionScalar = (props) => { upperBound={parseInt(upperBound, 10)} unit={unit} decimals={decimals} - marginalPriceCurrent={marginalPricesCurrent[1].toString()} - marginalPriceSelected={marginalPriceSelected[1].toString()} + marginalPriceCurrent={marginalPricesCurrent.toString()} + marginalPriceSelected={marginalPriceSelected.toString()} />
From b247c80479a26ba97db09ecde444686042232533 Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Tue, 3 Jul 2018 16:47:56 +0400 Subject: [PATCH 2/2] Style fixes PM-687 --- src/components/Outcome/OutcomeScalar/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/Outcome/OutcomeScalar/index.js b/src/components/Outcome/OutcomeScalar/index.js index 27b2ec74a..1ff00aa97 100644 --- a/src/components/Outcome/OutcomeScalar/index.js +++ b/src/components/Outcome/OutcomeScalar/index.js @@ -29,12 +29,11 @@ const OutcomeScalar = ({ const decimals = Math.max(decimalsRaw, 2) - const upper = Decimal(upperBound).div(10 ** decimals) const lower = Decimal(lowerBound).div(10 ** decimals) - const bounds = upper.sub(lower) + const bounds = Decimal(upperBound).sub(lowerBound) let value = Decimal(marginalPrice) - .times(upperBound - lowerBound) + .times(bounds) .add(lower) if (showOnlyWinningOutcome) {