Created
August 7, 2020 21:33
-
-
Save vladgovor77771/65b08aad3bb4a5e9fb35d34c4e162630 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const calculateBuySellPrice = ({ sellings, mounthAgo }) => { | |
| let trendWeight = 0.05; // диапазон средних точек 0.08 | |
| let average = calculateAveragePrice(sellings.slice(0, mounthAgo)); | |
| let min = []; | |
| let max = []; | |
| let first = 0; | |
| let last = 0; | |
| let minEl = 0; | |
| let maxEl = 0; | |
| for(var j = 0; j < Math.floor(mounthAgo / 2); j++) { | |
| if (sellings[j].price / average > 2 || sellings[j].price / average < 0.5) continue; | |
| first += sellings[j].price; | |
| if(sellings[j].price < sellings[minEl].price) minEl = j; | |
| if(sellings[j].price > sellings[maxEl].price) maxEl = j; | |
| } | |
| first /= Math.floor(mounthAgo / 2); | |
| for(var j = Math.floor(mounthAgo / 2); j < mounthAgo; j++) { | |
| if (sellings[j].price / average > 2 || sellings[j].price / average < 0.5) continue; | |
| last += sellings[j].price; | |
| if(sellings[j].price < sellings[minEl].price) minEl = j; | |
| if(sellings[j].price > sellings[maxEl].price) maxEl = j; | |
| } | |
| last /= mounthAgo - Math.floor(mounthAgo / 2); | |
| let step = (last - first) / (mounthAgo - 1); | |
| let range = sellings[maxEl].price - sellings[minEl].price; | |
| for(var j = 0; j < mounthAgo; j++) { | |
| let diff = sellings[j].price; | |
| if (diff / average > 2 || diff / average < 0.5) continue; | |
| let trend = first + j * step; | |
| let normtrend = trend / range; | |
| let normdiff = diff / range / normtrend; | |
| if(normdiff < 1 + trendWeight && normdiff > 1 - trendWeight) continue; | |
| if(normdiff > 1) max.push(sellings[j]); | |
| else min.push(sellings[j]); | |
| } | |
| let buyPrice = calculateAveragePrice(min); | |
| let sellPrice = calculateAveragePrice(max); | |
| let maxCount = max.length; | |
| let minCount = min.count; | |
| return { buyPrice, sellPrice, maxCount, minCount, average } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment